use of org.wso2.carbon.identity.mgt.stub.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);
}
}
use of org.wso2.carbon.identity.mgt.stub.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);
}
}
use of org.wso2.carbon.identity.mgt.stub.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;
}
use of org.wso2.carbon.identity.mgt.stub.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");
}
use of org.wso2.carbon.identity.mgt.stub.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");
}
Aggregations