/**
   * Login to the API gateway as an admin
   *
   * @return A session cookie string
   * @throws AxisFault if an error occurs while logging in
   */
  private String login(Environment environment) throws AxisFault {
    String user = environment.getUserName();
    String password = environment.getPassword();
    String serverURL = environment.getServerURL();

    if (serverURL == null || user == null || password == null) {
      throw new AxisFault("Required API gateway admin configuration unspecified");
    }

    String host;
    try {
      host = new URL(serverURL).getHost();
    } catch (MalformedURLException e) {
      throw new AxisFault("API gateway URL is malformed", e);
    }

    AuthenticationAdminStub authAdminStub =
        new AuthenticationAdminStub(null, serverURL + "AuthenticationAdmin");
    ServiceClient client = authAdminStub._getServiceClient();
    Options options = client.getOptions();
    options.setManageSession(true);
    try {
      authAdminStub.login(user, password, host);
      ServiceContext serviceContext =
          authAdminStub._getServiceClient().getLastOperationContext().getServiceContext();
      return (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
    } catch (RemoteException e) {
      throw new AxisFault("Error while contacting the authentication admin services", e);
    } catch (LoginAuthenticationExceptionException e) {
      throw new AxisFault("Error while authenticating against the API gateway admin", e);
    }
  }
  public SubscriberKeyMgtClient(String backendServerURL, String username, String password)
      throws Exception {
    try {
      AuthenticationAdminStub authenticationAdminStub =
          new AuthenticationAdminStub(null, backendServerURL + "AuthenticationAdmin");
      ServiceClient authAdminServiceClient = authenticationAdminStub._getServiceClient();
      authAdminServiceClient.getOptions().setManageSession(true);
      authenticationAdminStub.login(username, password, new URL(backendServerURL).getHost());
      ServiceContext serviceContext =
          authenticationAdminStub._getServiceClient().getLastOperationContext().getServiceContext();
      String authenticatedCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);

      if (log.isDebugEnabled()) {
        log.debug(
            "Authentication Successful with AuthenticationAdmin. "
                + "Authenticated Cookie ID : "
                + authenticatedCookie);
      }

      subscriberServiceStub =
          new APIKeyMgtSubscriberServiceStub(null, backendServerURL + "APIKeyMgtSubscriberService");
      ServiceClient client = subscriberServiceStub._getServiceClient();
      Options options = client.getOptions();
      options.setManageSession(true);
      options.setProperty(
          org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, authenticatedCookie);
    } catch (Exception e) {
      String errorMsg = "Error when instantiating SubscriberKeyMgtClient.";
      log.error(errorMsg, e);
      throw e;
    }
  }
示例#3
0
 /**
  * Authenticate to carbon as admin user and obtain the authentication cookie
  *
  * @param username
  * @param password
  * @return
  * @throws Exception
  */
 public String login(String username, String password) throws Exception {
   // String cookie = null;
   boolean loggedIn = authstub.login(username, password, "localhost");
   if (loggedIn) {
     System.out.println("The user " + username + " logged in successfully.");
     System.out.println();
     authCookie =
         (String)
             authstub
                 ._getServiceClient()
                 .getServiceContext()
                 .getProperty(HTTPConstants.COOKIE_STRING);
   } else {
     System.out.println("Error logging in " + username);
   }
   return authCookie;
 }
  private String login()
      throws RemoteException, LoginAuthenticationExceptionException, MalformedURLException {
    authenticationAdminStub =
        new AuthenticationAdminStub(
            policyDeployerConfiguration.getServiceUrl() + "AuthenticationAdmin");
    String sessionCookie = null;

    if (authenticationAdminStub.login(
        policyDeployerConfiguration.getUsername(),
        policyDeployerConfiguration.getPassword(),
        new URL(policyDeployerConfiguration.getServiceUrl()).getHost())) {
      ServiceContext serviceContext =
          authenticationAdminStub._getServiceClient().getLastOperationContext().getServiceContext();
      sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
    }
    return sessionCookie;
  }
 public String login(String userName, String password, String host)
     throws LoginAuthenticationExceptionException, RemoteException {
   Boolean loginStatus;
   ServiceContext serviceContext;
   String sessionCookie;
   loginStatus = authenticationAdminStub.login(userName, password, host);
   if (!loginStatus) {
     throw new LoginAuthenticationExceptionException(
         "Login Unsuccessful. Return false as a login status by Server");
   }
   log.info("Login Successful");
   serviceContext =
       authenticationAdminStub._getServiceClient().getLastOperationContext().getServiceContext();
   sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
   if (log.isDebugEnabled()) {
     log.debug("SessionCookie :" + sessionCookie);
   }
   return sessionCookie;
 }
  private static String authenticate(String username, String password) throws Exception {
    AuthenticationAdminStub stub = null;
    try {
      stub =
          new AuthenticationAdminStub(getConfigurationContext(), serverUrl + "AuthenticationAdmin");
      if (!stub.login(username, password, null)) {
        return null;
      }
      return (String)
          stub._getServiceClient()
              .getLastOperationContext()
              .getServiceContext()
              .getProperty(HTTPConstants.COOKIE_STRING);
    } finally {
      if (stub != null) {
        try {
          stub.cleanup();
        } catch (Exception ignore) {

        }
      }
    }
  }
  /**
   * authenticates with WSO2 Identity Server using authentication admin service This must be done
   * for each request
   *
   * @return true/false
   * @throws Exception if any error
   */
  private boolean authenticate() throws Exception {

    String serviceURL = null;
    ServiceClient client = null;
    Options option = null;
    boolean isAuthenticated = false;
    AuthenticationAdminStub authStub = null;

    serviceURL = backEndServerURL + "AuthenticationAdmin";
    authStub = new AuthenticationAdminStub(configCtx, serviceURL);
    client = authStub._getServiceClient();
    option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, authCookie);
    isAuthenticated = authStub.login(userName, password, remoteIp);
    authCookie =
        (String)
            authStub
                ._getServiceClient()
                .getServiceContext()
                .getProperty(HTTPConstants.COOKIE_STRING);
    return isAuthenticated;
  }
 public Boolean unsuccessfulLogin(String userName, String password, String backEndURL)
     throws LoginAuthenticationExceptionException, RemoteException {
   return authenticationAdminStub.login(userName, password, backEndURL);
 }