By: ved singh user 12 Nov 2017 at 11:50 p.m. CST

14 Responses
ved singh gravatar
Hi, I was trying to integrate with SCIM-Client (UMA)in Gluu version 3.1.1 I'm facing few issues here: - **Maven dependency version** - The document here : https://gluu.org/docs/ce/3.1.1/user-management/scim2/#testing-with-the-scim-client says to use scim.client.version = 3.1.1, but the maven repository does not have any artifact with coordinate ``` <dependency> <groupId>gluu.scim.client</groupId> <artifactId>SCIM-Client</artifactId> <version>3.1.1</version> </dependency> ``` I had to use 3.1.1.Final . Is this correct? - **SCIM Documentation** : One of the step is to activate the UMA Authorization policies ``` Activate UMA custom script in oxTrust admin GUI: Go to Configuration > Manage Custom Scripts, and in the tab for UMA Authorization policies check "Enabled" for the script labeled "Sample client authz UMA RPT Policy". Finally press the "Update" button. ``` But I don't see that option when i go that page. [Expected](https://drive.google.com/open?id=1qKNqp13uhfClnjNNNxR2SMCVemT5dGHf) [Found](https://drive.google.com/open?id=15yZdGLmAO8_oSroTxRigdmXuejt_F-Pz) Is this needed or it is just documentation error ? - **SCIM api to get user Extension data**: I have a custom attribute in the org.gluu.oxtrust.model.scim2.User object. That attribute is registered and the SCIM support enabled. I'm able to add user with custom attribute via org.gluu.oxtrust.model.scim2.Extension using gluu.scim2.client.ScimClient#createUser api. But when I'm searching for user, I'm getting zero for org.gluu.oxtrust.model.scim2.Extension data in the user object. What can be the possible reason ? Appreciate any help and guidance. Thanks

By Jose Gonzalez staff 14 Nov 2017 at 5:41 a.m. CST

Jose Gonzalez gravatar
Dear Mr. Singh, > I had to use 3.1.1.Final . Is this correct? yes, 3.1.0.Final or 3.1.1.Final should do the task > But I don't see that option when i go that page The script needed is under tab "UMA RPT policies" > SCIM api to get user Extension data Can you please elaborate more on this?. Maybe share some code to understand better?

By ved singh user 14 Nov 2017 at 11:38 a.m. CST

ved singh gravatar
Hi Jose, Thanks for confirming and the response. Find below details of my last query. I have a need to add my own custom attributes to user schema. I followed the steps to add custom attributes as described here: https://gluu.org/docs/ce/3.1.1/admin-guide/attribute/ I'm using SCIM-Client Java library version 3.1.1.Final for scim interactions. Code snippet to add custom attribute: ``` gluu.scim2.client.ScimClient.createUser(createDummyUser(), new String[] {}); ...... private User createDummyUser() throws Exception { final User user = new User(); final Name name = new Name(); name.setGivenName("Darth Vader"); name.setFamilyName("Vader"); user.setName(name); user.setDisplayName(String.format("TestUser_DisplayName_%d", System.currentTimeMillis())); user.setActive(true); user.setUserName("Darth Vader_" + new Date().getTime()); user.setPassword("starwars"); final List<Email> emails = new ArrayList<>(); Email email = new Email(); email.setPrimary(true); email.setValue("darthvader@starwars.com"); emails.add(email); user.setEmails(emails); try { Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID); extensionBuilder.setField("scimCustomAccountId","1"); user.addExtension(extensionBuilder.build()); } catch (Exception e) { e.printStackTrace(); } return user; } ``` The user gets added successfully with custom attribute. No issues in adding user.I can see the value in admin console. But,when I'm retrieving or searching the user, I'm not able to read this custom attribute. Here is the code to search user based on username. ``` public List<User> searchUsers(String aUserName) { List<User> users = Collections.emptyList(); final ScimClient scimClient = getScimClient(); final String filter = "userName eq \"" + aUserName + "\""; int startIndex = 1; int count = 1; final String sortBy = ""; final String sortOrder = ""; final String[] attributes = null; try { final BaseClientResponse<ListResponse> response = scimClient.searchUsers(filter, startIndex, count, sortBy, sortOrder, attributes); if (response.getStatus() == 200) { ListResponse listResponse = response.getEntity(); users = listResponse.getResources().stream().filter(User.class::isInstance).map(User.class::cast) .collect(Collectors.toList()); } } catch (IOException aE) { log.debug(aE) } return users; } ``` Here is the code to read custom attribute: ``` final Extension extension = aUser.getExtension(Constants.USER_EXT_SCHEMA_ID); final Extension.Field accountIdFiled = extension.getFields().get("scimCustomAccountId"); final String accountId = accountIdFiled.getValue(); ``` I'm getting below exception ``` java.util.NoSuchElementException: extension urn:ietf:params:scim:schemas:extension:gluu:2.0:User is not available at org.gluu.oxtrust.model.scim2.User.getExtension(User.java:449) ``` I did check that the attribute is part of the User Extension by verify it here: https://<host-name>/identity/restv1/scim/v2/Schemas/urn:ietf:params:scim:schemas:extension:gluu:2.0:User ``` { "id": "urn:ietf:params:scim:schemas:extension:gluu:2.0:User", "externalId": null, "meta": { "created": null, "lastModified": null, "location": "https://www.imcidp.com/identity/restv1/scim/v2/Schemas/urn:ietf:params:scim:schemas:extension:gluu:2.0:User", "version": null, "resourceType": "Schema" }, "name": "GluuUserCustomExtension", "description": "Gluu User Custom Extension", "attributes": [ { "name": "oxEnrollmentCode", "type": "string", "description": "oxEnrollmentCode", "required": false, "multiValued": false, "caseExact": false, "mutability": "readWrite", "returned": "default", "uniqueness": "none", "subAttributes": [], "referenceTypes": [] }, { "name": "scimCustomAccountId", "type": "string", "description": "Custom user account Id", "required": false, "multiValued": false, "caseExact": false, "mutability": "readWrite", "returned": "default", "uniqueness": "none", "subAttributes": [], "referenceTypes": [] } ] } ``` Let me know if you need more information. Thanks again for your guidance.

By Jose Gonzalez staff 14 Nov 2017 at 6:28 p.m. CST

Jose Gonzalez gravatar
Hi Ved, You are doing everything fine. Smells like deserialization problem... Can you please attach here the raw (Json) response you are having when issuing the search request, example: ``` ... BaseClientResponse<ListResponse> response = scimClient.searchUsers(filter, startIndex, count, sortBy, sortOrder, attributes); log.debug(response.readEntity(String.class)); return null; ... ``` Regards.

By ved singh user 14 Nov 2017 at 6:55 p.m. CST

ved singh gravatar
Hi Jose, I added this block of code: ``` try { final BaseClientResponse<ListResponse> response = scimClient.searchUsers(filter, startIndex, count, sortBy, sortOrder, attributes); System.out.println(response.readEntity(String.class)); if (response.getStatus() == 200) { ListResponse listResponse = response.getEntity(); users=listResponse.getResources().stream().filter(User.class::isInstance).map(User.class::cast) .collect(Collectors.toList()); } } catch (Exception aE) { aE.printStackTrace(); } ``` and getting this exception trace: ``` org.jboss.resteasy.spi.NotImplementedYetException at org.jboss.resteasy.client.core.BaseClientResponse.readEntity(BaseClientResponse.java:608) at com.imc.idm.scim.DefaultScimService.searchUsers(DefaultScimService.java:163) at com.imc.idm.scim.TestGluuScimService.should_search_user(TestGluuScimService.java:87) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) ``` Additionally I've attached debugger view of listresponse variable. [debugger](https://drive.google.com/open?id=1yha4vYLYed6Eom23NL3JCcdFw5Eo_tuU) You can see the extensions size is zero in the image Let me know if you need more info. Thanks

By Jose Gonzalez staff 15 Nov 2017 at 7:50 a.m. CST

Jose Gonzalez gravatar
Ved, My intention is that you can print somehow the json response you are receiving directly from the server (the output transmitted on the wire). That was the aim of the line of code `response.readEntity(String.class)`... but it seems it is not working in your environment. Please do your own research on how to obtain the raw data of a RestEasy response. Once you show the Json content I might determine if it's a bug in server, client libs, or your client code, and offer some solution or workaround... I am talking about something like this: ``` { "schemas":["urn:ietf:params:scim:api:messages:2.0:ListResponse"], "totalResults":1, ... "Resources":[ { "userName":"Darth1", ... } ] } ``` which is pretty similar but **not equal** to your debugger view of the `User` object.

By ved singh user 15 Nov 2017 at 8:48 a.m. CST

ved singh gravatar
Hi Jose, I converted listeResponse to json using gson. Here's the json data. Let me know if this helps. ``` { "totalResults": 1, "startIndex": 1, "itemsPerPage": 1, "schemas": [ "urn:ietf:params:scim:api:messages:2.0:ListResponse" ], "resources": [ { "id": "@!DF95.EFE3.F928.DD97!0001!0992.9975!0000!3029.DF63.E35F.4C3D", "meta": { "created": "2017-11-14T15:43:27.956-05:00", "lastModified": "2017-11-14T15:43:27.956-05:00", "location": "https://dev-gluutest.internal.com/identity/restv1/scim/v2/Users/@!DF95.EFE3.F928.DD97!0001!0992.9975!0000!3029.DF63.E35F.4C3D", "resourceType": "User" }, "schemas": [ "urn:ietf:params:scim:schemas:extension:gluu:2.0:User", "urn:ietf:params:scim:schemas:core:2.0:User" ], "userName": "Darth1", "name": { "formatted": "Darth Vader", "familyName": "Vader", "givenName": "Darth" }, "displayName": "Darth Vader", "active": true, "password": "Hidden for Privacy Reasons", "emails": [ { "value": "DarthVader_1@test.com", "primary": true } ] } ] } ```

By Jose Gonzalez staff 15 Nov 2017 at 10:38 a.m. CST

Jose Gonzalez gravatar
That's exactly what I don't want you to do... you are cheating that way. You are converting a Java object into Json. To get that Java object a deserialization process had to take place before: json -> Java I think the problem lies in the arrow, but we need to see if the server is giving you json properly formatted.

By ved singh user 15 Nov 2017 at 1:05 p.m. CST

ved singh gravatar
Hi Jose, I'm confused here: When scimClient.searchUsers is invoked, the raw response is already invoked, consumed and read in to type class org.gluu.oxtrust.model.scim2.ListResponse. How do i reread it ? The Stream is already closed. Anyway I'm attaching here few more debugger view.See if this is of any help. Unmarshalled response [Debugger-view](https://drive.google.com/open?id=1x-bamDFYnVhvUjCn9t8S47yJWq9U5-fU) Raw Response - i can see here extension is zero [Debugger View 1](https://drive.google.com/open?id=1K0lAys-J3Cfkjo2r9NhXJh1Kd9o9yvXc)

By Jose Gonzalez staff 16 Nov 2017 at 7:04 p.m. CST

Jose Gonzalez gravatar
Ved, I felt curious and tried to replicate. And yes, the response is already consumed... anyways, found an alternative way to inspect the raw data and could verify that custom attributes are included in the response coming from the server. So as I supposed initially, the problem occurs when conversion from Json to Java object is performed. Unfortunately there is no quick solution for this so this issue [https://github.com/GluuFederation/SCIM-Client/issues/55](https://github.com/GluuFederation/SCIM-Client/issues/55) was raised I hope we can get this fixed soon so please stay tuned. The git issue won't be closed until we can verify all test cases still pass and there are no other functionalities affected by changes, however, if you wish you may include the commits part of the fix into your project earlier before testing itself takes place. I will comment on that issue "tests pending" when all commits are done. Next official release of Gluu products will contain this patch, unfortunately it is scheduled for late December. Kind regards, Jose.

By ved singh user 17 Nov 2017 at 3:03 p.m. CST

ved singh gravatar
Thanks for the update Jose.

By Jose Gonzalez staff 18 Nov 2017 at 8:16 a.m. CST

Jose Gonzalez gravatar
Hi, The patch is ready. For your particular case you just would need to include the commit labeled "client side fixes" of the issue into your work. We cannot provide guidance on how to do that because your support plan does not allow but the following are some hints for you. The commit has two files modified and 1 added. These are part of the maven dependency oxtrust-scim (see [pom]( https://github.com/GluuFederation/SCIM-Client/blob/master/pom.xml#L105-L105)). Thus, you will have to generate your own oxtrust-scim.jar. oxtrust-scim is a maven subproject found inside the [oxTrust](https://github.com/GluuFederation/oxTrust/) repo, so you may have to clone it and focus only on compiling the scim maven submodule inside it. There are 3 test cases that involve work with custom extensions in the SCIM-Client for your reference: [UserExtensionsJsonTest](https://github.com/GluuFederation/SCIM-Client/blob/master/src/test/java/gluu/scim2/client/UserExtensionsJsonTest.java), [UserExtensionsObjectTest](https://github.com/GluuFederation/SCIM-Client/blob/master/src/test/java/gluu/scim2/client/UserExtensionsObjectTest.java), [UserObjectAttributesFilterTests](https://github.com/GluuFederation/SCIM-Client/blob/master/src/test/java/gluu/scim2/client/UserObjectAttributesFilterTests.java).

By ved singh user 19 Nov 2017 at 8:49 p.m. CST

ved singh gravatar
Sure Jose. I will give it a spin.

By Jose Gonzalez staff 24 Nov 2017 at 1:06 p.m. CST

Jose Gonzalez gravatar
Hi... closing this issue If you wish, you can use the `3.2.0-SNAPSHOT` version of `SCIM-Client` artifact in your `pom.xml` which contains the patch. Apart from that, there are no actual differences between 3.2.0-snap and 3.1.1.Final

By ved singh user 24 Nov 2017 at 1:19 p.m. CST

ved singh gravatar
Sure Jose. I will upgrade to new version. Thanks.