// 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;
      throw new RuntimeException(e);
    }

    for (FlaggedName role : roles) {
      if (role.getItemName().equals(roleName)) {
        log.info("Role name " + roleName + " already exists");
        return true;
      }
    }
    return false;
  }

  /**
   * Change User isPassword
   *
   * @param userName    The User's username
   * @param newPassword The User's new isPassword
   * @throws ChangePasswordUserAdminExceptionException
   */
  public void changePassword(String userName, String newPassword) throws ChangePasswordUserAdminExceptionException {
    try {
      userAdmin.changePassword(userName, newPassword);
    } catch (Exception e) {
      if (e.getMessage().contains("401 Error: Unauthorized")) {
        log.warn("Unauthorized error in changePassword method while invoking admin service due to session timeout.", e);
        userAdmin._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING,
            authenticateWithWSO2Server(isURL, isUserName, isPassword));
        changePassword(userName, newPassword);
        return;
      }
// 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;

      throw new RuntimeException(e);
    }

    for (FlaggedName role : roles) {
      if (role.getItemName().equals(roleName)) {
        log.info("Role name " + roleName + " already exists");
        return true;
      }
    }
    return false;
  }

  /**
   * Change User isPassword
   *
   * @param userName    The User's username
   * @param newPassword The User's new isPassword
   * @throws ChangePasswordUserAdminExceptionException
   */
  public void changePassword(String userName, String newPassword) throws ChangePasswordUserAdminExceptionException {
    try {
      userAdmin.changePassword(userName, newPassword);
    } catch (Exception e) {
      if (e.getMessage().contains("401 Error: Unauthorized")) {
        log.warn("Unauthorized error in changePassword method while invoking admin service due to session timeout.", e);
        userAdmin._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING,
            authenticateWithWSO2Server(isURL, isUserName, isPassword));
        changePassword(userName, newPassword);
        return;
      }
      throw new ChangePasswordUserAdminExceptionException("Cannot change isPassword for userId: " + userName, e);