Search in sources :

Example 1 with KapuaAuthorizationException

use of org.eclipse.kapua.service.authorization.shiro.KapuaAuthorizationException in project kapua by eclipse.

the class PermissionFactoryImpl method parseString.

@Override
public Permission parseString(String stringPermission) throws KapuaException {
    StringTokenizer st = new StringTokenizer(stringPermission, ":");
    int iTokensCount = st.countTokens();
    if (iTokensCount < 1 || iTokensCount > 3) {
        throw new KapuaAuthorizationException(KapuaAuthorizationErrorCodes.INVALID_STRING_PERMISSION, null, stringPermission);
    }
    // 
    // Build the new Permission
    String domain = st.nextToken();
    Actions action = null;
    if (iTokensCount > 1) {
        action = Actions.valueOf(st.nextToken());
    }
    KapuaId scopeTargetId = null;
    if (iTokensCount > 2) {
        try {
            BigInteger kapuaId = new BigInteger(st.nextToken());
            scopeTargetId = new KapuaEid(kapuaId);
        } catch (IllegalArgumentException iae) {
            throw new KapuaAuthorizationException(KapuaAuthorizationErrorCodes.INVALID_STRING_PERMISSION, iae, stringPermission);
        }
    }
    return new PermissionImpl(domain, action, scopeTargetId);
}
Also used : StringTokenizer(java.util.StringTokenizer) KapuaAuthorizationException(org.eclipse.kapua.service.authorization.shiro.KapuaAuthorizationException) Actions(org.eclipse.kapua.service.authorization.permission.Actions) RolePermissionImpl(org.eclipse.kapua.service.authorization.role.shiro.RolePermissionImpl) BigInteger(java.math.BigInteger) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid)

Aggregations

BigInteger (java.math.BigInteger)1 StringTokenizer (java.util.StringTokenizer)1 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 Actions (org.eclipse.kapua.service.authorization.permission.Actions)1 RolePermissionImpl (org.eclipse.kapua.service.authorization.role.shiro.RolePermissionImpl)1 KapuaAuthorizationException (org.eclipse.kapua.service.authorization.shiro.KapuaAuthorizationException)1