8

I need to know how to get wso2 users by claim value, to perform some kind of search?

example:

getUsersByClaimValue(String claimUri, String claimValue);

Adrian Mitev
  • 4,722
  • 3
  • 31
  • 53
Stepan Bahdikyan
  • 358
  • 2
  • 11

1 Answers1

6

Yes.This API method has been introduced to user store API to get user names associated with particular user's attribute. say you want to get users whose "country" attribute value is "USA". then you can use this method as follows.

getUserList("http://wso2.org/claims/country", "USA", null);

You can find this method as web service API in RemoteUserStoreManagerService of WSO2IS. Your SOAP message would look likes follows.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.ws.um.carbon.wso2.org"> <soapenv:Header/> <soapenv:Body> <ser:getUserList> <ser:claimUri>http://wso2.org/claims/country</ser:claimUri> <ser:claimValue>USA</ser:claimValue> <ser:profile></ser:profile> </ser:getUserList> </soapenv:Body> </soapenv:Envelope>

Here, this claim uri is generic one which is independent of the user store. With WSO2 Identity server you can map these claim uri in to any attribute in your user store. More details from here

Asela
  • 5,781
  • 1
  • 15
  • 23
  • 1
    Thank you for the fast answer, but I can't see such method in org.wso2.carbon.user.core.UserStoreManager.class. Should I have to use another class? – Stepan Bahdikyan Aug 15 '12 at 08:33
  • 1
    In above class you can find it as getUserList("http://wso2.org/claims/country", "USA" ,"default"). Here third parameter is the profile. By default it would be "default" profile. sorry i actually miss the method name... :)... – Asela Aug 20 '12 at 10:22
  • I've tried this but I'm getting an empty String[] every time. – Stepan Bahdikyan Sep 05 '12 at 11:13
  • This is the implementation in WSUserStoreManager.class @Override public String[] getUserList(String claim, String claimValue, String profileName) throws UserStoreException { // TODO return new String[0]; } – Stepan Bahdikyan Sep 05 '12 at 11:18
  • This answer seems to be outdated. There is now `UserStoreManager.listUsers` which takes some kind of query string. – Thilo Sep 30 '15 at 03:40
  • 2
    Thanks. Method name is not correct. Updated it. However `listUser()` is just for listing all users, not to search by attribute. It is not correct. – Asela Sep 30 '15 at 05:38
  • I finally found the method `getUserList`. It is defined in `core.UserStoreManager`, but not in `api.UserStoreManager`. A downcast fixed that (I got the UserStoreManager from an `api.UserRealm`). Should one be accessing `core` from web service client code? – Thilo Oct 07 '15 at 06:16