use of com.unboundid.scim2.common.types.Meta in project cas by apereo.
the class PrincipalScimV2ProvisionerActionTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
WebUtils.putCredential(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
val user = new UserResource();
user.setActive(true);
user.setDisplayName("CASUser");
user.setId("casuser");
val name = new Name();
name.setGivenName("casuser");
user.setName(name);
val meta = new Meta();
meta.setResourceType("User");
meta.setCreated(Calendar.getInstance());
meta.setLocation(new URI("http://localhost:8218"));
user.setMeta(meta);
val data = MAPPER.writeValueAsString(user);
try (val webServer = new MockWebServer(8218, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, principalScimProvisionerAction.execute(context).getId());
}
}
use of com.unboundid.scim2.common.types.Meta in project cas by apereo.
the class ScimV2PrincipalAttributeMapperTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val user = new UserResource();
user.setActive(true);
user.setDisplayName("CASUser");
user.setId("casuser");
val name = new Name();
name.setGivenName("casuser");
user.setName(name);
val meta = new Meta();
meta.setResourceType("User");
meta.setCreated(Calendar.getInstance());
meta.setLocation(new URI("http://localhost:8218"));
user.setMeta(meta);
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
val mapper = new DefaultScimV2PrincipalAttributeMapper();
mapper.map(user, CoreAuthenticationTestUtils.getPrincipal(), CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
}
});
}
use of com.unboundid.scim2.common.types.Meta in project cas by apereo.
the class DefaultScimV2PrincipalAttributeMapper method map.
@Override
public void map(final UserResource user, final Principal principal, final Credential credential) {
user.setUserName(principal.getId());
if (credential instanceof UsernamePasswordCredential) {
user.setPassword(UsernamePasswordCredential.class.cast(credential).getPassword());
}
user.setActive(Boolean.TRUE);
user.setNickName(getPrincipalAttributeValue(principal, "nickName"));
user.setDisplayName(getPrincipalAttributeValue(principal, "displayName"));
val name = new Name();
name.setGivenName(getPrincipalAttributeValue(principal, "givenName"));
name.setFamilyName(getPrincipalAttributeValue(principal, "familyName"));
name.setMiddleName(getPrincipalAttributeValue(principal, "middleName"));
user.setName(name);
val email = new Email();
email.setPrimary(Boolean.TRUE);
email.setValue(getPrincipalAttributeValue(principal, "email"));
user.setEmails(CollectionUtils.wrap(email));
val phone = new PhoneNumber();
phone.setPrimary(Boolean.TRUE);
phone.setValue(getPrincipalAttributeValue(principal, "phoneNumber"));
user.setPhoneNumbers(CollectionUtils.wrap(phone));
user.setExternalId(getPrincipalAttributeValue(principal, "externalId", principal.getId()));
if (user.getMeta() == null) {
val meta = new Meta();
meta.setCreated(Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC)));
meta.setResourceType(user.getUserType());
user.setMeta(meta);
}
}
Aggregations