Search in sources :

Example 1 with UserIdentityClaimDTO

use of org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method updateUserIdentityClaims.

/**
 * Updates users recovery data such as the phone number, email etc
 *
 * @param userStoreManager
 * @param userIdentityRecoveryData
 * @throws IdentityException
 */
public static void updateUserIdentityClaims(String userName, UserStoreManager userStoreManager, UserIdentityClaimDTO[] userIdentityRecoveryData) throws IdentityException {
    UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
    UserIdentityClaimsDO userIdentityDO = store.load(userName, userStoreManager);
    if (userIdentityDO != null) {
        userIdentityDO.updateUserIdentityRecoveryData(userIdentityRecoveryData);
        store.store(userIdentityDO, userStoreManager);
    } else {
        throw IdentityException.error("No user account found for user " + userName);
    }
}
Also used : UserIdentityDataStore(org.wso2.carbon.identity.mgt.store.UserIdentityDataStore) UserIdentityClaimsDO(org.wso2.carbon.identity.mgt.dto.UserIdentityClaimsDO)

Example 2 with UserIdentityClaimDTO

use of org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method getAllUserIdentityClaims.

/**
 * Returns all user claims
 *
 * @param userName
 * @return
 * @throws IdentityMgtServiceException
 */
public static UserIdentityClaimDTO[] getAllUserIdentityClaims(String userName) throws IdentityMgtServiceException {
    int tenantId = 0;
    try {
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        UserStoreManager userStoreManager = IdentityMgtServiceComponent.getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
        // read all claims and convert them to UserIdentityClaimDTO
        Claim[] claims = userStoreManager.getUserClaimValues(userName, null);
        List<UserIdentityClaimDTO> allDefaultClaims = new ArrayList<UserIdentityClaimDTO>();
        for (Claim claim : claims) {
            if (claim.getClaimUri().contains(UserCoreConstants.DEFAULT_CARBON_DIALECT)) {
                UserIdentityClaimDTO claimDTO = new UserIdentityClaimDTO();
                claimDTO.setClaimUri(claim.getClaimUri());
                claimDTO.setClaimValue(claim.getValue());
                allDefaultClaims.add(claimDTO);
            }
        }
        UserIdentityClaimDTO[] claimDTOs = new UserIdentityClaimDTO[allDefaultClaims.size()];
        return allDefaultClaims.toArray(claimDTOs);
    } catch (UserStoreException e) {
        throw new IdentityMgtServiceException("Error while getting user identity claims", e);
    }
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) UserIdentityClaimDTO(org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO) Claim(org.wso2.carbon.user.api.Claim)

Example 3 with UserIdentityClaimDTO

use of org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method getUsernameByClaims.

/**
 * @param claims
 * @param tenantId
 * @return
 * @throws IdentityMgtServiceException - If user cannot be retrieved using the provided claims.
 */
public static String getUsernameByClaims(UserIdentityClaimDTO[] claims, int tenantId) throws IdentityMgtServiceException {
    if (claims == null || claims.length < 1) {
        throw new IdentityMgtServiceException("No fields found for user search");
    }
    String userName = null;
    String[] tempUserList = null;
    // passed array.
    for (int i = 0; i < claims.length; i++) {
        UserIdentityClaimDTO claim = claims[i];
        if (claim.getClaimUri() != null && claim.getClaimValue() != null) {
            String[] userList = getUserList(tenantId, claim.getClaimUri(), claim.getClaimValue(), null);
            if (userList != null && userList.length > 0) {
                if (userList.length == 1) {
                    return userList[0];
                } else {
                    // If more than one user find the first matching user. Hence need to define unique claims
                    if (tempUserList != null) {
                        for (int j = 0; j < tempUserList.length; j++) {
                            for (int x = 0; x < userList.length; x++) {
                                if (tempUserList[j].equals(userList[x])) {
                                    return userList[x];
                                }
                            }
                        }
                    }
                    tempUserList = userList;
                    continue;
                }
            } else {
                throw new IdentityMgtServiceException("No associated user is found for given claim values");
            }
        }
    }
    return userName;
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserIdentityClaimDTO(org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO)

Example 4 with UserIdentityClaimDTO

use of org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO in project product-is by wso2.

the class UserInformationRecoveryServiceTenantEmailUserTestCase method testVerifyUserAccount.

@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(groups = "wso2.is", description = "Check user account verification")
public void testVerifyUserAccount() throws Exception {
    UserIdentityClaimDTO[] claims = new UserIdentityClaimDTO[1];
    UserIdentityClaimDTO claimEmail = new UserIdentityClaimDTO();
    claimEmail.setClaimUri(USERNAME_CLAIM_URI);
    claimEmail.setClaimValue(TENANT_USER);
    claims[0] = claimEmail;
    VerificationBean bean = infoRecoveryClient.verifyAccount(claims, null, TENANT_DOMAIN);
    Assert.assertTrue(bean.getVerified(), "Verifying user account has failed with null return");
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.stub.beans.VerificationBean) UserIdentityClaimDTO(org.wso2.carbon.identity.mgt.stub.dto.UserIdentityClaimDTO) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 5 with UserIdentityClaimDTO

use of org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO in project product-is by wso2.

the class UserInformationRecoveryServiceTestCase method testVerifyUserAccount.

// @SetEnvironment(executionEnvironments = { ExecutionEnvironment.integration_all })
// @Test(groups = "wso2.is", description = "Check getting supported claims")
// public void testGetUserIdentitySupportedClaims() throws Exception {
// loginManger.login("admin", "admin", isServer.getBackEndUrl());
// UserIdentityClaimDTO[] bean = infoRecoveryClient.getUserIdentitySupportedClaims("http://wso2.org/claims");
// Assert.assertNotNull(bean, "Getting supported claims has failed with null return");
// }
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(groups = "wso2.is", description = "Check user account verification", dependsOnMethods = "testVerifyUserChallengeAnswer")
public void testVerifyUserAccount() throws Exception {
    UserIdentityClaimDTO[] claims = new UserIdentityClaimDTO[2];
    UserIdentityClaimDTO claimEmail = new UserIdentityClaimDTO();
    claimEmail.setClaimUri("http://wso2.org/claims/emailaddress");
    claimEmail.setClaimValue("user11@wso2.com");
    UserIdentityClaimDTO claimLastName = new UserIdentityClaimDTO();
    claimLastName.setClaimUri("http://wso2.org/claims/givenname");
    claimLastName.setClaimValue("user11");
    claims[0] = claimEmail;
    claims[1] = claimLastName;
    VerificationBean bean = infoRecoveryClient.verifyAccount(claims, null, null);
    Assert.assertNotNull(bean, "Verifying user account has failed with null return");
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.stub.beans.VerificationBean) UserIdentityClaimDTO(org.wso2.carbon.identity.mgt.stub.dto.UserIdentityClaimDTO) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Aggregations

IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)9 Test (org.testng.annotations.Test)7 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)7 VerificationBean (org.wso2.carbon.identity.mgt.stub.beans.VerificationBean)7 UserIdentityClaimDTO (org.wso2.carbon.identity.mgt.stub.dto.UserIdentityClaimDTO)7 UserStoreException (org.wso2.carbon.user.api.UserStoreException)7 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)7 IdentityException (org.wso2.carbon.identity.base.IdentityException)6 UserIdentityClaimDTO (org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO)6 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)5 UserIdentityClaimsDO (org.wso2.carbon.identity.mgt.dto.UserIdentityClaimsDO)4 UserIdentityDataStore (org.wso2.carbon.identity.mgt.store.UserIdentityDataStore)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)2 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)2 NotificationDataDTO (org.wso2.carbon.identity.mgt.dto.NotificationDataDTO)2 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)2 UserRecoveryDTO (org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO)2 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1