Search in sources :

Example 1 with UserResource

use of com.unboundid.scim2.common.types.UserResource in project cas by apereo.

the class Scim2Provisioner method createUserResource.

private boolean createUserResource(final Principal p, final UsernamePasswordCredential credential) throws Exception {
    final UserResource user = new UserResource();
    this.mapper.map(user, p, credential);
    return scimService.create("Users", user) != null;
}
Also used : UserResource(com.unboundid.scim2.common.types.UserResource)

Example 2 with UserResource

use of com.unboundid.scim2.common.types.UserResource in project cas by apereo.

the class Scim2PrincipalAttributeMapper method map.

/**
 * Map.
 *
 * @param user       the user
 * @param p          the p
 * @param credential the credential
 */
public void map(final UserResource user, final Principal p, final UsernamePasswordCredential credential) {
    user.setUserName(p.getId());
    user.setPassword(credential.getPassword());
    user.setActive(Boolean.TRUE);
    String attr = getPrincipalAttributeValue(p, "nickName");
    user.setNickName(attr);
    attr = getPrincipalAttributeValue(p, "displayName");
    user.setDisplayName(attr);
    final Name name = new Name();
    attr = getPrincipalAttributeValue(p, "givenName");
    name.setGivenName(attr);
    attr = getPrincipalAttributeValue(p, "familyName");
    name.setFamilyName(attr);
    attr = getPrincipalAttributeValue(p, "middleName");
    name.setMiddleName(attr);
    user.setName(name);
    final Email email = new Email();
    email.setPrimary(Boolean.TRUE);
    attr = getPrincipalAttributeValue(p, "mail");
    if (StringUtils.isBlank(attr)) {
        attr = getPrincipalAttributeValue(p, "email");
    }
    email.setValue(attr);
    user.setEmails(CollectionUtils.wrap(email));
    final PhoneNumber phone = new PhoneNumber();
    phone.setPrimary(Boolean.TRUE);
    attr = getPrincipalAttributeValue(p, "phone");
    if (StringUtils.isBlank(attr)) {
        attr = getPrincipalAttributeValue(p, "phoneNumber");
    }
    phone.setValue(attr);
    user.setPhoneNumbers(CollectionUtils.wrap(phone));
}
Also used : Email(com.unboundid.scim2.common.types.Email) PhoneNumber(com.unboundid.scim2.common.types.PhoneNumber) Name(com.unboundid.scim2.common.types.Name)

Example 3 with UserResource

use of com.unboundid.scim2.common.types.UserResource 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());
    }
}
Also used : lombok.val(lombok.val) Meta(com.unboundid.scim2.common.types.Meta) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) UserResource(com.unboundid.scim2.common.types.UserResource) MockWebServer(org.apereo.cas.util.MockWebServer) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ByteArrayResource(org.springframework.core.io.ByteArrayResource) URI(java.net.URI) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Name(com.unboundid.scim2.common.types.Name) Test(org.junit.jupiter.api.Test)

Example 4 with UserResource

use of com.unboundid.scim2.common.types.UserResource 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());
        }
    });
}
Also used : lombok.val(lombok.val) Meta(com.unboundid.scim2.common.types.Meta) UserResource(com.unboundid.scim2.common.types.UserResource) Executable(org.junit.jupiter.api.function.Executable) URI(java.net.URI) Name(com.unboundid.scim2.common.types.Name) Test(org.junit.jupiter.api.Test)

Example 5 with UserResource

use of com.unboundid.scim2.common.types.UserResource 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);
    }
}
Also used : lombok.val(lombok.val) Meta(com.unboundid.scim2.common.types.Meta) Email(com.unboundid.scim2.common.types.Email) PhoneNumber(com.unboundid.scim2.common.types.PhoneNumber) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Name(com.unboundid.scim2.common.types.Name)

Aggregations

Name (com.unboundid.scim2.common.types.Name)4 UserResource (com.unboundid.scim2.common.types.UserResource)4 lombok.val (lombok.val)4 Meta (com.unboundid.scim2.common.types.Meta)3 Email (com.unboundid.scim2.common.types.Email)2 PhoneNumber (com.unboundid.scim2.common.types.PhoneNumber)2 URI (java.net.URI)2 Test (org.junit.jupiter.api.Test)2 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)1 MockWebServer (org.apereo.cas.util.MockWebServer)1 Executable (org.junit.jupiter.api.function.Executable)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 MockRequestContext (org.springframework.webflow.test.MockRequestContext)1