Search in sources :

Example 6 with USER_EXT_SCHEMA_ID

use of io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID in project jans by JanssenProject.

the class QueryParamCreateUpdateTest method execAssertions.

private void execAssertions(UserResource user) {
    // Verify "ALWAYS" attribs were retrieved
    assertNotNull(user.getSchemas());
    assertNotNull(user.getId());
    // Verify no password was retrieved
    assertNull(user.getPassword());
    // Verify preferredLanguage is null (not provided in Json originally)
    assertNull(user.getPreferredLanguage());
    // Verify all others are present
    assertNotNull(user.getUserName());
    assertNotNull(user.getDisplayName());
    assertNotNull(user.getNickName());
    assertNotNull(user.getName().getGivenName());
    // Verify cust attrs are there
    CustomAttributes custAttrs = user.getCustomAttributes(USER_EXT_SCHEMA_ID);
    assertNotNull(custAttrs.getValues("scimCustomSecond", Date.class));
    assertNotNull(custAttrs.getValue("scimCustomThird", Integer.class));
    // Verify e-mails were retrieved
    assertNotNull(user.getEmails());
    assertTrue(user.getEmails().stream().map(Email::getValue).map(Optional::ofNullable).allMatch(Optional::isPresent));
}
Also used : CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) Optional(java.util.Optional) Date(java.util.Date)

Example 7 with USER_EXT_SCHEMA_ID

use of io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID in project jans by JanssenProject.

the class QueryParamCreateUpdateTest method update2.

@Test(dependsOnMethods = "update1")
public void update2() throws Exception {
    UserResource cheapClone = getDeepCloneUsr(user);
    cheapClone.setEmails(Collections.emptyList());
    cheapClone.setAddresses(Collections.emptyList());
    cheapClone.setPhoneNumbers(Collections.emptyList());
    cheapClone.setIms(Collections.emptyList());
    cheapClone.setRoles(Collections.emptyList());
    cheapClone.setEntitlements(Collections.emptyList());
    cheapClone.setX509Certificates(Collections.emptyList());
    String exclude = "urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomFirst, urn:ietf:params:scim:schemas:core:2.0:User:active, " + "urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomSecond, externalId, userName, name, " + "urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomThird, userType, title, profileUrl";
    Response response = client.updateUser(cheapClone, cheapClone.getId(), null, exclude);
    assertEquals(response.getStatus(), OK.getStatusCode());
    user = response.readEntity(usrClass);
    assertNotNull(user.getDisplayName());
    assertNotNull(user.getNickName());
    // Verify excluded are not present
    assertNull(user.getCustomAttributes(USER_EXT_SCHEMA_ID));
    assertNull(user.getExternalId());
    assertNull(user.getUserName());
    assertNull(user.getName());
    assertNull(user.getProfileUrl());
    assertNull(user.getUserType());
    assertNull(user.getTitle());
    assertNull(user.getActive());
    // Verify update took place really
    assertNull(user.getEmails());
    assertNull(user.getAddresses());
    assertNull(user.getPhoneNumbers());
    assertNull(user.getIms());
    assertNull(user.getRoles());
    assertNull(user.getEntitlements());
    assertNull(user.getX509Certificates());
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 8 with USER_EXT_SCHEMA_ID

use of io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID in project jans by JanssenProject.

the class PatchUserExtTest method patchObject.

@Test(dependsOnMethods = "patchJson")
public void patchObject() {
    PatchOperation operation = new PatchOperation();
    operation.setOperation("replace");
    operation.setPath("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomSecond");
    long now = System.currentTimeMillis();
    List<String> someDates = Arrays.asList(now, now + 1000, now + 2000, now + 3000).stream().map(DateUtil::millisToISOString).collect(Collectors.toList());
    operation.setValue(someDates);
    PatchRequest pr = new PatchRequest();
    pr.setOperations(Collections.singletonList(operation));
    Response response = client.patchUser(pr, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    CustomAttributes custAttrs = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
    // Verify different dates appeared in scimCustomSecond
    List<Date> scimCustomSecond = custAttrs.getValues("scimCustomSecond", Date.class);
    assertEquals(scimCustomSecond.size(), someDates.size());
    assertEquals(now, scimCustomSecond.get(0).getTime());
}
Also used : Response(javax.ws.rs.core.Response) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 9 with USER_EXT_SCHEMA_ID

use of io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID in project jans by JanssenProject.

the class FullUserTest method searchEscapingChars.

@SkipTest(databases = { "couchbase", "spanner" })
@Test(dependsOnMethods = "updateNonExisting", groups = "lastTests")
public void searchEscapingChars() {
    char quote = '"', backslash = '\\';
    String scapedQuote = String.valueOf(new char[] { backslash, quote });
    String scapedBkSlash = String.valueOf(new char[] { backslash, backslash });
    // Used to generate a random Unicode char
    String rnd = UUID.randomUUID().toString().substring(0, 4);
    String unicodeStr = String.valueOf(Character.toChars(Integer.parseInt(rnd, 16)));
    Name name = user.getName();
    name.setGivenName(String.format("with %cquotes%c", quote, quote));
    name.setMiddleName(String.format("with backslash %c", backslash));
    name.setFamilyName(String.format("%c %c %s", quote, backslash, unicodeStr));
    CustomAttributes attrs = new CustomAttributes(USER_EXT_SCHEMA_ID);
    attrs.setAttribute("scimCustomFirst", String.valueOf(quote));
    user.addCustomAttributes(attrs);
    Response response = client.updateUser(user, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // => name.givenName co "\""
    String filter = String.format("name.givenName co %c%s%c", quote, scapedQuote, quote);
    // => and name.middleName ew "\\"
    filter += String.format(" and name.middleName ew %c%s%c", quote, scapedBkSlash, quote);
    String compValue = String.format("%s %s %cu%s", scapedQuote, scapedBkSlash, backslash, rnd);
    // => and name.familyName eq ""\ \\ \\uWXYZ"
    filter += String.format(" and name.familyName eq %c%s%c", quote, compValue, quote);
    String customFirst = String.format("%s:%s", USER_EXT_SCHEMA_ID, "scimCustomFirst");
    filter += String.format(" and %s eq %c%s%c", customFirst, quote, scapedQuote, quote);
    SearchRequest sr = new SearchRequest();
    sr.setFilter(filter);
    sr.setCount(1);
    sr.setAttributes("name, " + customFirst);
    response = client.searchUsersPost(sr);
    user = (UserResource) response.readEntity(ListResponse.class).getResources().get(0);
    assertEquals(name.getGivenName(), user.getName().getGivenName());
    assertEquals(name.getMiddleName(), user.getName().getMiddleName());
    assertEquals(name.getFamilyName(), user.getName().getFamilyName());
    // Verify the unicode character is intact
    compValue = user.getName().getFamilyName();
    // pick the last char
    compValue = compValue.substring(compValue.length() - 1);
    assertEquals(unicodeStr, compValue);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) Name(io.jans.scim.model.scim2.user.Name) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest) SkipTest(io.jans.scim2.listener.SkipTest)

Example 10 with USER_EXT_SCHEMA_ID

use of io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID in project jans by JanssenProject.

the class QueryParamCreateUpdateTest method update1.

@Test(dependsOnMethods = "create2")
public void update1() throws Exception {
    // Change some attributes existing in user object
    UserResource cheapClone = getDeepCloneUsr(user);
    cheapClone.getName().setGivenName("Bavara");
    cheapClone.setNickName("Cloned");
    String rndString = Double.toString(Math.random());
    // For help on usage of io.jans.scim.model.scim2.CustomAttributes class, read its api docs (oxtrust-scim maven project)
    CustomAttributes custAttrs = cheapClone.getCustomAttributes(USER_EXT_SCHEMA_ID);
    custAttrs.setAttribute("scimCustomFirst", rndString);
    String include = "userName, name.givenName, nickName, urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomFirst";
    Response response = client.updateUser(cheapClone, cheapClone.getId(), include, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    user = response.readEntity(usrClass);
    assertNull(user.getDisplayName());
    assertEquals(user.getName().getGivenName(), cheapClone.getName().getGivenName());
    assertEquals(user.getNickName(), cheapClone.getNickName());
    custAttrs = user.getCustomAttributes(USER_EXT_SCHEMA_ID);
    assertNull(custAttrs.getValues("scimCustomSecond", Date.class));
    assertNull(custAttrs.getValue("scimCustomThird", Integer.class));
    assertEquals(custAttrs.getValue("scimCustomFirst", String.class), rndString);
}
Also used : Response(javax.ws.rs.core.Response) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) UserResource(io.jans.scim.model.scim2.user.UserResource) Date(java.util.Date) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)8 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)7 UserBaseTest (io.jans.scim2.client.UserBaseTest)7 Response (javax.ws.rs.core.Response)7 UserResource (io.jans.scim.model.scim2.user.UserResource)6 ListResponse (io.jans.scim.model.scim2.ListResponse)3 SkipTest (io.jans.scim2.listener.SkipTest)3 Parameters (org.testng.annotations.Parameters)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Optional (java.util.Optional)2 GluuAttribute (io.jans.model.GluuAttribute)1 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)1 USER_EXT_SCHEMA_ID (io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID)1 SearchRequest (io.jans.scim.model.scim2.SearchRequest)1 Extension (io.jans.scim.model.scim2.extensions.Extension)1 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)1 Fido2DeviceResource (io.jans.scim.model.scim2.fido.Fido2DeviceResource)1 FidoDeviceResource (io.jans.scim.model.scim2.fido.FidoDeviceResource)1 GroupResource (io.jans.scim.model.scim2.group.GroupResource)1