AdministratorProperty adminUserProperty = ADSContext
.getAdminUserPropFromName(propertyName);
if (adminUserProperty == null)
{
Message message = ERR_CLI_ERROR_PROPERTY_UNRECOGNIZED.get(propertyName);
throw new ArgumentException(message);
}
// Check that propName is not hidden.
if (userAdminProperties.get(adminUserProperty).isHidden())
{
Message message = ERR_CLI_ERROR_PROPERTY_UNRECOGNIZED.get(propertyName);
throw new ArgumentException(message);
}
// Check the property Syntax.
MessageBuilder invalidReason = new MessageBuilder();
Argument arg = userAdminProperties.get(adminUserProperty) ;
if ( ! arg.valueIsAcceptable(value, invalidReason))
{
Message message =
ERR_CLI_ERROR_INVALID_PROPERTY_VALUE.get(propertyName, value);
throw new ArgumentException(message);
}
if (adminUserProperty.equals(AdministratorProperty.PRIVILEGE))
{
// Check if 'root' privilege is requested, or
// if it's a valid privilege
if (value.equals(arg.getDefaultValue()))
{
rootPrivileges = true ;
}
else
{
String valueToCheck = value ;
if (value.startsWith("-"))
{
valueToCheck = value.substring(1);
}
if (Privilege.privilegeForName(valueToCheck) == null)
{
Message message = ERR_CLI_ERROR_INVALID_PROPERTY_VALUE.get(
AdministratorProperty.PRIVILEGE.getAttributeName(),
valueToCheck);
throw new ArgumentException(message);
}
}
}
// Add the value to the argument.
arg.addValue(value);
// add to the map.
if (arg.isMultiValued())
{
map.put(adminUserProperty, arg.getValues());
}
else
{
map.put(adminUserProperty, value);
}
}
// If we are not in the create admin user, just return the
// provided atributes.
if (! createCall)
{
return map ;
}
// Here, we are in the create case.
// If privileges was not provided by the user, set the default value
if (! map.containsKey(AdministratorProperty.PRIVILEGE))
{
rootPrivileges = true ;
}
// If we have root privilege, translate it to the corresponding
// list of privileges associated to 'root' user.
if (rootPrivileges)
{
LinkedList<String> privilegesList = new LinkedList<String>();
for (Privilege p : Privilege.getDefaultRootPrivileges())
{
privilegesList.add(p.getName());
}
map.put(AdministratorProperty.PRIVILEGE,privilegesList);
}
for (AdministratorProperty s : AdministratorProperty.values())
{
Argument arg = userAdminProperties.get(s);
if (arg.isHidden())
{
continue;
}
if (map.containsKey(s))
{
continue ;
}
if ( ! arg.isRequired())
{
continue ;
}
// If we are here, it means that the argument is required
// but not yet is the map. Check if we have a default value.
if (arg.getDefaultValue() == null)
{
Message message =
ERR_CLI_ERROR_MISSING_PROPERTY.get(s.getAttributeName());
throw new ArgumentException(message);
}
else
{
map.put(s, arg.getDefaultValue());
}