Search in sources :

Example 1 with AbacPermission

use of gov.ca.cwds.security.permission.AbacPermission in project perry by ca-cwds.

the class DefaultStaticAuthorizer method authorize.

@Override
public void authorize(PerryAccount perryAccount, SimpleAuthorizationInfo authorizationInfo) {
    Optional.ofNullable(perryAccount.getRoles()).ifPresent(authorizationInfo::addRoles);
    authorizationInfo.addObjectPermission(new AbacPermission());
}
Also used : AbacPermission(gov.ca.cwds.security.permission.AbacPermission)

Example 2 with AbacPermission

use of gov.ca.cwds.security.permission.AbacPermission in project perry by ca-cwds.

the class AbacMethodInterceptor method checkPermission.

@SuppressWarnings("unchecked")
private void checkPermission(String permission, Object arg) throws ScriptException {
    AbacPermission abacPermission = new AbacPermission(permission);
    String selector = abacPermission.getSecuredObject().toString();
    int dotIndex = selector.indexOf('.');
    String identifier;
    if (dotIndex == -1) {
        identifier = selector;
    } else {
        identifier = selector.substring(0, dotIndex);
    }
    ScriptContext scriptContext = new SimpleScriptContext();
    scriptContext.setAttribute(identifier, arg, ScriptContext.ENGINE_SCOPE);
    for (Object o : (Collection<Object>) scriptEngine.eval("[" + selector + "].flatten()", scriptContext)) {
        abacPermission.setSecuredObject(o);
        SecurityUtils.getSubject().checkPermission(abacPermission);
    }
}
Also used : AbacPermission(gov.ca.cwds.security.permission.AbacPermission) SimpleScriptContext(javax.script.SimpleScriptContext) SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContext(javax.script.ScriptContext) Collection(java.util.Collection)

Aggregations

AbacPermission (gov.ca.cwds.security.permission.AbacPermission)2 Collection (java.util.Collection)1 ScriptContext (javax.script.ScriptContext)1 SimpleScriptContext (javax.script.SimpleScriptContext)1