use of com.unboundid.scim.data.UserResource in project cas by apereo.
the class ScimV1PrincipalAttributeMapperTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val user = new UserResource(CoreSchema.USER_DESCRIPTOR);
user.setActive(true);
user.setDisplayName("CASUser");
user.setId("casuser");
val name = new Name("formatted", "family", "middle", "givenMame", "prefix", "prefix2");
name.setGivenName("casuser");
user.setName(name);
val meta = new Meta(new Date(), new Date(), new URI("http://localhost:8215"), "1");
meta.setCreated(new Date());
user.setMeta(meta);
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
val mapper = new ScimV1PrincipalAttributeMapper();
mapper.map(user, CoreAuthenticationTestUtils.getPrincipal(), CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
}
});
}
use of com.unboundid.scim.data.UserResource in project cas by apereo.
the class PrincipalScimV1ProvisionerActionTests 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(CoreSchema.USER_DESCRIPTOR);
user.setActive(true);
user.setDisplayName("CASUser");
user.setId("casuser");
val name = new Name("formatted", "family", "middle", "givenMame", "prefix", "prefix2");
name.setGivenName("casuser");
user.setName(name);
val meta = new Meta(new Date(), new Date(), new URI("http://localhost:8215"), "1");
meta.setCreated(new Date());
user.setMeta(meta);
val resources = new Resources(CollectionUtils.wrapList(user));
val stream = new ByteArrayOutputStream();
resources.marshal(new JsonMarshaller(), stream);
val data = stream.toString(StandardCharsets.UTF_8);
try (val webServer = new MockWebServer(8215, 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.scim.data.UserResource in project cas by apereo.
the class ScimV1PrincipalProvisioner method createUserResource.
/**
* Create user resource boolean.
*
* @param principal the p
* @param credential the credential
* @return true /false
* @throws Exception the exception
*/
protected boolean createUserResource(final Principal principal, final Credential credential) throws Exception {
val user = new UserResource(CoreSchema.USER_DESCRIPTOR);
this.mapper.map(user, principal, credential);
return getScimEndpoint().create(user) != null;
}
use of com.unboundid.scim.data.UserResource in project cas by apereo.
the class Scim1Provisioner method createUserResource.
private boolean createUserResource(final Principal p, final UsernamePasswordCredential credential) throws Exception {
final UserResource user = new UserResource(CoreSchema.USER_DESCRIPTOR);
this.mapper.map(user, p, credential);
return endpoint.create(user) != null;
}
use of com.unboundid.scim.data.UserResource in project cas by apereo.
the class Scim1Provisioner method create.
@Override
public boolean create(final Principal p, final UsernamePasswordCredential credential) {
try {
final Resources<UserResource> resources = endpoint.query("userName eq \"" + p.getId() + "\"");
if (resources.getItemsPerPage() == 0) {
LOGGER.debug("User [{}] not found", p.getId());
return false;
}
final UserResource user = resources.iterator().next();
if (user != null) {
return updateUserResource(user, p, credential);
}
return createUserResource(p, credential);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
Aggregations