Search in sources :

Example 1 with UserAuthorization

use of gov.ca.cwds.rest.api.domain.auth.UserAuthorization in project perry by ca-cwds.

the class IdentityMappingService method map.

public String map(UniversalUserToken subject, String providerId) {
    IdentityMappingScript mappingScript = loadMappingScriptForServiceProvider(providerId);
    if (mappingScript != null) {
        UserAuthorization authorization = userAuthorizationService.find(subject.getUserId());
        subject.setAuthorization(authorization);
        try {
            return mappingScript.map(subject);
        } catch (ScriptException e) {
            throw new IllegalArgumentException("Identity Mapping failed for service provider: " + providerId, e);
        }
    }
    return subject.getUserId();
}
Also used : ScriptException(javax.script.ScriptException) UserAuthorization(gov.ca.cwds.rest.api.domain.auth.UserAuthorization) IdentityMappingScript(gov.ca.cwds.service.scripts.IdentityMappingScript)

Example 2 with UserAuthorization

use of gov.ca.cwds.rest.api.domain.auth.UserAuthorization in project perry by ca-cwds.

the class UserAuthorizationService method find.

/**
 * {@inheritDoc}
 *
 * @see CrudsService#find(Serializable)
 */
public UserAuthorization find(Serializable primaryKey) {
    final String userId = ((String) primaryKey).trim();
    LOGGER.info(userId);
    List<UserId> userList = userIdDao.findActiveByLogonId(userId);
    if (userList == null || userList.isEmpty()) {
        LOGGER.warn("No user id found for {}", primaryKey);
        return null;
    }
    final UserId user = userList.get(0);
    String userIdentifier = user.getId();
    String staffPersonIdentifier = user.getStaffPersonId();
    boolean socialWorker = !staffAuthorityPrivilegeDao.findSocialWorkerPrivileges(userIdentifier).isEmpty();
    Set<StaffAuthorityPrivilege> userAuthPrivs = getStaffAuthorityPriveleges(userIdentifier);
    Set<StaffUnitAuthority> setStaffUnitAuths = getStaffUnitAuthorities(staffPersonIdentifier);
    StaffPerson staffPerson = staffPersonDao.findOne(staffPersonIdentifier);
    if (staffPerson == null) {
        LOGGER.warn("No staff person found for {}", staffPersonIdentifier);
        return null;
    }
    CwsOffice cwsOffice = cwsOfficeDao.findOne(staffPerson.getCwsOffice());
    if (cwsOffice == null) {
        LOGGER.warn("No cws office found for {}", staffPerson.getCwsOffice());
        return null;
    }
    return new UserAuthorization(user.getLogonId(), socialWorker, false, true, userAuthPrivs, setStaffUnitAuths, cwsOffice, staffPerson);
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.auth.StaffPerson) StaffAuthorityPrivilege(gov.ca.cwds.rest.api.domain.auth.StaffAuthorityPrivilege) UserAuthorization(gov.ca.cwds.rest.api.domain.auth.UserAuthorization) UserId(gov.ca.cwds.data.persistence.auth.UserId) CwsOffice(gov.ca.cwds.data.persistence.auth.CwsOffice) StaffUnitAuthority(gov.ca.cwds.rest.api.domain.auth.StaffUnitAuthority)

Example 3 with UserAuthorization

use of gov.ca.cwds.rest.api.domain.auth.UserAuthorization in project perry by ca-cwds.

the class BaseScriptTest method test.

public void test(String script, String json, String userAuthorization) throws Exception {
    IdentityMappingScript identityMappingScript = loadScript(script);
    UniversalUserToken user = new UniversalUserToken();
    UserAuthorization authorization = MAPPER.readValue(fixture(userAuthorization), UserAuthorization.class);
    user.setAuthorization(authorization);
    String result = identityMappingScript.map(user);
    System.out.println(result);
    String expectedResult = readResource(json);
    Assert.assertEquals(expectedResult, result);
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) UserAuthorization(gov.ca.cwds.rest.api.domain.auth.UserAuthorization)

Aggregations

UserAuthorization (gov.ca.cwds.rest.api.domain.auth.UserAuthorization)3 UniversalUserToken (gov.ca.cwds.UniversalUserToken)1 CwsOffice (gov.ca.cwds.data.persistence.auth.CwsOffice)1 StaffPerson (gov.ca.cwds.data.persistence.auth.StaffPerson)1 UserId (gov.ca.cwds.data.persistence.auth.UserId)1 StaffAuthorityPrivilege (gov.ca.cwds.rest.api.domain.auth.StaffAuthorityPrivilege)1 StaffUnitAuthority (gov.ca.cwds.rest.api.domain.auth.StaffUnitAuthority)1 IdentityMappingScript (gov.ca.cwds.service.scripts.IdentityMappingScript)1 ScriptException (javax.script.ScriptException)1