// Path: app/edu/indiana/d2i/htrc/portal/exception/ChangePasswordUserAdminExceptionException.java
// public class ChangePasswordUserAdminExceptionException extends Exception {
//     public ChangePasswordUserAdminExceptionException() {
//         super();
//     }
// 
//     public ChangePasswordUserAdminExceptionException(String message) {
//         super(message);
//     }
// 
//     public ChangePasswordUserAdminExceptionException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ChangePasswordUserAdminExceptionException(Throwable cause) {
//         super(cause);
//     }
// 
//     protected ChangePasswordUserAdminExceptionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: app/edu/indiana/d2i/htrc/portal/exception/EmailAlreadyExistsException.java
// public class EmailAlreadyExistsException extends Exception {
//     public EmailAlreadyExistsException(String message) {
//       super(message);
//     }
// 
//     public EmailAlreadyExistsException(String message, Throwable cause) {
//       super(message, cause);
//     }
// 
//     public EmailAlreadyExistsException(Throwable cause) {
//       super(cause);
//     }
// }
// 
// Path: app/edu/indiana/d2i/htrc/portal/exception/RoleNameAlreadyExistsException.java
// public class RoleNameAlreadyExistsException extends Exception {
//     public RoleNameAlreadyExistsException(String message) {
//         super(message);
//     }
// 
//     public RoleNameAlreadyExistsException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public RoleNameAlreadyExistsException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: app/edu/indiana/d2i/htrc/portal/exception/UserAlreadyExistsException.java
// public class UserAlreadyExistsException extends Exception {
//     public UserAlreadyExistsException(String message) {
//         super(message);
//     }
// 
//     public UserAlreadyExistsException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public UserAlreadyExistsException(Throwable cause) {
//         super(cause);
//     }
// }


import edu.indiana.d2i.htrc.portal.exception.ChangePasswordUserAdminExceptionException;
import edu.indiana.d2i.htrc.portal.exception.EmailAlreadyExistsException;
import edu.indiana.d2i.htrc.portal.exception.RoleNameAlreadyExistsException;
import edu.indiana.d2i.htrc.portal.exception.UserAlreadyExistsException;
import edu.indiana.d2i.htrc.wso2is.extensions.stub.types.UserInfoRequest;
import edu.indiana.d2i.htrc.wso2is.extensions.stub.types.UserInfoResponse;
import org.apache.axis2.client.Options;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
import org.wso2.carbon.registry.core.Collection;
import org.wso2.carbon.registry.extensions.stub.ResourceAdminServiceStub;
import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;
import org.wso2.carbon.user.mgt.common.UserAdminException;
import org.wso2.carbon.user.mgt.stub.UserAdminStub;
import edu.indiana.d2i.htrc.wso2is.extensions.stub.ExtendedUserAdminStub;
import org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue;
import org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName;
import org.wso2.carbon.user.mgt.stub.types.carbon.UserRealmInfo;
import org.wso2.carbon.utils.NetworkUtils;
import play.Logger;
import java.rmi.RemoteException;
import java.util.*;
import java.util.regex.Pattern;
   * @throws UserAlreadyExistsException Thrown if an error occurred
   * @see #getRequiredUserClaims()
   * @see #getAvailablePermissions()
   */
  public void createUser(String userName, String password, String email, List<Map.Entry<String, String>> claims) throws Exception { // TODO: Review this
    if (userName == null) {
      throw new NullPointerException("User name null.");
    }

    if (password == null) {
      throw new NullPointerException("Password null.");
    }

    if (isUserExists(userName)) {
      String message = "User with name " + userName + " already exists.";
      log.warn(message);
      throw new UserAlreadyExistsException(message);
    }

    if (roleNameExists(userName)) {
      String message = userName + " is a already exist role name.";
      log.warn(message);
      throw new RoleNameAlreadyExistsException(message);
    }

    List<String> usersWithEmail = getUserIdsFromEmail(email);

    if (usersWithEmail != null && usersWithEmail.size() > 0) {
      String message = email + " is already used for user accounts: " + usersWithEmail;
      log.warn(message);
// Path: app/edu/indiana/d2i/htrc/portal/exception/ChangePasswordUserAdminExceptionException.java
// public class ChangePasswordUserAdminExceptionException extends Exception {
//     public ChangePasswordUserAdminExceptionException() {
//         super();
//     }
// 
//     public ChangePasswordUserAdminExceptionException(String message) {
//         super(message);
//     }
// 
//     public ChangePasswordUserAdminExceptionException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ChangePasswordUserAdminExceptionException(Throwable cause) {
//         super(cause);
//     }
// 
//     protected ChangePasswordUserAdminExceptionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: app/edu/indiana/d2i/htrc/portal/exception/EmailAlreadyExistsException.java
// public class EmailAlreadyExistsException extends Exception {
//     public EmailAlreadyExistsException(String message) {
//       super(message);
//     }
// 
//     public EmailAlreadyExistsException(String message, Throwable cause) {
//       super(message, cause);
//     }
// 
//     public EmailAlreadyExistsException(Throwable cause) {
//       super(cause);
//     }
// }
// 
// Path: app/edu/indiana/d2i/htrc/portal/exception/RoleNameAlreadyExistsException.java
// public class RoleNameAlreadyExistsException extends Exception {
//     public RoleNameAlreadyExistsException(String message) {
//         super(message);
//     }
// 
//     public RoleNameAlreadyExistsException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public RoleNameAlreadyExistsException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: app/edu/indiana/d2i/htrc/portal/exception/UserAlreadyExistsException.java
// public class UserAlreadyExistsException extends Exception {
//     public UserAlreadyExistsException(String message) {
//         super(message);
//     }
// 
//     public UserAlreadyExistsException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public UserAlreadyExistsException(Throwable cause) {
//         super(cause);
//     }
// }


// Path: app/edu/indiana/d2i/htrc/portal/HTRCUserManagerUtility.java
import edu.indiana.d2i.htrc.portal.exception.ChangePasswordUserAdminExceptionException;
import edu.indiana.d2i.htrc.portal.exception.EmailAlreadyExistsException;
import edu.indiana.d2i.htrc.portal.exception.RoleNameAlreadyExistsException;
import edu.indiana.d2i.htrc.portal.exception.UserAlreadyExistsException;
import edu.indiana.d2i.htrc.wso2is.extensions.stub.types.UserInfoRequest;
import edu.indiana.d2i.htrc.wso2is.extensions.stub.types.UserInfoResponse;
import org.apache.axis2.client.Options;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
import org.wso2.carbon.registry.core.Collection;
import org.wso2.carbon.registry.extensions.stub.ResourceAdminServiceStub;
import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;
import org.wso2.carbon.user.mgt.common.UserAdminException;
import org.wso2.carbon.user.mgt.stub.UserAdminStub;
import edu.indiana.d2i.htrc.wso2is.extensions.stub.ExtendedUserAdminStub;
import org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue;
import org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName;
import org.wso2.carbon.user.mgt.stub.types.carbon.UserRealmInfo;
import org.wso2.carbon.utils.NetworkUtils;
import play.Logger;
import java.rmi.RemoteException;
import java.util.*;
import java.util.regex.Pattern;

   * @throws UserAlreadyExistsException Thrown if an error occurred
   * @see #getRequiredUserClaims()
   * @see #getAvailablePermissions()
   */
  public void createUser(String userName, String password, String email, List<Map.Entry<String, String>> claims) throws Exception { // TODO: Review this
    if (userName == null) {
      throw new NullPointerException("User name null.");
    }

    if (password == null) {
      throw new NullPointerException("Password null.");
    }

    if (isUserExists(userName)) {
      String message = "User with name " + userName + " already exists.";
      log.warn(message);
      throw new UserAlreadyExistsException(message);
    }

    if (roleNameExists(userName)) {
      String message = userName + " is a already exist role name.";
      log.warn(message);
      throw new RoleNameAlreadyExistsException(message);
    }

    List<String> usersWithEmail = getUserIdsFromEmail(email);

    if (usersWithEmail != null && usersWithEmail.size() > 0) {
      String message = email + " is already used for user accounts: " + usersWithEmail;
      log.warn(message);
      throw new EmailAlreadyExistsException(message);