use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class AccountCredentialMgtConfigService method saveEmailConfig.
/**
* This method is used to save the Email template configurations which is specific to tenant.
*
* @param emailTemplates - Email templates to be saved.
* @throws IdentityMgtServiceException
*/
public void saveEmailConfig(EmailTemplateDTO[] emailTemplates) throws IdentityMgtServiceException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
EmailNotificationConfig emailConfig = new EmailNotificationConfig();
ConfigBuilder configBuilder = ConfigBuilder.getInstance();
try {
Properties props = EmailConfigTransformer.transform(emailTemplates);
emailConfig.setProperties(props);
configBuilder.saveConfiguration(StorageType.REGISTRY, tenantId, emailConfig);
} catch (Exception e) {
log.error("Error occurred while saving email configuration", e);
throw new IdentityMgtServiceException("Error occurred while saving email configuration");
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method unlockUserAccount.
/**
* Admin unlocks the user account.
*
* @param userName
* @throws IdentityMgtServiceException
*/
public void unlockUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
try {
UserStoreManager userStoreManager = getUserStore(userName);
String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
UserIdentityManagementUtil.unlockUserAccount(userNameWithoutDomain, userStoreManager);
int tenantID = userStoreManager.getTenantId();
String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
boolean isNotificationSending = IdentityMgtConfig.getInstance().isNotificationSending();
if (notificationType != null && isNotificationSending) {
UserRecoveryDTO dto;
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
dto = new UserRecoveryDTO(userName);
} else {
UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
userDTO.setTenantId(tenantID);
dto = new UserRecoveryDTO(userDTO);
}
dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_UNLOCK);
dto.setNotificationType(notificationType);
IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
}
log.info("Account unlocked for: " + userName);
} catch (UserStoreException | IdentityException e) {
String message = "Error occurred while unlocking account for: " + userName;
log.error(message, e);
throw new IdentityMgtServiceException(message, e);
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method changeUserPassword.
/**
* User change the password of the user.
*
* @param newPassword
* @throws IdentityMgtServiceException
*/
public void changeUserPassword(String newPassword, String oldPassword) throws IdentityMgtServiceException {
String userName = CarbonContext.getThreadLocalCarbonContext().getUsername();
try {
UserStoreManager userStoreManager = getUserStore(userName);
userName = UserCoreUtil.removeDomainFromName(userName);
userStoreManager.updateCredential(userName, newPassword, oldPassword);
log.info("Password changed for: " + userName);
} catch (UserStoreException e) {
String message = "Error while resetting the password for: " + userName;
log.error(message, e);
throw new IdentityMgtServiceException(message, e);
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method setChallengeQuestionsOfUser.
/**
* set challenges of user
*
* @param userName bean class that contains user and tenant Information
* @throws IdentityMgtServiceException if fails
*/
public void setChallengeQuestionsOfUser(String userName, UserChallengesDTO[] challengesDTOs) throws IdentityMgtServiceException {
if (challengesDTOs == null || challengesDTOs.length < 1) {
log.error("no challenges provided by user");
throw new IdentityMgtServiceException("no challenges provided by user");
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String loggedInName = CarbonContext.getThreadLocalCarbonContext().getUsername();
if (userName != null && !userName.equals(loggedInName)) {
AuthorizationManager authzManager = null;
try {
authzManager = IdentityMgtServiceComponent.getRealmService().getTenantUserRealm(tenantId).getAuthorizationManager();
} catch (UserStoreException e) {
throw new IdentityMgtServiceException("Error occurred while retrieving AuthorizationManager for tenant " + tenantDomain, e);
}
boolean isAuthorized = false;
try {
isAuthorized = authzManager.isUserAuthorized(loggedInName, "/permission/admin/manage/identity/identitymgt/update", CarbonConstants.UI_PERMISSION_ACTION);
} catch (UserStoreException e) {
throw new IdentityMgtServiceException("Error occurred while checking access level for " + "user " + userName + " in tenant " + tenantDomain, e);
}
if (!isAuthorized) {
throw new IdentityMgtServiceException("Unauthorized access!! Possible elevation of privilege attack. " + "User " + loggedInName + " trying to change challenge questions for user " + userName);
}
} else if (userName == null) {
userName = loggedInName;
}
validateSecurityQuestionDuplicate(challengesDTOs);
ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
try {
List<ChallengeQuestionDTO> challengeQuestionDTOs = processor.getAllChallengeQuestions();
for (UserChallengesDTO userChallengesDTO : challengesDTOs) {
boolean found = false;
for (ChallengeQuestionDTO challengeQuestionDTO : challengeQuestionDTOs) {
if (challengeQuestionDTO.getQuestion().equals(userChallengesDTO.getQuestion()) && challengeQuestionDTO.getQuestionSetId().equals(userChallengesDTO.getId())) {
found = true;
break;
}
}
if (!found) {
String errMsg = "Error while persisting user challenges for user : " + userName + ", because these user challengers are not registered with the tenant";
log.error(errMsg);
throw new IdentityMgtServiceException(errMsg);
}
}
processor.setChallengesOfUser(userName, tenantId, challengesDTOs);
} catch (IdentityException e) {
String errorMessage = "Error while persisting user challenges for user : " + userName;
log.error(errorMessage, e);
throw new IdentityMgtServiceException(errorMessage);
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method isReadOnlyUserStore.
/**
* This method is used to check the user's user store is read only.
*
* @param userName
* @param tenantDomain
* @return
* @throws IdentityMgtServiceException
*/
public boolean isReadOnlyUserStore(String userName, String tenantDomain) throws IdentityMgtServiceException {
boolean isReadOnly = false;
org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
if (StringUtils.isEmpty(tenantDomain)) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
RealmService realmService = IdentityMgtServiceComponent.getRealmService();
int tenantId;
try {
tenantId = Utils.getTenantId(tenantDomain);
if (realmService.getTenantUserRealm(tenantId) != null) {
userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) getUserStore(userName);
}
} catch (Exception e) {
String msg = "Error retrieving the user store manager for the tenant";
log.error(msg, e);
throw new IdentityMgtServiceException(msg);
}
try {
if (userStoreManager != null && userStoreManager.isReadOnly()) {
isReadOnly = true;
} else
isReadOnly = false;
} catch (org.wso2.carbon.user.core.UserStoreException e) {
String errorMessage = "Error while retrieving user store manager";
log.error(errorMessage, e);
throw new IdentityMgtServiceException(errorMessage);
}
return isReadOnly;
}
Aggregations