public void addUser(UserDTO user) throws Exception {
    UserFieldDTO[] userFieldDTOs = null;
    Map<String, String> userClaims = null;

    userFieldDTOs = user.getUserFields();
    userClaims = new HashMap<String, String>();

    if (userFieldDTOs != null) {
      for (UserFieldDTO userFieldDTO : userFieldDTOs) {
        userClaims.put(userFieldDTO.getClaimUri(), userFieldDTO.getFieldValue());
      }
    }

    UserRealm realm = null;
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(user.getUserName());
    String tenantName = MultitenantUtils.getTenantDomain(user.getUserName());
    realm = IdentityTenantUtil.getRealm(tenantName, null);
    Registry registry = IdentityTenantUtil.getRegistry(null, null);
    addUser(tenantAwareUserName, user.getPassword(), userClaims, null, realm);
  }
  private UserFieldDTO getUserFieldDTO(
      String claimUri,
      String displayName,
      boolean isRequired,
      int displayOrder,
      String regex,
      boolean isSupportedByDefault) {

    UserFieldDTO fieldDTO = null;
    fieldDTO = new UserFieldDTO();
    fieldDTO.setClaimUri(claimUri);
    fieldDTO.setFieldName(displayName);
    fieldDTO.setRequired(isRequired);
    fieldDTO.setDisplayOrder(displayOrder);
    fieldDTO.setSupportedByDefault(isSupportedByDefault);
    fieldDTO.setRegEx(regex);
    return fieldDTO;
  }