|
17 | 17 | package org.springframework.integration.smb.session;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
20 |
| -import java.util.Arrays; |
21 | 20 |
|
22 | 21 | import org.apache.commons.logging.Log;
|
23 | 22 | import org.apache.commons.logging.LogFactory;
|
@@ -91,23 +90,70 @@ public String getFilename() {
|
91 | 90 | }
|
92 | 91 |
|
93 | 92 | /**
|
94 |
| - * An Access Control Entry (ACE) is an element in a security descriptor |
95 |
| - * such as those associated with files and directories. The Windows OS |
96 |
| - * determines which users have the necessary permissions to access objects |
97 |
| - * based on these entries. |
98 |
| - * @return a list of Access Control Entry (ACE) objects representing |
99 |
| - * the security descriptor associated with this file or directory. |
| 93 | + * An Access Control Entry (ACE) is an element in a security descriptor such as |
| 94 | + * those associated with files and directories. The Windows OS determines which |
| 95 | + * users have the necessary permissions to access objects based on these entries. |
| 96 | + * A readable, formatted list of security descriptor entries and associated |
| 97 | + * permissions will be returned by this implementation. |
| 98 | + * |
| 99 | + * <pre> |
| 100 | + * WNET\alice - Deny Write, Deny Modify, Direct - This folder only |
| 101 | + * SYSTEM - Allow Read, Allow Write, Allow Modify, Allow Execute, Allow Delete, Inherited - This folder only |
| 102 | + * WNET\alice - Allow Read, Allow Write, Allow Modify, Allow Execute, Allow Delete, Inherited - This folder only |
| 103 | + * Administrators - Allow Read, Allow Write, Allow Modify, Allow Execute, Allow Delete, Inherited - This folder only |
| 104 | + * </pre> |
| 105 | + * |
| 106 | + * @return a list of Access Control Entry (ACE) objects representing the security |
| 107 | + * descriptor entry and permissions associated with this file or directory. |
| 108 | + * @see jcifs.ACE |
| 109 | + * @see jcifs.SID |
100 | 110 | */
|
101 | 111 | @Override
|
102 | 112 | public String getPermissions() {
|
103 |
| - ACE[] aceArray = null; |
| 113 | + ACE[] aces = null; |
104 | 114 | try {
|
105 |
| - aceArray = this.smbFile.getSecurity(true); |
| 115 | + aces = this.smbFile.getSecurity(true); |
106 | 116 | }
|
107 |
| - catch (IOException se) { |
108 |
| - logger.error("Unable to determine security descriptor information for this SmbFile", se); |
| 117 | + catch (IOException ioe) { |
| 118 | + logger.error("Unable to determine security descriptor information for this SmbFile", ioe); |
| 119 | + return null; |
109 | 120 | }
|
110 |
| - return (aceArray == null) ? null : Arrays.toString(aceArray); |
| 121 | + |
| 122 | + StringBuilder sb = new StringBuilder(); |
| 123 | + for (ACE ace : aces) { |
| 124 | + sb.append(ace.getSID().toDisplayString()); |
| 125 | + sb.append(" - "); |
| 126 | + |
| 127 | + if ((ace.getAccessMask() & ACE.FILE_READ_DATA) != 0) { |
| 128 | + sb.append(ace.isAllow() ? "Allow " : "Deny "); |
| 129 | + sb.append("Read, "); |
| 130 | + } |
| 131 | + if ((ace.getAccessMask() & ACE.FILE_WRITE_DATA) != 0) { |
| 132 | + sb.append(ace.isAllow() ? "Allow " : "Deny "); |
| 133 | + sb.append("Write, "); |
| 134 | + } |
| 135 | + if ((ace.getAccessMask() & ACE.FILE_APPEND_DATA) != 0) { |
| 136 | + sb.append(ace.isAllow() ? "Allow " : "Deny "); |
| 137 | + sb.append("Modify, "); |
| 138 | + } |
| 139 | + if ((ace.getAccessMask() & ACE.FILE_EXECUTE) != 0) { |
| 140 | + sb.append(ace.isAllow() ? "Allow " : "Deny "); |
| 141 | + sb.append("Execute, "); |
| 142 | + } |
| 143 | + if ((ace.getAccessMask() & ACE.FILE_DELETE) != 0 |
| 144 | + || (ace.getAccessMask() & ACE.DELETE) != 0) { |
| 145 | + sb.append(ace.isAllow() ? "Allow " : "Deny "); |
| 146 | + sb.append("Delete, "); |
| 147 | + } |
| 148 | + |
| 149 | + sb.append(ace.isInherited() ? "Inherited - " : "Direct - "); |
| 150 | + sb.append(ace.getApplyToText()); |
| 151 | + sb.append("\n"); |
| 152 | + } |
| 153 | + logger.debug(this.getFilename()); |
| 154 | + logger.debug("\n" + sb.toString()); |
| 155 | + |
| 156 | + return sb.toString(); |
111 | 157 | }
|
112 | 158 |
|
113 | 159 | @Override
|
|
0 commit comments