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();
}
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);
}
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);
}
Aggregations