Search in sources :

Example 1 with Name

use of com.unboundid.scim.data.Name in project cas by apereo.

the class Scim1PrincipalAttributeMapper 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);
    user.setNickName(getPrincipalAttributeValue(p, "nickName"));
    user.setDisplayName(getPrincipalAttributeValue(p, "displayName"));
    final Name name = new Name(getPrincipalAttributeValue(p, "formattedName"), getPrincipalAttributeValue(p, "familyName"), getPrincipalAttributeValue(p, "middleName"), getPrincipalAttributeValue(p, "givenName"), getPrincipalAttributeValue(p, "honorificPrefix"), getPrincipalAttributeValue(p, "honorificSuffix"));
    user.setName(name);
    Entry entry = new Entry(getPrincipalAttributeValue(p, "mail"), "primary");
    user.setEmails(CollectionUtils.wrap(entry));
    entry = new Entry(getPrincipalAttributeValue(p, "phoneNumber"), "primary");
    user.setPhoneNumbers(CollectionUtils.wrap(entry));
}
Also used : Entry(com.unboundid.scim.data.Entry) Name(com.unboundid.scim.data.Name)

Example 2 with Name

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

Example 3 with Name

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

Example 4 with Name

use of com.unboundid.scim.data.Name in project cas by apereo.

the class ScimV1PrincipalAttributeMapper 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 Credential credential) {
    user.setUserName(p.getId());
    if (credential instanceof UsernamePasswordCredential) {
        user.setPassword(UsernamePasswordCredential.class.cast(credential).getPassword());
    }
    user.setActive(Boolean.TRUE);
    user.setNickName(getPrincipalAttributeValue(p, "nickName"));
    user.setDisplayName(getPrincipalAttributeValue(p, "displayName"));
    val name = new Name(getPrincipalAttributeValue(p, "formattedName"), getPrincipalAttributeValue(p, "familyName"), getPrincipalAttributeValue(p, "middleName"), getPrincipalAttributeValue(p, "givenName"), getPrincipalAttributeValue(p, "honorificPrefix"), getPrincipalAttributeValue(p, "honorificSuffix"));
    user.setName(name);
    val entry = new Entry(getPrincipalAttributeValue(p, "mail"), "primary");
    user.setEmails(CollectionUtils.wrap(entry));
    val entry2 = new Entry(getPrincipalAttributeValue(p, "phoneNumber"), "primary");
    user.setPhoneNumbers(CollectionUtils.wrap(entry2));
}
Also used : lombok.val(lombok.val) Entry(com.unboundid.scim.data.Entry) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Name(com.unboundid.scim.data.Name)

Aggregations

Name (com.unboundid.scim.data.Name)4 lombok.val (lombok.val)3 Entry (com.unboundid.scim.data.Entry)2 Meta (com.unboundid.scim.data.Meta)2 UserResource (com.unboundid.scim.data.UserResource)2 URI (java.net.URI)2 Date (java.util.Date)2 Test (org.junit.jupiter.api.Test)2 JsonMarshaller (com.unboundid.scim.marshal.json.JsonMarshaller)1 Resources (com.unboundid.scim.sdk.Resources)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 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