16,8 → 16,12 |
|
package net.brutex.xservices.security; |
|
import net.brutex.xservices.ws.XmlService; |
import net.brutex.xservices.ws.rs.FileInfo; |
|
import org.apache.log4j.Logger; |
import org.apache.shiro.authz.Permission; |
import org.apache.shiro.authz.permission.InvalidPermissionStringException; |
|
/** |
* @author Brian Rosenberger, bru(at)brutex.de |
26,10 → 30,31 |
public class PermissionResolver implements org.apache.shiro.authz.permission.PermissionResolver { |
|
final Logger logger = Logger.getLogger(PermissionResolver.class); |
private final String DELIMITER = "||"; |
|
@Override |
public Permission resolvePermission(String permissionString) { |
logger.debug(String.format("Creating new Permission '%s'", permissionString)); |
return new DirectoryPermission(permissionString); |
logger.debug(String.format("Trying to examine new Permission '%s'", permissionString)); |
if(! permissionString.contains(DELIMITER)) { |
logger.error(String.format("Permission '%s' is missing permission class.", permissionString)); |
throw new InvalidPermissionStringException(String.format("Permission '%s' is missing permission class.", permissionString), permissionString); |
} |
int delimiterIndex = permissionString.indexOf(DELIMITER); |
String value = permissionString.substring(0, delimiterIndex); |
delimiterIndex = delimiterIndex + DELIMITER.length(); |
switch (value) { |
case XmlService.SERVICE_NAME: |
logger.debug(String.format("Found '%s' as permission class.", value)); |
return new XmlServicePermission(permissionString.substring( delimiterIndex )); |
|
case FileInfo.SERVICE_NAME: |
logger.debug(String.format("Found '%s' as permission class.", value)); |
return new DirectoryPermission(permissionString.substring( delimiterIndex )); |
|
|
default: |
logger.warn(String.format("Permission class '%s' is not defined.", value)); |
throw new InvalidPermissionStringException(String.format("Permission class '%s' is not defined.", value), permissionString); |
} |
} |
} |