Search in sources :

Example 1 with ClaimManager

use of org.wso2.carbon.user.api.ClaimManager in project carbon-apimgt by wso2.

the class APIUtil method getClaims.

/**
 * Returns the user claims for the given user.
 *
 * @param endUserName name of the user whose claims needs to be returned
 * @param tenantId    tenant id of the user
 * @param dialectURI  claim dialect URI
 * @return claims map
 * @throws APIManagementException
 */
public static SortedMap<String, String> getClaims(String endUserName, int tenantId, String dialectURI) throws APIManagementException {
    SortedMap<String, String> claimValues;
    try {
        ClaimManager claimManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getClaimManager();
        ClaimMapping[] claims = claimManager.getAllClaimMappings(dialectURI);
        String[] claimURIs = claimMappingtoClaimURIString(claims);
        UserStoreManager userStoreManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
        String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(endUserName);
        claimValues = new TreeMap(userStoreManager.getUserClaimValues(tenantAwareUserName, claimURIs, null));
        return claimValues;
    } catch (UserStoreException e) {
        throw new APIManagementException("Error while retrieving user claim values from user store", e);
    }
}
Also used : ClaimManager(org.wso2.carbon.user.api.ClaimManager) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) TreeMap(java.util.TreeMap)

Example 2 with ClaimManager

use of org.wso2.carbon.user.api.ClaimManager in project carbon-apimgt by wso2.

the class APIUtil method getClaimDisplayName.

/**
 * Returns the display name of the given claim URI.
 *
 * @param claimURI
 * @param subscriber
 * @return display name of the claim
 * @throws APIManagementException
 */
public static String getClaimDisplayName(String claimURI, String subscriber) throws APIManagementException {
    String tenantDomain = MultitenantUtils.getTenantDomain(subscriber);
    int tenantId;
    String displayName;
    try {
        tenantId = getTenantId(tenantDomain);
        ClaimManager claimManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getClaimManager();
        displayName = claimManager.getClaim(claimURI).getDisplayTag();
    } catch (UserStoreException e) {
        throw new APIManagementException("Error while retrieving claim values from user store", e);
    }
    return displayName;
}
Also used : ClaimManager(org.wso2.carbon.user.api.ClaimManager) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 ClaimManager (org.wso2.carbon.user.api.ClaimManager)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 TreeMap (java.util.TreeMap)1 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)1 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)1 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)1 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)1