WSO2 get user by claim value
Asked Answered
S

1

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);

Superdominant answered 13/8, 2012 at 11:56 Comment(0)
B
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

Bougainville answered 14/8, 2012 at 12:22 Comment(7)
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?Superdominant
In above class you can find it as getUserList("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... :)...Bougainville
I've tried this but I'm getting an empty String[] every time.Superdominant
This is the implementation in WSUserStoreManager.class @Override public String[] getUserList(String claim, String claimValue, String profileName) throws UserStoreException { // TODO return new String[0]; }Superdominant
This answer seems to be outdated. There is now UserStoreManager.listUsers which takes some kind of query string.Teillo
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.Bougainville
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?Teillo

© 2022 - 2024 — McMap. All rights reserved.