Search in sources :

Example 1 with IAuthorizationAction

use of org.pentaho.platform.api.engine.IAuthorizationAction in project pentaho-platform by pentaho.

the class AuthorizationActionService method validateAuth.

public boolean validateAuth(String authAction) {
    boolean isAllowed = false;
    boolean validInput = false;
    for (IAuthorizationAction a : getActionList()) {
        if (a.getName().equals(authAction)) {
            validInput = true;
            break;
        }
    }
    if (validInput) {
        IAuthorizationPolicy policy = getPolicy();
        isAllowed = policy.isAllowed(authAction);
    }
    return isAllowed;
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IAuthorizationAction(org.pentaho.platform.api.engine.IAuthorizationAction)

Example 2 with IAuthorizationAction

use of org.pentaho.platform.api.engine.IAuthorizationAction in project pentaho-platform by pentaho.

the class AuthorizationActionServiceTest method testDoValidateAuth.

@Test
public void testDoValidateAuth() {
    IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
    List<IAuthorizationAction> actions = new ArrayList();
    actions.add(new AdministerSecurityAction());
    doReturn(actions).when(authorizationActionService).getActionList();
    doReturn(policy).when(authorizationActionService).getPolicy();
    doReturn(true).when(policy).isAllowed("org.pentaho.security.administerSecurity");
    boolean isAllowed = authorizationActionService.validateAuth("org.pentaho.security.administerSecurity");
    assertEquals(isAllowed, true);
    isAllowed = authorizationActionService.validateAuth("invalid-auth");
    assertEquals(isAllowed, false);
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IAuthorizationAction(org.pentaho.platform.api.engine.IAuthorizationAction) AdministerSecurityAction(org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

IAuthorizationAction (org.pentaho.platform.api.engine.IAuthorizationAction)2 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 AdministerSecurityAction (org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction)1