Search in sources :

Example 26 with PerryAccount

use of gov.ca.cwds.security.realm.PerryAccount in project api-core by ca-cwds.

the class SubstituteCareProviderCreateAuthorizerTest method checkInstance_returnFalse_whenPerryPrivilegesAreNull.

@Test
public void checkInstance_returnFalse_whenPerryPrivilegesAreNull() {
    final PerryAccount perryAccount = new PerryAccount();
    final boolean expectedResult = false;
    checkInstance_returnExpected_withPreparedPerryAccount(perryAccount, expectedResult);
}
Also used : PerryAccount(gov.ca.cwds.security.realm.PerryAccount) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with PerryAccount

use of gov.ca.cwds.security.realm.PerryAccount in project api-core by ca-cwds.

the class SubstituteCareProviderCreateAuthorizerTest method checkInstance_returnFalse_whenPerryPrivilegesAreEmpty.

@Test
public void checkInstance_returnFalse_whenPerryPrivilegesAreEmpty() {
    final PerryAccount perryAccount = initPerryAccountWithPrivileges();
    final boolean expectedResult = false;
    checkInstance_returnExpected_withPreparedPerryAccount(perryAccount, expectedResult);
}
Also used : PerryAccount(gov.ca.cwds.security.realm.PerryAccount) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with PerryAccount

use of gov.ca.cwds.security.realm.PerryAccount in project api-core by ca-cwds.

the class AbstractBaseAuthorizer method authorizeInstanceOperation.

protected boolean authorizeInstanceOperation(final T instance, List<Object> authorizationFacts) {
    try {
        final PerryAccount perryAccount = PerrySubject.getPerryAccount();
        final Set<StaffPrivilegeType> staffPrivilegeTypes = toStaffPersonPrivilegeTypes(perryAccount);
        if (staffPrivilegeTypes.isEmpty()) {
            return false;
        }
        if (authorizationFacts == null) {
            authorizationFacts = new ArrayList<>();
        }
        authorizationFacts.add(instance);
        authorizationFacts.add(perryAccount);
        final boolean authorizationResult = droolsAuthorizationService.authorizeObjectOperation(staffPrivilegeTypes, droolsConfiguration, authorizationFacts);
        logAuthorization(perryAccount, staffPrivilegeTypes, instance, authorizationResult);
        return authorizationResult;
    } catch (DroolsException e) {
        throw new AuthorizationException(e.getMessage(), e);
    }
}
Also used : AuthorizationException(org.apache.shiro.authz.AuthorizationException) DroolsException(gov.ca.cwds.drools.DroolsException) PerryAccount(gov.ca.cwds.security.realm.PerryAccount)

Aggregations

PerryAccount (gov.ca.cwds.security.realm.PerryAccount)28 Test (org.junit.Test)18 StaffPrivilegeType (gov.ca.cwds.authorizer.StaffPrivilegeType)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 DroolsException (gov.ca.cwds.drools.DroolsException)3 DataAccessBundle (gov.ca.cwds.cms.data.access.service.lifecycle.DataAccessBundle)2 PlacementHome (gov.ca.cwds.data.legacy.cms.entity.PlacementHome)2 SubstituteCareProvider (gov.ca.cwds.data.legacy.cms.entity.SubstituteCareProvider)2 HashSet (java.util.HashSet)2 AuthorizationException (org.apache.shiro.authz.AuthorizationException)1 Subject (org.apache.shiro.subject.Subject)1