Search in sources :

Example 16 with PerryAccount

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

the class ClientConditionUtils method toClientCondition.

// TODO(dd): Consider to move this to drools
/**
 * @param sensitivity sensitivity
 * @param clientCountyCodes client county codes
 * @return client condition
 */
public static ClientCondition toClientCondition(Sensitivity sensitivity, List<Short> clientCountyCodes) {
    final PerryAccount perryAccount = PerrySubject.getPerryAccount();
    final Short staffPersonCountyCode = getStaffPersonCountyCode(perryAccount.getCountyCwsCode());
    if (sensitivity == null || sensitivity == Sensitivity.NOT_APPLICABLE) {
        return ClientCondition.NO_CONDITIONS;
    }
    return sensitivity == Sensitivity.SENSITIVE ? getConditionWhenSensitive(clientCountyCodes, staffPersonCountyCode) : getConditionWhenSealed(clientCountyCodes, staffPersonCountyCode);
}
Also used : PerryAccount(gov.ca.cwds.security.realm.PerryAccount)

Example 17 with PerryAccount

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

the class PrincipalUtils method getPrincipal.

public static PerryAccount getPrincipal() {
    Optional<PerryAccount> perryAccount = Optional.empty();
    Subject currentUser = SecurityUtils.getSubject();
    if (currentUser.getPrincipals() != null) {
        perryAccount = currentUser.getPrincipals().asList().stream().filter(principal -> principal instanceof PerryAccount).findAny();
    }
    return perryAccount.orElseThrow(IllegalStateException::new);
}
Also used : Subject(org.apache.shiro.subject.Subject) PerryAccount(gov.ca.cwds.security.realm.PerryAccount)

Example 18 with PerryAccount

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

the class PlacementHomeCreateAuthorizerTest 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 19 with PerryAccount

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

the class StaffPrivilegeUtilTest method toStaffPersonPrivilegeTypes_empty_whenUnknownPerryPrivileges.

@Test
public void toStaffPersonPrivilegeTypes_empty_whenUnknownPerryPrivileges() {
    // given
    final PerryAccount input = initPerryAccountWithPrivileges("a", "bbb");
    // when
    final Set<StaffPrivilegeType> actual = StaffPrivilegeUtil.toStaffPersonPrivilegeTypes(input);
    // then
    assertThat(actual.isEmpty(), is(true));
}
Also used : StaffPrivilegeType(gov.ca.cwds.authorizer.StaffPrivilegeType) PerryAccount(gov.ca.cwds.security.realm.PerryAccount) Test(org.junit.Test)

Example 20 with PerryAccount

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

the class StaffPrivilegeUtilTest method toStaffPersonPrivilegeTypes_success_whenSocialWorker.

@Test
public void toStaffPersonPrivilegeTypes_success_whenSocialWorker() {
    // given
    final PerryAccount input = initPerryAccountWithPrivileges("CWS Case Management System");
    // when
    final Set<StaffPrivilegeType> actual = StaffPrivilegeUtil.toStaffPersonPrivilegeTypes(input);
    // then
    assertThat(actual.size(), is(1));
    assertThat(actual, contains(SOCIAL_WORKER_ONLY));
}
Also used : StaffPrivilegeType(gov.ca.cwds.authorizer.StaffPrivilegeType) PerryAccount(gov.ca.cwds.security.realm.PerryAccount) Test(org.junit.Test)

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