Search in sources :

Example 1 with ClaimValue

use of org.wso2.carbon.identity.test.integration.service.dao.ClaimValue in project airavata by apache.

the class MigrationManager method getUserProfilesFromWso2IS.

/* Method used to fetch all the user profiles from the registered tenants */
public List<UserProfileDAO> getUserProfilesFromWso2IS() {
    ArrayList<UserProfileDAO> userProfileList = new ArrayList<UserProfileDAO>();
    for (Wso2ISLoginCredentialsDAO creds : adminCredentials) {
        RemoteUserStoreManagerServiceStub isClient = Wso2IdentityServerClient.getAdminServiceClient(creds.getLoginUserName(), creds.getLoginPassword(), "RemoteUserStoreManagerService");
        String[] userList;
        System.out.println("Fetching User Profiles for " + creds.getGateway() + " tenant ...");
        try {
            userList = isClient.getUserList("http://wso2.org/claims/givenname", "*", "default");
            System.out.println("FirstName\tLastName\tEmail\t\t\tuserName\tCountry\tOrganization\tphone\tRoles");
            String[] claims = { "http://wso2.org/claims/givenname", "http://wso2.org/claims/lastname", "http://wso2.org/claims/emailaddress", "http://wso2.org/claims/country", "http://wso2.org/claims/organization", "http://wso2.org/claims/mobile", "http://wso2.org/claims/telephone", "http://wso2.org/claims/streetaddress", "http://wso2.org/claims/role", "http://wso2.org/claims/identity/accountLocked" };
            for (String user : userList) {
                UserProfileDAO userProfile = new UserProfileDAO();
                ClaimValue[] retrievedClaimValues = isClient.getUserClaimValuesForClaims(user, claims, null);
                List<String> phones = new ArrayList<String>();
                for (ClaimValue claim : retrievedClaimValues) {
                    if (claim.getClaimURI().equals(claims[0])) {
                        userProfile.setFirstName(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[1])) {
                        userProfile.setLastName(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[2])) {
                        userProfile.setEmail(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[3])) {
                        userProfile.setCountry(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[4])) {
                        userProfile.setOrganization(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[5]) || claim.getClaimURI().equals(claims[6])) {
                        phones.add(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[7])) {
                        userProfile.setAddress(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[8])) {
                        userProfile.setRoles(convertCommaSeparatedRolesToList(claim.getValue()));
                    } else if (claim.getClaimURI().equals(claims[9])) {
                        userProfile.setAccountLocked(claim.getValue().equals("true"));
                    }
                }
                // Lowercase all usernames as required by Keycloak and User Profile service
                userProfile.setUserName(user.toLowerCase());
                userProfile.setGatewayID(creds.getGateway());
                userProfile.setPhones(phones);
                if (!userProfile.isAccountLocked()) {
                    System.out.println(userProfile.getFirstName() + "\t" + userProfile.getLastName() + "\t" + userProfile.getUserName() + "\t" + userProfile.getEmail() + "\t" + userProfile.getCountry() + "\t" + userProfile.getOrganization() + "\t" + userProfile.getAddress() + "\t" + userProfile.getRoles());
                    userProfileList.add(userProfile);
                } else {
                    System.out.println("Skipping locked account for user " + user + "!");
                }
            }
        } catch (RemoteException e) {
            System.out.println(e.getMessage());
            System.out.println(e.getCause());
            e.printStackTrace();
        } catch (RemoteUserStoreManagerServiceUserStoreExceptionException e) {
            System.out.println(e.getMessage());
            System.out.println(e.getCause());
            e.printStackTrace();
        }
    }
    System.out.println("User profiles from all the tenant are retrieved ...");
    return userProfileList;
}
Also used : ClaimValue(org.wso2.carbon.um.ws.api.stub.ClaimValue) RemoteUserStoreManagerServiceStub(org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceStub) RemoteException(java.rmi.RemoteException) RemoteUserStoreManagerServiceUserStoreExceptionException(org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceUserStoreExceptionException)

Example 2 with ClaimValue

use of org.wso2.carbon.identity.test.integration.service.dao.ClaimValue in project core-util by WSO2Telco.

the class UserClaimProsser method getClaimValue.

private void getClaimValue(Claim[] claims, ClaimName claimName) {
    for (int i = 0; i < claims.length; i++) {
        Claim claim = claims[i];
        if (claim.getClaimUri().equalsIgnoreCase(claimName.getClaimURL())) {
            String claimValue = claim.getValue();
            userClaimDetails.put(claimName, claimValue);
        }
    }
}
Also used : Claim(org.wso2.carbon.user.core.claim.Claim)

Example 3 with ClaimValue

use of org.wso2.carbon.identity.test.integration.service.dao.ClaimValue in project carbon-identity-framework by wso2.

the class DefaultAttributeFinder method getAttributeValues.

/*
     * (non-Javadoc)
	 * 
	 * @see
	 * org.wso2.carbon.identity.entitlement.pip.PIPAttributeFinder#getAttributeValues(java.lang.
	 * String, java.lang.String, java.lang.String)
	 */
public Set<String> getAttributeValues(String subjectId, String resourceId, String actionId, String environmentId, String attributeId, String issuer) throws Exception {
    Set<String> values = new HashSet<String>();
    if (log.isDebugEnabled()) {
        log.debug("Retrieving attribute values of subjectId \'" + subjectId + "\'with attributeId \'" + attributeId + "\'");
    }
    if (StringUtils.isEmpty(subjectId)) {
        if (log.isDebugEnabled()) {
            log.debug("subjectId value is null or empty. Returning empty attribute set");
        }
        return values;
    }
    subjectId = MultitenantUtils.getTenantAwareUsername(subjectId);
    if (UserCoreConstants.ClaimTypeURIs.ROLE.equals(attributeId)) {
        if (log.isDebugEnabled()) {
            log.debug("Looking for roles via DefaultAttributeFinder");
        }
        String[] roles = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager().getRoleListOfUser(subjectId);
        if (roles != null && roles.length > 0) {
            for (String role : roles) {
                if (log.isDebugEnabled()) {
                    log.debug(String.format("User %1$s belongs to the Role %2$s", subjectId, role));
                }
                values.add(role);
            }
        }
    } else {
        String claimValue = null;
        try {
            claimValue = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager().getUserClaimValue(subjectId, attributeId, null);
            if (log.isDebugEnabled()) {
                log.debug("Claim \'" + claimValue + "\' retrieved for attributeId \'" + attributeId + "\' " + "for subjectId \'" + subjectId + "\'");
            }
        } catch (UserStoreException e) {
            if (e.getMessage().startsWith(IdentityCoreConstants.USER_NOT_FOUND)) {
                if (log.isDebugEnabled()) {
                    log.debug("User: " + subjectId + " not found in user store");
                }
            } else {
                throw e;
            }
        }
        if (claimValue == null && log.isDebugEnabled()) {
            log.debug(String.format("Request attribute %1$s not found", attributeId));
        }
        // Fix for multiple claim values
        if (claimValue != null) {
            String claimSeparator = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
            if (StringUtils.isBlank(claimSeparator)) {
                claimSeparator = IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR_DEFAULT;
            }
            if (claimValue.contains(claimSeparator)) {
                StringTokenizer st = new StringTokenizer(claimValue, claimSeparator);
                while (st.hasMoreElements()) {
                    String attributeValue = st.nextElement().toString();
                    if (StringUtils.isNotBlank(attributeValue)) {
                        values.add(attributeValue);
                    }
                }
            } else {
                values.add(claimValue);
            }
        }
    }
    return values;
}
Also used : StringTokenizer(java.util.StringTokenizer) UserStoreException(org.wso2.carbon.user.api.UserStoreException) HashSet(java.util.HashSet)

Example 4 with ClaimValue

use of org.wso2.carbon.identity.test.integration.service.dao.ClaimValue in project carbon-identity-framework by wso2.

the class Utils method getClaimFromUserStoreManager.

/**
 * Get the claims from the user store manager
 *
 * @param userName user name
 * @param tenantId tenantId
 * @param claim    claim name
 * @return claim value
 * @throws IdentityException if fails
 */
public static String getClaimFromUserStoreManager(String userName, int tenantId, String claim) throws IdentityException {
    org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
    RealmService realmService = IdentityMgtServiceComponent.getRealmService();
    String claimValue = "";
    try {
        if (realmService.getTenantUserRealm(tenantId) != null) {
            userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
        }
    } catch (Exception e) {
        String msg = "Error retrieving the user store manager for tenant id : " + tenantId;
        log.error(msg, e);
        throw IdentityException.error(msg, e);
    }
    try {
        if (userStoreManager != null) {
            Map<String, String> claimsMap = userStoreManager.getUserClaimValues(userName, new String[] { claim }, UserCoreConstants.DEFAULT_PROFILE);
            if (claimsMap != null && !claimsMap.isEmpty()) {
                claimValue = claimsMap.get(claim);
            }
        }
        return claimValue;
    } catch (Exception e) {
        String msg = "Unable to retrieve the claim for user : " + userName;
        log.error(msg, e);
        throw IdentityException.error(msg, e);
    }
}
Also used : RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 5 with ClaimValue

use of org.wso2.carbon.identity.test.integration.service.dao.ClaimValue in project carbon-identity-framework by wso2.

the class ProvisioningUtil method getMappedClaims.

public static Map<ClaimMapping, List<String>> getMappedClaims(String outboundClaimDialect, Map<String, String> inboundClaimValueMap, String inboundClaimMappingDialect, Map<ClaimMapping, List<String>> outboundClaimValueMappings, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            return outboundClaimValueMappings;
        }
        Map<String, String> claimMap = null;
        if (IdentityApplicationConstants.WSO2CARBON_CLAIM_DIALECT.equals(inboundClaimMappingDialect)) {
            // in-bound dialect is in default carbon dialect.
            // otherDialectURI, carbonClaimURIs, tenantDomain, carbonDialectAsKey
            // this map will have out-bound dialect as the key.
            claimMap = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(outboundClaimDialect, null, tenantDomain, true);
        } else {
            // out-bound is not in wso2 carbon dialect. we need to find how it maps to wso2
            // carbon dialect.
            Map<String, String> inboundToCarbonClaimMaping = null;
            Map<String, String> outBoundToCarbonClaimMappping = null;
            // this will return back the mapped carbon dialect for the in-bound claims in the
            // in-bound provisioning request.
            // the key of this map will be in in-bound claim dialect.
            inboundToCarbonClaimMaping = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(inboundClaimMappingDialect, inboundClaimValueMap.keySet(), tenantDomain, false);
            // we only know the dialect - it is standard claim dialect.
            // this will return back all the wso2 carbon claims mapped to the out-bound dialect.
            // we send null here because we do not know the required claims for out-bound
            // provisioning.
            // the key of this map will be in carbon dialect.
            outBoundToCarbonClaimMappping = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(outboundClaimDialect, null, tenantDomain, true);
            // in-bound dialect / out-bound dialect.
            claimMap = new HashMap<String, String>();
            for (Iterator<Map.Entry<String, String>> iterator = inboundToCarbonClaimMaping.entrySet().iterator(); iterator.hasNext(); ) {
                Map.Entry<String, String> entry = iterator.next();
                String outboundClaim = outBoundToCarbonClaimMappping.get(entry.getValue());
                if (outboundClaim != null) {
                    claimMap.put(entry.getKey(), outboundClaim);
                }
            }
        }
        if (claimMap.isEmpty()) {
            return outboundClaimValueMappings;
        }
        // through the in-bound provisioning claim map.
        for (Iterator<Map.Entry<String, String>> iterator = claimMap.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, String> entry = iterator.next();
            String outboundClaimUri = entry.getValue();
            String inboundClaimUri = entry.getKey();
            String claimValue = null;
            if (outboundClaimUri != null) {
                claimValue = inboundClaimValueMap.get(inboundClaimUri);
            }
            if (claimValue != null) {
                outboundClaimValueMappings.put(ClaimMapping.build(inboundClaimUri, outboundClaimUri, null, false), Arrays.asList(new String[] { claimValue }));
            }
        }
    } catch (Exception e) {
        throw new IdentityApplicationManagementException("Error while loading claim mappings.", e);
    }
    return outboundClaimValueMappings;
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) HashMap(java.util.HashMap) Map(java.util.Map) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)

Aggregations

ClaimValue (org.wso2.carbon.um.ws.api.stub.ClaimValue)23 HashMap (java.util.HashMap)21 Test (org.testng.annotations.Test)19 UserStoreException (org.wso2.carbon.user.core.UserStoreException)14 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)14 Map (java.util.Map)13 ArrayList (java.util.ArrayList)11 RemoteException (java.rmi.RemoteException)9 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)9 UserStoreException (org.wso2.carbon.user.api.UserStoreException)9 ClaimValue (org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue)9 IdentityException (org.wso2.carbon.identity.base.IdentityException)8 WorkflowAdminServiceWorkflowException (org.wso2.carbon.identity.workflow.mgt.stub.WorkflowAdminServiceWorkflowException)8 Association (org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association)8 Matchers.anyString (org.mockito.Matchers.anyString)7 FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)7 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)6 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)5 ClaimValue (org.wso2.carbon.user.mgt.common.ClaimValue)5 HashSet (java.util.HashSet)4