log.error("The username is null");
throw new Exception("The username is null");
}
RealmService realmService = IdentityRPServiceComponent.getRealmService();
UserRealm userRealm = null;
Registry registry = null;
int tenantId = realmService.getTenantManager().getTenantId(domainName);
if (tenantId == -1) {
tenantId = this.createTenant(domainName, email, username, firstName, lastName);
}
userRealm = IdentityTenantUtil.getRealm(domainName, null);
if (!userRealm.getUserStoreManager().isExistingUser(username)) {
if (! GOOGLE_APPS_IDP_NAME.equals(userRealm.getRealmConfiguration().
getUserStoreProperties().
get(UserCoreConstants.RealmConfig.PROPERTY_EXTERNAL_IDP))) {
throw new Exception(
"The domain you are trying to login already exist. If you can prove your rights to this domain please contact administrator.");
}
String password = UUIDGenerator.getUUID();
UserStoreManager userStore = userRealm.getUserStoreManager();
if (!userStore.isExistingRole(IdentityConstants.IDENTITY_DEFAULT_ROLE)) {
Permission permission =
new Permission("/permission/admin/login",
UserMgtConstants.EXECUTE_ACTION);
userStore.addRole(IdentityConstants.IDENTITY_DEFAULT_ROLE, null,