* @param tenantInfoBean tenant information
* @throws Exception UserStoreException
*/
public void updateTenant(TenantInfoBean tenantInfoBean) throws Exception {
TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
UserStoreManager userStoreManager;
// filling the non-set admin and admin password first
UserRegistry configSystemRegistry = TenantMgtServiceComponent.getConfigSystemRegistry(
tenantInfoBean.getTenantId());
String tenantDomain = tenantInfoBean.getTenantDomain();
int tenantId;
try {
tenantId = tenantManager.getTenantId(tenantDomain);
} catch (UserStoreException e) {
String msg = "Error in retrieving the tenant id for the tenant domain: " + tenantDomain
+ ".";
log.error(msg, e);
throw new Exception(msg, e);
}
boolean updatePassword = false;
boolean isPasswordChanged = false;
if (tenantInfoBean.getAdminPassword() != null
&& !tenantInfoBean.getAdminPassword().equals("")) {
updatePassword = true;
}
Tenant tenant;
try {
tenant = (Tenant) tenantManager.getTenant(tenantId);
} catch (UserStoreException e) {
String msg = "Error in retrieving the tenant id for the tenant domain: " +
tenantDomain + ".";
log.error(msg, e);
throw new Exception(msg, e);
}
// filling the first and last name values
if (tenantInfoBean.getFirstname() != null &&
!tenantInfoBean.getFirstname().trim().equals("")) {
try {
CommonUtil.validateName(tenantInfoBean.getFirstname(), "First Name");
} catch (Exception e) {
String msg = "Invalid first name is provided.";
log.error(msg, e);
throw new Exception(msg, e);
}
}
if (tenantInfoBean.getLastname() != null &&
!tenantInfoBean.getLastname().trim().equals("")) {
try {
CommonUtil.validateName(tenantInfoBean.getLastname(), "Last Name");
} catch (Exception e) {
String msg = "Invalid last name is provided.";
log.error(msg, e);
throw new Exception(msg, e);
}
}
Map<String, String> claimsMap = new HashMap<String, String>(); // map of claims
claimsMap.put(UserCoreConstants.ClaimTypeURIs.GIVEN_NAME, tenantInfoBean.getFirstname());
claimsMap.put(UserCoreConstants.ClaimTypeURIs.SURNAME, tenantInfoBean.getLastname());
userStoreManager = TenantMgtUtil.getUserStoreManager(tenant, tenant.getId());
userStoreManager.setUserClaimValues(tenantInfoBean.getAdmin(), claimsMap,
UserCoreConstants.DEFAULT_PROFILE);
// filling the email value
if (tenantInfoBean.getEmail() != null && !tenantInfoBean.getEmail().equals("")) {
// validate the email
try {
CommonUtil.validateEmail(tenantInfoBean.getEmail());
} catch (Exception e) {
String msg = "Invalid email is provided.";
log.error(msg, e);
throw new Exception(msg, e);
}
tenant.setEmail(tenantInfoBean.getEmail());
}
UserRealm userRealm = configSystemRegistry.getUserRealm();
try {
userStoreManager = userRealm.getUserStoreManager();
} catch (UserStoreException e) {
String msg = "Error in getting the user store manager for tenant, tenant domain: " +
tenantDomain + ".";
log.error(msg, e);
throw new Exception(msg, e);
}
if (!userStoreManager.isReadOnly() && updatePassword) {
// now we will update the tenant admin with the admin given
// password.
try {
userStoreManager.updateCredentialByAdmin(tenantInfoBean.getAdmin(),
tenantInfoBean.getAdminPassword());
isPasswordChanged = true;
} catch (UserStoreException e) {
String msg = "Error in changing the tenant admin password, tenant domain: " +
tenantInfoBean.getTenantDomain() + ". " + e.getMessage() + " for: " +