String profileName) throws UserAdminException {
try {
RealmConfiguration realmConfig = realm.getRealmConfiguration();
if (realmConfig.
getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_EXTERNAL_IDP) != null) {
throw new UserAdminException(
"Please contact your extenernal Identity Provider to add users");
}
if (roles != null) {
boolean isContained = false;
String[] temp = new String[roles.length + 1];
for (int i = 0; i < roles.length; i++) {
temp[i] = roles[i];
if (roles[i].equals(realmConfig.getEveryOneRoleName())) {
isContained = true;
break;
}
}
if (!isContained) {
temp[roles.length] = realmConfig.getEveryOneRoleName();
roles = temp;
}
}
UserStoreManager admin = realm.getUserStoreManager();
Map<String, String> claimMap = new HashMap<String, String>();
if (claims != null) {
for (ClaimValue claimValue : claims) {
claimMap.put(claimValue.getClaimURI(), claimValue.getValue());
}
}
admin.addUser(userName, password, roles, claimMap, profileName, false);
} catch (UserStoreException e) {
// previously logged so logging not needed
throw new UserAdminException(e.getMessage(), e);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new UserAdminException(e.getMessage(), e);
}
}