Skip to content

Commit 0cf1dfe

Browse files
authored
Some improvements for SMB module
* Improve permission information returned in `SmbFileInfo` * Improve documentation for `SmbFileInfo.getPermissions()` * Add Junit tests to verify all outbound gateway functionality * Clean test directory of mistakenly migrated SMB extension code
1 parent 751d808 commit 0cf1dfe

File tree

5 files changed

+208
-208
lines changed

5 files changed

+208
-208
lines changed

spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbFileInfo.java

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.integration.smb.session;
1818

1919
import java.io.IOException;
20-
import java.util.Arrays;
2120

2221
import org.apache.commons.logging.Log;
2322
import org.apache.commons.logging.LogFactory;
@@ -91,23 +90,70 @@ public String getFilename() {
9190
}
9291

9392
/**
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
100110
*/
101111
@Override
102112
public String getPermissions() {
103-
ACE[] aceArray = null;
113+
ACE[] aces = null;
104114
try {
105-
aceArray = this.smbFile.getSecurity(true);
115+
aces = this.smbFile.getSecurity(true);
106116
}
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;
109120
}
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();
111157
}
112158

113159
@Override

spring-integration-smb/src/test/java/org/springframework/integration/smb/Main.java

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)