container/src/main/java/com/streamsets/datacollector/cli/sch/SchAdmin.java
private static String retrieveUserToken(String url, String username, String password) {
    Response response = null;
    try {
      Map<String, String> loginJson = new HashMap<>();
      loginJson.put("userName", username);
      loginJson.put("password", password);
      response = ClientBuilder.newClient()
          .target(url + "/security/public-rest/v1/authentication/login")
          .register(new CsrfProtectionFilter("CSRF"))
          .request()
          .post(Entity.json(loginJson));
      if (response.getStatus() != Response.Status.OK.getStatusCode()) {
        throw new RuntimeException(Utils.format("DPM Login failed, status code '{}': {}",
            response.getStatus(),
            response.readEntity(String.class)
        ));
      }
    } finally {
      if (response != null) {
        response.close();
      }
    }

   return response.getHeaderString(SSOConstants.X_USER_AUTH_TOKEN);
  }
private static String retrieveUserToken(String url, String username, String password) {
    Response response = null;
    try {
      Map<String, String> loginJson = new HashMap<>();
      loginJson.put("userName", username);
      loginJson.put("password", password);
      response = ClientBuilder.newClient()
          .target(url + "/security/public-rest/v1/authentication/login")
          .register(new CsrfProtectionFilter("CSRF"))
          .request()
          .post(Entity.json(loginJson));
      if (response.getStatus() != Response.Status.OK.getStatusCode()) {
        throw new RuntimeException(Utils.format("DPM Login failed, status code '{}': {}",
            response.getStatus(),
            response.readEntity(String.class)
        ));
      }
    } finally {
      if (response != null) {
        response.close();
      }
    }

   return response.getHeaderString(SSOConstants.X_USER_AUTH_TOKEN);
  }
private static String retrieveUserToken ( String url , String username , String password ) { Response response = null ; try { Map < String , String > loginJson = new HashMap <> ( ) ; loginJson . put ( "userName" , username ) ; loginJson . put ( "password" , password ) ; response = ClientBuilder . newClient ( ) . target ( url + "/security/public-rest/v1/authentication/login" ) . register ( new CsrfProtectionFilter ( "CSRF" ) ) . request ( ) . post ( Entity . json ( loginJson ) ) ; if ( response . getStatus ( ) != Response . Status . OK . getStatusCode ( ) ) { throw new RuntimeException ( Utils . format ( "DPM Login failed, status code '{}': {}" , response . getStatus ( ) , response . readEntity ( String . class ) ) ) ; } } finally { if ( response != null ) { response . close ( ) ; } } return response . getHeaderString ( SSOConstants . X_USER_AUTH_TOKEN ) ; }
Login user and retrieve authentication token.
Login user and retrieve authentication token .