use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementUtil method getUserList.
private static String[] getUserList(int tenantId, String claim, String value, String profileName) throws IdentityMgtServiceException {
org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
String[] userList = null;
RealmService realmService = IdentityMgtServiceComponent.getRealmService();
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 the tenant";
throw new IdentityMgtServiceException(msg, e);
}
try {
if (userStoreManager != null) {
userList = userStoreManager.getUserList(claim, value, profileName);
}
return userList;
} catch (Exception e) {
String msg = "Unable to retrieve the claim for the given tenant";
throw new IdentityMgtServiceException(msg, e);
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException 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.IdentityMgtServiceException 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.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserInformationRecoveryService method getUserChallengeQuestion.
/**
* To get the challenge question for the user.
*
* @param userName
* @param confirmation
* @param questionId - Question id returned from the getUserChanllegneQuestionIds
* method.
* @return Populated question bean with the question details and the key.
* @throws IdentityMgtServiceException
*/
public UserChallengesDTO getUserChallengeQuestion(String userName, String confirmation, String questionId) throws IdentityMgtServiceException {
UserDTO userDTO = null;
UserChallengesDTO userChallengesDTO = new UserChallengesDTO();
if (log.isDebugEnabled()) {
log.debug("User challenge question request received with username :" + userName);
}
try {
userDTO = Utils.processUserId(userName);
} catch (IdentityException e) {
return handleChallengesError(VerificationBean.ERROR_CODE_INVALID_USER + " Error validating user : " + userName, null);
}
try {
if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
carbonContext.setTenantId(userDTO.getTenantId());
carbonContext.setTenantDomain(userDTO.getTenantDomain());
}
RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
VerificationBean bean;
try {
bean = processor.verifyConfirmationCode(20, userDTO.getUserId(), confirmation);
if (bean.isVerified()) {
bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
} else if (processor.verifyConfirmationCode(30, userDTO.getUserId(), confirmation).isVerified()) {
bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
} else {
bean.setVerified(false);
}
} catch (IdentityException e) {
userChallengesDTO = UserIdentityManagementUtil.getCustomErrorMessagesForChallengQuestions(e, userName);
if (userChallengesDTO == null) {
userChallengesDTO = handleChallengesError(VerificationBean.ERROR_CODE_INVALID_CODE + " Invalid confirmation code for user : " + userName, e);
}
return userChallengesDTO;
}
if (bean.isVerified()) {
userChallengesDTO = processor.getQuestionProcessor().getUserChallengeQuestion(userDTO.getUserId(), userDTO.getTenantId(), questionId);
userChallengesDTO.setKey(bean.getKey());
userChallengesDTO.setVerfied(true);
if (log.isDebugEnabled()) {
log.debug("User challenge question retrieved successfully");
}
} else {
if (log.isDebugEnabled()) {
log.debug("Verification failed for user. Error : " + bean.getError());
}
userChallengesDTO.setError(VerificationBean.ERROR_CODE_INVALID_USER + " " + bean.getError());
}
} finally {
if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return userChallengesDTO;
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class AccountCredentialMgtConfigService method getEmailConfig.
/**
* This method is used to load the tenant specific Email template configurations.
*
* @return an array of templates.
* @throws IdentityMgtServiceException
*/
public EmailTemplateDTO[] getEmailConfig() throws IdentityMgtServiceException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Config emailConfig = null;
EmailTemplateDTO[] templates = null;
ConfigBuilder configBuilder = ConfigBuilder.getInstance();
try {
emailConfig = configBuilder.loadConfiguration(ConfigType.EMAIL, StorageType.REGISTRY, tenantId);
if (emailConfig != null) {
templates = EmailConfigTransformer.transform(emailConfig.getProperties());
}
} catch (Exception e) {
log.error("Error occurred while loading email configuration", e);
throw new IdentityMgtServiceException("Error occurred while loading email configuration");
}
return templates;
}
Aggregations