Search in sources :

Example 11 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-apimgt by wso2.

the class AMDefaultKeyManagerImpl method getUserClaims.

@Override
public Map<String, String> getUserClaims(String username, Map<String, Object> properties) throws APIManagementException {
    Map<String, String> map = new HashMap<String, String>();
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(username);
    UserInfoDTO userinfo = new UserInfoDTO();
    userinfo.setUsername(tenantAwareUserName);
    if (tenantAwareUserName.contains(CarbonConstants.DOMAIN_SEPARATOR)) {
        userinfo.setDomain(tenantAwareUserName.split(CarbonConstants.DOMAIN_SEPARATOR)[0]);
    }
    if (properties.containsKey(APIConstants.KeyManager.ACCESS_TOKEN)) {
        userinfo.setAccessToken(properties.get(APIConstants.KeyManager.ACCESS_TOKEN).toString());
    }
    if (properties.containsKey(APIConstants.KeyManager.CLAIM_DIALECT)) {
        userinfo.setDialectURI(properties.get(APIConstants.KeyManager.CLAIM_DIALECT).toString());
    }
    if (properties.containsKey(APIConstants.KeyManager.BINDING_FEDERATED_USER_CLAIMS)) {
        userinfo.setBindFederatedUserClaims(Boolean.valueOf(properties.get(APIConstants.KeyManager.BINDING_FEDERATED_USER_CLAIMS).toString()));
    }
    try {
        ClaimsList claims = userClient.generateClaims(userinfo);
        if (claims != null && claims.getList() != null) {
            for (Claim claim : claims.getList()) {
                map.put(claim.getUri(), claim.getValue());
            }
        }
    } catch (KeyManagerClientException e) {
        handleException("Error while getting user info", e);
    }
    return map;
}
Also used : KeyManagerClientException(org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException) HashMap(java.util.HashMap) ClaimsList(org.wso2.carbon.apimgt.impl.kmclient.model.ClaimsList) UserInfoDTO(org.wso2.carbon.apimgt.impl.dto.UserInfoDTO) Claim(org.wso2.carbon.apimgt.impl.kmclient.model.Claim)

Example 12 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromSubscriberClaimsToDTO.

/**
 * Convert Subscriber claims information into SubscriberInfoDTO
 *
 * @param subscriberClaims list of subscriber claims
 * @param subscriberName   subscriber name
 * @return SubscriberInfoDTO
 * @throws APIManagementException If an error occurs when getting display name of claim
 */
public static SubscriberInfoDTO fromSubscriberClaimsToDTO(Map<String, String> subscriberClaims, String subscriberName) throws APIManagementException {
    SubscriberInfoDTO subscriberInfoDTO = new SubscriberInfoDTO();
    subscriberInfoDTO.setName(subscriberName);
    List<ClaimDTO> claimDTOList = new ArrayList<>();
    for (String key : subscriberClaims.keySet()) {
        ClaimDTO claimDTO = new ClaimDTO();
        claimDTO.setName(APIUtil.getClaimDisplayName(key, subscriberName));
        claimDTO.setURI(key);
        claimDTO.setValue(subscriberClaims.get(key));
        claimDTOList.add(claimDTO);
    }
    subscriberInfoDTO.setClaims(claimDTOList);
    return subscriberInfoDTO;
}
Also used : ClaimDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClaimDTO) ArrayList(java.util.ArrayList) SubscriberInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriberInfoDTO)

Example 13 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim 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 14 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project core-util by WSO2Telco.

the class ClaimUtil method convertToClaims.

public org.wso2.carbon.user.core.claim.Claim[] convertToClaims(ClaimDTO[] claims) {
    if (claims == null) {
        return new org.wso2.carbon.user.core.claim.Claim[0];
    }
    org.wso2.carbon.user.core.claim.Claim[] claimz = new org.wso2.carbon.user.core.claim.Claim[claims.length];
    int i = 0;
    for (ClaimDTO claim : claims) {
        claimz[i] = convertToClaim(claim);
        i++;
    }
    return claimz;
}
Also used : ClaimDTO(org.wso2.carbon.um.ws.api.stub.ClaimDTO)

Example 15 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project core-util by WSO2Telco.

the class UserClaimProsser method getUserClaimsByUserName.

public Map<ClaimName, String> getUserClaimsByUserName(String userName) {
    try {
        APIManagerConfiguration config = HostObjectComponent.getAPIManagerConfiguration();
        String remoteUserStoreManagerServiceEndpoint = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL) + AdminServicePath.REMOTE_USER_STORE_MANAGER_SERVICE.getTObject();
        String adminUsername = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME);
        String adminPassword = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD);
        RemoteUserStoreManagerServiceStub userStoreManagerStub = new RemoteUserStoreManagerServiceStub(remoteUserStoreManagerServiceEndpoint);
        CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userStoreManagerStub._getServiceClient());
        ClaimUtil claimUtil = new ClaimUtil();
        Claim[] claims = claimUtil.convertToClaims(userStoreManagerStub.getUserClaimValues(userName, UserProfileType.DEFAULT.getTObject()));
        List<ClaimName> somethingList = Arrays.asList(ClaimName.values());
        for (Iterator<ClaimName> iterator = somethingList.iterator(); iterator.hasNext(); ) {
            ClaimName claimName = iterator.next();
            getClaimValue(claims, claimName);
        }
    } catch (RemoteException | RemoteUserStoreManagerServiceUserStoreExceptionException e) {
        log.error("unable to retrieve claims for user " + userName + " : ", e);
        return Collections.emptyMap();
    }
    return userClaimDetails;
}
Also used : ClaimName(com.wso2telco.core.userprofile.util.ClaimName) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ClaimUtil(com.wso2telco.core.userprofile.util.ClaimUtil) RemoteUserStoreManagerServiceStub(org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceStub) RemoteException(java.rmi.RemoteException) Claim(org.wso2.carbon.user.core.claim.Claim) RemoteUserStoreManagerServiceUserStoreExceptionException(org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceUserStoreExceptionException)

Aggregations

HashMap (java.util.HashMap)112 ArrayList (java.util.ArrayList)89 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)66 UserStoreException (org.wso2.carbon.user.api.UserStoreException)65 Test (org.testng.annotations.Test)63 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)55 Map (java.util.Map)49 PreparedStatement (java.sql.PreparedStatement)48 SQLException (java.sql.SQLException)43 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)34 RealmService (org.wso2.carbon.user.core.service.RealmService)30 UserRealm (org.wso2.carbon.user.core.UserRealm)29 Claim (org.wso2.carbon.user.api.Claim)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)28 ResultSet (java.sql.ResultSet)27 Connection (java.sql.Connection)25 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 Claim (org.wso2.carbon.identity.application.common.model.Claim)24