Subversion Repositories XServices

Rev

Rev 198 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 198 Rev 199
Line 14... Line 14...
14
 *   limitations under the License.
14
 *   limitations under the License.
15
*/
15
*/
Line 16... Line 16...
16
 
16
 
Line -... Line 17...
-
 
17
package net.brutex.xservices.security;
17
package net.brutex.xservices.security;
18
 
18
 
19
import lombok.extern.slf4j.Slf4j;
Line 19... Line -...
19
import net.brutex.xservices.ws.XmlService;
-
 
20
import net.brutex.xservices.ws.rs.FileInfo;
-
 
-
 
20
import net.brutex.xservices.ws.XmlService;
21
 
21
import net.brutex.xservices.ws.rs.FileInfo;
22
import org.apache.logging.log4j.Logger;
22
 
Line 23... Line 23...
23
import org.apache.logging.log4j.LogManager;
23
 
24
import org.apache.shiro.authz.Permission;
24
import org.apache.shiro.authz.Permission;
25
import org.apache.shiro.authz.permission.InvalidPermissionStringException;
25
import org.apache.shiro.authz.permission.InvalidPermissionStringException;
26
 
26
 
-
 
27
/**
27
/**
28
 * @author Brian Rosenberger, bru(at)brutex.de
28
 * @author Brian Rosenberger, bru(at)brutex.de
29
 *
29
 *
-
 
30
 */
30
 */
Line 31... Line 31...
31
public class PermissionResolver implements org.apache.shiro.authz.permission.PermissionResolver {
31
@Slf4j
32
	
32
public class PermissionResolver implements org.apache.shiro.authz.permission.PermissionResolver {
33
	private final Logger logger = LogManager.getLogger();
33
 
34
	private final String DELIMITER = "||";
34
	private final String DELIMITER = "||";
35
 
35
 
36
	@Override
36
	@Override
37
	public Permission resolvePermission(String permissionString) {
37
	public Permission resolvePermission(String permissionString) {
38
		logger.debug(String.format("Trying to examine new Permission '%s'", permissionString));
38
		log.debug(String.format("Trying to examine new Permission '{}'", permissionString));
39
		if(! permissionString.contains(DELIMITER)) {
39
		if(! permissionString.contains(DELIMITER)) {
40
			logger.error(String.format("Permission '%s' is missing permission class.", permissionString));
40
			log.error(String.format("Permission '{}' is missing permission class.", permissionString));
41
			throw new InvalidPermissionStringException(String.format("Permission '%s' is missing permission class.", permissionString), permissionString);
41
			throw new InvalidPermissionStringException(String.format("Permission '{}' is missing permission class.", permissionString), permissionString);
42
		}
42
		}
43
		int delimiterIndex = permissionString.indexOf(DELIMITER);
43
		int delimiterIndex = permissionString.indexOf(DELIMITER);
44
		String value = permissionString.substring(0, delimiterIndex);
44
		String value = permissionString.substring(0, delimiterIndex);
Line 45... Line 45...
45
		delimiterIndex = delimiterIndex + DELIMITER.length();
45
		delimiterIndex = delimiterIndex + DELIMITER.length();
46
		switch (value) {
46
		switch (value) {
47
		case XmlService.SERVICE_NAME:
47
		case XmlService.SERVICE_NAME:
Line 48... Line 48...
48
			logger.debug(String.format("Found '%s' as permission class.", value));
48
			log.debug(String.format("Found '{}' as permission class.", value));
49
			return new XmlServicePermission(permissionString.substring( delimiterIndex ));
49
			return new XmlServicePermission(permissionString.substring( delimiterIndex ));
50
		
50
		
51
		case FileInfo.SERVICE_NAME:
51
		case FileInfo.SERVICE_NAME:
52
			logger.debug(String.format("Found '%s' as permission class.", value));
52
			log.debug(String.format("Found '{}' as permission class.", value));
53
			return new DirectoryPermission(permissionString.substring( delimiterIndex ));
53
			return new DirectoryPermission(permissionString.substring( delimiterIndex ));