Java 类org.apache.http.client.params.AuthPolicy 实例源码

项目:ProBOT    文件:ClientAuthentication2.java   
public static void main(String... args) throws IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.NTLM);
    httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
    NTCredentials creds = new NTCredentials("abhisheks", "abhiProJul17", "", "");
    httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
    HttpHost target = new HttpHost("apps.prorigo.com", 80, "http");

    // Make sure the same context is used to execute logically related requests
    HttpContext localContext = new BasicHttpContext();
    // Execute a cheap method first. This will trigger NTLM authentication
    HttpGet httpget = new HttpGet("/conference/Booking");
    HttpResponse response = httpclient.execute(target, httpget, localContext);
    HttpEntity entity = response.getEntity();
    System.out.println(EntityUtils.toString(entity));
}
项目:ProBOT    文件:ClientAuthentication.java   
public static void main(String... args) throws IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.NTLM);
    httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
    NTCredentials creds = new NTCredentials("abhisheks", "abhiProJul17", "", "");
    httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
    HttpHost target = new HttpHost("apps.prorigo.com", 80, "http");

    // Make sure the same context is used to execute logically related requests
    HttpContext localContext = new BasicHttpContext();
    // Execute a cheap method first. This will trigger NTLM authentication
    HttpGet httpget = new HttpGet("/conference/Booking");
    HttpResponse response = httpclient.execute(target, httpget, localContext);
    HttpEntity entity = response.getEntity();
    System.out.println(EntityUtils.toString(entity));
}
项目:lams    文件:ProxyClient.java   
public ProxyClient(final HttpParams params) {
    super();
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            new RequestContent(),
            new RequestTargetHost(),
            new RequestClientConnControl(),
            new RequestUserAgent(),
            new RequestProxyAuthentication()
    } );
    this.requestExec = new HttpRequestExecutor();
    this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
    this.authenticator = new HttpAuthenticator();
    this.proxyAuthState = new AuthState();
    this.authSchemeRegistry = new AuthSchemeRegistry();
    this.authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
    this.reuseStrategy = new DefaultConnectionReuseStrategy();
    this.params = params;
}
项目:lams    文件:AbstractHttpClient.java   
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(
            AuthPolicy.BASIC,
            new BasicSchemeFactory());
    registry.register(
            AuthPolicy.DIGEST,
            new DigestSchemeFactory());
    registry.register(
            AuthPolicy.NTLM,
            new NTLMSchemeFactory());
    registry.register(
            AuthPolicy.SPNEGO,
            new SPNegoSchemeFactory());
    registry.register(
            AuthPolicy.KERBEROS,
            new KerberosSchemeFactory());
    return registry;
}
项目:hadoop    文件:AuthenticatorTestCase.java   
private SystemDefaultHttpClient getHttpClient() {
  final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
  httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
   Credentials use_jaas_creds = new Credentials() {
     public String getPassword() {
       return null;
     }

     public Principal getUserPrincipal() {
       return null;
     }
   };

   httpClient.getCredentialsProvider().setCredentials(
     AuthScope.ANY, use_jaas_creds);
   return httpClient;
}
项目:aliyun-oss-hadoop-fs    文件:AuthenticatorTestCase.java   
private SystemDefaultHttpClient getHttpClient() {
  final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
  httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
   Credentials use_jaas_creds = new Credentials() {
     public String getPassword() {
       return null;
     }

     public Principal getUserPrincipal() {
       return null;
     }
   };

   httpClient.getCredentialsProvider().setCredentials(
     AuthScope.ANY, use_jaas_creds);
   return httpClient;
}
项目:big-c    文件:AuthenticatorTestCase.java   
private SystemDefaultHttpClient getHttpClient() {
  final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
  httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
   Credentials use_jaas_creds = new Credentials() {
     public String getPassword() {
       return null;
     }

     public Principal getUserPrincipal() {
       return null;
     }
   };

   httpClient.getCredentialsProvider().setCredentials(
     AuthScope.ANY, use_jaas_creds);
   return httpClient;
}
项目:registry    文件:AuthenticatorTestCase.java   
private SystemDefaultHttpClient getHttpClient() {
    final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
    httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
    Credentials use_jaas_creds = new Credentials() {
        public String getPassword() {
            return null;
        }

        public Principal getUserPrincipal() {
            return null;
        }
    };

    httpClient.getCredentialsProvider().setCredentials(
            AuthScope.ANY, use_jaas_creds);
    return httpClient;
}
项目:purecloud-iot    文件:AbstractHttpClient.java   
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    final AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(
            AuthPolicy.BASIC,
            new BasicSchemeFactory());
    registry.register(
            AuthPolicy.DIGEST,
            new DigestSchemeFactory());
    registry.register(
            AuthPolicy.NTLM,
            new NTLMSchemeFactory());
    registry.register(
            AuthPolicy.SPNEGO,
            new SPNegoSchemeFactory());
    registry.register(
            AuthPolicy.KERBEROS,
            new KerberosSchemeFactory());
    return registry;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:AuthenticatorTestCase.java   
private SystemDefaultHttpClient getHttpClient() {
  final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
  httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
   Credentials use_jaas_creds = new Credentials() {
     public String getPassword() {
       return null;
     }

     public Principal getUserPrincipal() {
       return null;
     }
   };

   httpClient.getCredentialsProvider().setCredentials(
     AuthScope.ANY, use_jaas_creds);
   return httpClient;
}
项目:r01fb    文件:TwilioService.java   
@SuppressWarnings({ "resource"})
private TwilioRestClient _createTwilioRESTClient() {
       TwilioRestClient outClient = new TwilioRestClient(_apiData.getAccountSID().asString(),
                                                      _apiData.getAccountToken().asString());
    if (_proxySettings != null && _proxySettings.isEnabled()) {
        UrlComponents proxyUrlComps = _proxySettings.getProxyUrl().getComponents();
        log.info("Connecting to twilio through {}:{}",proxyUrlComps.getHost(), 
                                                      proxyUrlComps.getPort());
        // Get the twilio api underlying http client
        DefaultHttpClient httpClient = (DefaultHttpClient)outClient.getHttpClient();

        // Set proxy details
        HttpHost proxy = new HttpHost(proxyUrlComps.getHost().asString(),proxyUrlComps.getPort(),
                                      "http");
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
                                            proxy);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyUrlComps.getHost().asString(), 
                                                                         proxyUrlComps.getPort()),
                                                           new UsernamePasswordCredentials(_proxySettings.getUserCode().asString(),
                                                                                           _proxySettings.getPassword().asString()));
        httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF,
                                            Lists.newArrayList(AuthPolicy.BASIC));

    } 
    return outClient;
}
项目:hops    文件:AuthenticatorTestCase.java   
private SystemDefaultHttpClient getHttpClient() {
  final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
  httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
   Credentials use_jaas_creds = new Credentials() {
     public String getPassword() {
       return null;
     }

     public Principal getUserPrincipal() {
       return null;
     }
   };

   httpClient.getCredentialsProvider().setCredentials(
     AuthScope.ANY, use_jaas_creds);
   return httpClient;
}
项目:lams    文件:ResponseAuthCache.java   
private boolean isCachable(final AuthState authState) {
    AuthScheme authScheme = authState.getAuthScheme();
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }
    String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
            schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
项目:lams    文件:AuthenticationStrategyAdaptor.java   
private boolean isCachable(final AuthScheme authScheme) {
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }
    String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
            schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
项目:lams    文件:AuthenticationStrategyImpl.java   
protected boolean isCachable(final AuthScheme authScheme) {
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }
    String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
            schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
项目:purecloud-iot    文件:ResponseAuthCache.java   
private boolean isCachable(final AuthState authState) {
    final AuthScheme authScheme = authState.getAuthScheme();
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }
    final String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
            schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
项目:purecloud-iot    文件:AuthenticationStrategyAdaptor.java   
private boolean isCachable(final AuthScheme authScheme) {
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }
    final String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
            schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
项目:namie-crawler    文件:HttpClientForProxy.java   
/**
 * 認証プロキシを通過するためのHttpClient。
 */
public HttpClientForProxy() {
    super();
    String proxyUser = System.getProperty("http.proxyUser");
    if (proxyUser != null) {
        String proxyHost = System.getProperty("http.proxyHost");
        String proxyPortStr = System.getProperty("http.proxyPort");
        int proxyPort = 0;
        if (proxyPortStr != null) {
            proxyPort = Integer.parseInt(proxyPortStr);
        }
        String proxyPassword = System.getProperty("http.proxyPassword");
        List<String> authpref = new ArrayList<String>();
        authpref.add(AuthPolicy.BASIC);
        this.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
        CredentialsProvider credsProvider = this.getCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(
                        proxyUser, proxyPassword));
        this.setCredentialsProvider(credsProvider);
        String protocol = "";
        if (proxyHost.indexOf("https") != 0) {
            protocol = "http";
        } else {
            protocol = "https";
        }
        HttpHost proxy = new HttpHost(proxyHost, proxyPort, protocol);
        this.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
}
项目:Pushjet-Android    文件:HttpClientConfigurer.java   
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) {
    Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials);

    NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
    Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials);

    LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port});
}
项目:Pushjet-Android    文件:HttpClientConfigurer.java   
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) {
    Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials);

    NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
    Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials);

    LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port});
}
项目:namie-accountcreator    文件:HttpClientForProxy.java   
/**
 * 認証プロキシを通過するためのHttpClient。
 */
public HttpClientForProxy() {
    super();
    String proxyHost = System.getProperty("http.proxyHost");

    if (proxyHost != null) {
        String proxyPortStr = System.getProperty("http.proxyPort");
        int proxyPort = 0;
        if (proxyPortStr != null) {
            proxyPort = Integer.parseInt(proxyPortStr);
        }
        String proxyUser = System.getProperty("http.proxyUser");
        if (proxyUser != null) {
            String proxyPassword = System.getProperty("http.proxyPassword");
            List<String> authpref = new ArrayList<String>();
            authpref.add(AuthPolicy.BASIC);
            this.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
            CredentialsProvider credsProvider = this.getCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(
                            proxyUser, proxyPassword));
            this.setCredentialsProvider(credsProvider);
        }

        String protocol = "";
        if (proxyHost.indexOf("https") != 0) {
            protocol = "http";
        } else {
            protocol = "https";
        }
        HttpHost proxy = new HttpHost(proxyHost, proxyPort, protocol);
        this.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
}
项目:modules    文件:FormControllerIT.java   
@Before
public void setUp() throws IOException, InterruptedException {
    createAdminUser();

    getHttpClient().getCredentialsProvider().setCredentials(
            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthPolicy.BASIC),
            new UsernamePasswordCredentials("motech", "motech")
    );

    login();
}
项目:modules    文件:CommcareBundleIT.java   
@Before
public void setUp() throws IOException, InterruptedException {
    createAdminUser();

    getHttpClient().getCredentialsProvider().setCredentials(
            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthPolicy.BASIC),
            new UsernamePasswordCredentials("motech", "motech")
    );
}
项目:cJUnit-mc626    文件:DefaultHttpClient.java   
@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry(); 
    registry.register(
            AuthPolicy.BASIC, 
            new BasicSchemeFactory());
    registry.register(
            AuthPolicy.DIGEST, 
            new DigestSchemeFactory());
    return registry;
}
项目:fiware-cygnus    文件:HttpClientFactory.java   
/**
 * Gets a HTTP client.
 * @param ssl True if SSL connections are desired. False otherwise
 * @param krb5Auth.
 * @return A http client obtained from the (SSL) Connections Manager.
 */
public DefaultHttpClient getHttpClient(boolean ssl, boolean krb5Auth) {
    DefaultHttpClient httpClient;

    if (ssl) {
        httpClient = new DefaultHttpClient(sslConnectionsManager);
    } else {
        httpClient = new DefaultHttpClient(connectionsManager);
    } // if else

    if (krb5Auth) {
        // http://stackoverflow.com/questions/21629132/httpclient-set-credentials-for-kerberos-authentication

        System.setProperty("java.security.auth.login.config", loginConfFile);
        System.setProperty("java.security.krb5.conf", krb5ConfFile);
        System.setProperty("sun.security.krb5.debug", "false");
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
        Credentials jaasCredentials = new Credentials() {

            @Override
            public String getPassword() {
                return null;
            } // getPassword

            @Override
            public Principal getUserPrincipal() {
                return null;
            } // getUserPrincipal

        };

        // 'true' means the port is stripped from the principal names
        SPNegoSchemeFactory spnegoSchemeFactory = new SPNegoSchemeFactory(true);
        httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, spnegoSchemeFactory);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(null, -1, null), jaasCredentials);
    } // if

    return httpClient;
}
项目:apache-jmeter-2.10    文件:AuthManager.java   
/**
 * Configure credentials and auth scheme on client if an authorization is 
 * available for url
 * @param client {@link HttpClient}
 * @param url URL to test 
 * @param credentialsProvider {@link CredentialsProvider}
 * @param localHost host running JMeter
 */
public void setupCredentials(HttpClient client, URL url,
        CredentialsProvider credentialsProvider, String localHost) {
    Authorization auth = getAuthForURL(url);
    if (auth != null) {
        String username = auth.getUser();
        String realm = auth.getRealm();
        String domain = auth.getDomain();
        if (log.isDebugEnabled()){
            log.debug(username + " > D="+domain+" R="+realm + " M="+auth.getMechanism());
        }
        if (Mechanism.KERBEROS.equals(auth.getMechanism())) {
            ((AbstractHttpClient) client).getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
            credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
        } else {
            credentialsProvider.setCredentials(
                    new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
                    new NTCredentials(username, auth.getPass(), localHost, domain));
        }
    }
}
项目:Gw2InfoViewer    文件:ClientKerberosAuthentication.java   
public static void main(String[] args) throws Exception {

        System.setProperty("java.security.auth.login.config", "login.conf");
        System.setProperty("java.security.krb5.conf", "krb5.conf");
        System.setProperty("sun.security.krb5.debug", "true");
        System.setProperty("javax.security.auth.useSubjectCredsOnly","false");

        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());

            Credentials use_jaas_creds = new Credentials() {

                public String getPassword() {
                    return null;
                }

                public Principal getUserPrincipal() {
                    return null;
                }

            };

            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope(null, -1, null),
                    use_jaas_creds);

            HttpUriRequest request = new HttpGet("http://kerberoshost/");
            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            System.out.println("----------------------------------------");
            if (entity != null) {
                System.out.println(EntityUtils.toString(entity));
            }
            System.out.println("----------------------------------------");

            // This ensures the connection gets released back to the manager
            EntityUtils.consume(entity);

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }
项目:project-bianca    文件:PickToLight.java   
public String getServerTime() {
    String soapAction = "http://tempuri.org/SoapService/GetServerTime";
    String soapEnv = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">   <soapenv:Header/>   <soapenv:Body>      <tem:GetServerTime/>   </soapenv:Body></soapenv:Envelope>";
    log.info(String.format("sendSoap - action %s [%s]", soapAction, soapEnv));
    String mesEndpoint = properties.getProperty("mes.endpoint");
    String mesUser = properties.getProperty("mes.user");
    String mesDomain = properties.getProperty("mes.domain");
    String mesPassword = properties.getProperty("mes.password");

    log.info(String.format("mesEndpoint %s", mesEndpoint));
    log.info(String.format("mesUser %s", mesUser));
    log.info(String.format("mesDomain %s", mesDomain));
    log.info(String.format("mesPassword %s", mesPassword));

    String ret = "";

    try {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        List<String> authpref = new ArrayList<String>();
        authpref.add(AuthPolicy.NTLM);
        httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
        NTCredentials creds = new NTCredentials(mesUser, mesPassword, "", mesDomain);
        httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);

        HttpContext localContext = new BasicHttpContext();
        HttpPost post = new HttpPost(mesEndpoint);

        // ,"utf-8"
        StringEntity stringentity = new StringEntity(soapEnv);
        stringentity.setChunked(true);
        post.setEntity(stringentity);
        post.addHeader("Accept", "text/xml");
        post.addHeader("SOAPAction", soapAction);
        post.addHeader("Content-Type", "text/xml; charset=utf-8");

        HttpResponse response = httpclient.execute(post, localContext);
        HttpEntity entity = response.getEntity();
        ret = EntityUtils.toString(entity);

        // parse the response - check
    } catch (Exception e) {
        error("endpoint %s user %s domain %s password %s", mesEndpoint, mesUser, mesDomain, mesPassword);
        Logging.logError(e);
        ret = e.getMessage();
    }

    log.info(String.format("soap response [%s]", ret));
    return ret;

}
项目:project-bianca    文件:PickToLight.java   
public String sendSoap(String soapAction, String soapEnv) {
    log.info(String.format("sendSoap - action %s [%s]", soapAction, soapEnv));
    String mesEndpoint = properties.getProperty("mes.endpoint");
    String mesUser = properties.getProperty("mes.user");
    String mesDomain = properties.getProperty("mes.domain");
    String mesPassword = properties.getProperty("mes.password");

    log.info(String.format("mesEndpoint %s", mesEndpoint));
    log.info(String.format("mesUser %s", mesUser));
    log.info(String.format("mesDomain %s", mesDomain));
    log.info(String.format("mesPassword %s", mesPassword));

    String ret = "";

    try {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        List<String> authpref = new ArrayList<String>();
        authpref.add(AuthPolicy.NTLM);
        httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
        NTCredentials creds = new NTCredentials(mesUser, mesPassword, "", mesDomain);
        httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);

        HttpContext localContext = new BasicHttpContext();
        HttpPost post = new HttpPost(mesEndpoint);

        // ,"utf-8"
        StringEntity stringentity = new StringEntity(soapEnv);
        stringentity.setChunked(true);
        post.setEntity(stringentity);
        post.addHeader("Accept", "text/xml");
        post.addHeader("SOAPAction", soapAction);
        post.addHeader("Content-Type", "text/xml; charset=utf-8");

        HttpResponse response = httpclient.execute(post, localContext);
        HttpEntity entity = response.getEntity();
        ret = EntityUtils.toString(entity);

        // parse the response - check
    } catch (Exception e) {
        error("endpoint %s user %s domain %s password %s", mesEndpoint, mesUser, mesDomain, mesPassword);
        Logging.logError(e);
        ret = e.getMessage();
    }

    log.info(String.format("soap response [%s]", ret));
    return ret;

}
项目:myrobotlab    文件:PickToLight.java   
public String sendSoap(String soapAction, String soapEnv) {
  log.info(String.format("sendSoap - action %s [%s]", soapAction, soapEnv));
  String mesEndpoint = properties.getProperty("mes.endpoint");
  String mesUser = properties.getProperty("mes.user");
  String mesDomain = properties.getProperty("mes.domain");
  String mesPassword = properties.getProperty("mes.password");

  log.info(String.format("mesEndpoint %s", mesEndpoint));
  log.info(String.format("mesUser %s", mesUser));
  log.info(String.format("mesDomain %s", mesDomain));
  log.info(String.format("mesPassword %s", mesPassword));

  String ret = "";

  try {
    DefaultHttpClient client = new DefaultHttpClient();
    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.NTLM);
    client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
    NTCredentials creds = new NTCredentials(mesUser, mesPassword, "", mesDomain);
    client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);

    HttpContext localContext = new BasicHttpContext();
    HttpPost post = new HttpPost(mesEndpoint);

    // ,"utf-8"
    StringEntity stringentity = new StringEntity(soapEnv);
    stringentity.setChunked(true);
    post.setEntity(stringentity);
    post.addHeader("Accept", "text/xml");
    post.addHeader("SOAPAction", soapAction);
    post.addHeader("Content-Type", "text/xml; charset=utf-8");

    HttpResponse response = client.execute(post, localContext);
    HttpEntity entity = response.getEntity();
    ret = EntityUtils.toString(entity);

    // parse the response - check
  } catch (Exception e) {
    error("endpoint %s user %s domain %s password %s", mesEndpoint, mesUser, mesDomain, mesPassword);
    Logging.logError(e);
    ret = e.getMessage();
  }

  log.info(String.format("soap response [%s]", ret));
  return ret;

}
项目:AnalyzerBeans    文件:SimpleMainAppForManualTesting.java   
public static void main(String[] args) throws Throwable {

        // create a HTTP BASIC enabled HTTP client
        final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
        final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider();
        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
        final List<String> authpref = new ArrayList<String>();
        authpref.add(AuthPolicy.BASIC);
        authpref.add(AuthPolicy.DIGEST);
        httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
        credentialsProvider.setCredentials(new AuthScope("localhost", 8080), credentials);
        credentialsProvider.setCredentials(new AuthScope("localhost", 9090), credentials);

        // register endpoints
        final List<String> slaveEndpoints = new ArrayList<String>();
        slaveEndpoints.add("http://localhost:8080/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");
        slaveEndpoints.add("http://localhost:9090/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");

        final HttpClusterManager clusterManager = new HttpClusterManager(httpClient, slaveEndpoints);

        final AnalyzerBeansConfiguration configuration = ClusterTestHelper.createConfiguration("manual_test", false);

        // build a job that concats names and inserts the concatenated names
        // into a file
        final AnalysisJobBuilder jobBuilder = new AnalysisJobBuilder(configuration);
        jobBuilder.setDatastore("orderdb");
        jobBuilder.addSourceColumns("CUSTOMERS.CUSTOMERNUMBER", "CUSTOMERS.CUSTOMERNAME", "CUSTOMERS.CONTACTFIRSTNAME",
                "CUSTOMERS.CONTACTLASTNAME");

        AnalyzerJobBuilder<CompletenessAnalyzer> completeness = jobBuilder.addAnalyzer(CompletenessAnalyzer.class);
        completeness.addInputColumns(jobBuilder.getSourceColumns());
        completeness.setConfiguredProperty("Conditions", new CompletenessAnalyzer.Condition[] {
                CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL, CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL, CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL });

        AnalysisJob job = jobBuilder.toAnalysisJob();
        jobBuilder.close();

        AnalysisResultFuture result = new DistributedAnalysisRunner(configuration, clusterManager).run(job);

        if (result.isErrornous()) {
            throw result.getErrors().get(0);
        }

        final List<AnalyzerResult> results = result.getResults();
        for (AnalyzerResult analyzerResult : results) {
            System.out.println("result:" + analyzerResult);
            if (analyzerResult instanceof CompletenessAnalyzerResult) {
                int invalidRowCount = ((CompletenessAnalyzerResult) analyzerResult).getInvalidRowCount();
                System.out.println("invalid records found: " + invalidRowCount);
            } else {
                System.out.println("class: " + analyzerResult.getClass().getName());
            }
        }
    }
项目:fiware-cosmos-ambari    文件:AppCookieManager.java   
/**
 * Returns hadoop.auth cookie, doing needed SPNego authentication
 * 
 * @param endpoint
 *          the URL of the Hadoop service
 * @param refresh
 *          flag indicating wehther to refresh the cookie, if
 *          <code>true</code>, we do a new SPNego authentication and refresh
 *          the cookie even if the cookie already exists in local cache
 * @return hadoop.auth cookie value
 * @throws IOException
 *           in case of problem getting hadoop.auth cookie
 */
public String getAppCookie(String endpoint, boolean refresh)
    throws IOException {

  HttpUriRequest outboundRequest = new HttpGet(endpoint);
  URI uri = outboundRequest.getURI();
  String scheme = uri.getScheme();
  String host = uri.getHost();
  int port = uri.getPort();
  String path = uri.getPath();
  if (!refresh) {
    String appCookie = endpointCookieMap.get(endpoint);
    if (appCookie != null) {
      return appCookie;
    }
  }

  clearAppCookie(endpoint);

  DefaultHttpClient client = new DefaultHttpClient();
  SPNegoSchemeFactory spNegoSF = new SPNegoSchemeFactory(/* stripPort */true);
  // spNegoSF.setSpengoGenerator(new BouncySpnegoTokenGenerator());
  client.getAuthSchemes().register(AuthPolicy.SPNEGO, spNegoSF);
  client.getCredentialsProvider().setCredentials(
      new AuthScope(/* host */null, /* port */-1, /* realm */null),
      EMPTY_JAAS_CREDENTIALS);

  String hadoopAuthCookie = null;
  HttpResponse httpResponse = null;
  try {
    HttpHost httpHost = new HttpHost(host, port, scheme);
    HttpRequest httpRequest = new HttpOptions(path);
    httpResponse = client.execute(httpHost, httpRequest);
    Header[] headers = httpResponse.getHeaders(SET_COOKIE);
    hadoopAuthCookie = getHadoopAuthCookieValue(headers);
    if (hadoopAuthCookie == null) {
      LOG.error("SPNego authentication failed, can not get hadoop.auth cookie for URL: " + endpoint);
      throw new IOException(
          "SPNego authentication failed, can not get hadoop.auth cookie");
    }
  } finally {
    if (httpResponse != null) {
      HttpEntity entity = httpResponse.getEntity();
      if (entity != null) {
        entity.getContent().close();
      }
    }

  }

  hadoopAuthCookie = HADOOP_AUTH_EQ + quote(hadoopAuthCookie);
  setAppCookie(endpoint, hadoopAuthCookie);
  if (LOG.isInfoEnabled()) {
    LOG.info("Successful SPNego authentication to URL:" + uri.toString());
  }
  return hadoopAuthCookie;
}
项目:LibraryH3lp-Transfer-Bot    文件:ClientKerberosAuthentication.java   
public static void main(String[] args) throws Exception {

        System.setProperty("java.security.auth.login.config", "login.conf");
        System.setProperty("java.security.krb5.conf", "krb5.conf");
        System.setProperty("sun.security.krb5.debug", "true");
        System.setProperty("javax.security.auth.useSubjectCredsOnly","false");

        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());

            Credentials use_jaas_creds = new Credentials() {

                public String getPassword() {
                    return null;
                }

                public Principal getUserPrincipal() {
                    return null;
                }

            };

            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope(null, -1, null),
                    use_jaas_creds);

            HttpUriRequest request = new HttpGet("http://kerberoshost/");
            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            System.out.println("----------------------------------------");
            if (entity != null) {
                System.out.println(EntityUtils.toString(entity));
            }
            System.out.println("----------------------------------------");

            // This ensures the connection gets released back to the manager
            EntityUtils.consume(entity);

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }