Search in sources :

Example 1 with Claim

use of org.wso2.carbon.user.core.claim.Claim in project carbon-apimgt by wso2.

the class PolicyDAOImpl method setJWTClaimConditions.

/**
 * Add JWT claim conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
 * provided {@link Condition} array
 *
 * @param pipelineId Id of the pipeline
 * @param conditions condition array to populate
 * @throws SQLException
 */
private void setJWTClaimConditions(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
    final String query = "SELECT " + "CLAIM_URI, " + "CLAIM_ATTRIB , IS_CLAIM_MAPPING " + "FROM " + "AM_JWT_CLAIM_CONDITION " + "WHERE " + "CONDITION_GROUP_ID =?";
    try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        preparedStatement.setInt(1, pipelineId);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
                jwtClaimsCondition.setClaimUrl(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_URI));
                jwtClaimsCondition.setAttribute(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_ATTRIBUTE));
                jwtClaimsCondition.setInvertCondition(resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_IS_CLAIM_MAPPING));
                conditions.add(jwtClaimsCondition);
            }
        }
    }
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with Claim

use of org.wso2.carbon.user.core.claim.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 3 with Claim

use of org.wso2.carbon.user.core.claim.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)

Example 4 with Claim

use of org.wso2.carbon.user.core.claim.Claim 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 5 with Claim

use of org.wso2.carbon.user.core.claim.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)

Aggregations

UserRealm (org.wso2.carbon.user.core.UserRealm)5 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)5 ArrayList (java.util.ArrayList)4 XSString (org.opensaml.core.xml.schema.XSString)4 RealmService (org.wso2.carbon.user.core.service.RealmService)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Assertion (org.opensaml.saml.saml2.core.Assertion)3 Response (org.opensaml.saml.saml2.core.Response)3 Subject (org.opensaml.saml.saml2.core.Subject)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 AuthenticatorsConfiguration (org.wso2.carbon.core.security.AuthenticatorsConfiguration)3 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 UserStoreException (org.wso2.carbon.user.core.UserStoreException)3 Claim (org.wso2.carbon.user.core.claim.Claim)3 RemoteException (java.rmi.RemoteException)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2