List of usage examples for org.apache.commons.httpclient.auth BasicScheme authenticate
public String authenticate(Credentials paramCredentials, HttpMethod paramHttpMethod) throws AuthenticationException
From source file:com.twinsoft.convertigo.engine.ProxyManager.java
public void setCredentials() { //Setting credentials for XUL if (this.promptUser == null) { this.promptUser = this.proxyUser; }/*from ww w. j a v a 2s. c o m*/ if (this.promptPassword == null) { this.promptPassword = this.proxyPassword; } if (this.promptUser != null && this.promptPassword.length() > 0 && proxyMethod.equals(ProxyMethod.basic.name())) { this.basicValue = BasicScheme .authenticate(new UsernamePasswordCredentials(this.promptUser, this.promptPassword), "UTF-8"); } else { this.basicValue = null; } }
From source file:org.jetbrains.tfsIntegration.webservice.WebServiceHelper.java
public static void setupStub(final @NotNull Stub stub, final @NotNull Credentials credentials, final @NotNull URI serverUri) { Options options = stub._getServiceClient().getOptions(); // http params options.setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE); options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE); options.setProperty(HTTPConstants.SO_TIMEOUT, SOCKET_TIMEOUT); if (Registry.is("tfs.set.connection.timeout", false)) { options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, SOCKET_TIMEOUT); }/*from w w w .j av a 2 s . c om*/ // credentials if (credentials.getType() == Credentials.Type.Alternate) { String basicAuth = BasicScheme.authenticate( new UsernamePasswordCredentials(credentials.getUserName(), credentials.getPassword()), "UTF-8"); Map<String, String> headers = new HashMap<String, String>(); headers.put(HTTPConstants.HEADER_AUTHORIZATION, basicAuth); options.setProperty(HTTPConstants.HTTP_HEADERS, headers); } else { HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); auth.setUsername(credentials.getUserName()); auth.setPassword(credentials.getPassword() != null ? credentials.getPassword() : ""); auth.setDomain(credentials.getDomain()); auth.setHost(serverUri.getHost()); options.setProperty(HTTPConstants.AUTHENTICATE, auth); HttpMethodParams params = new HttpMethodParams(); params.setBooleanParameter(USE_NATIVE_CREDENTIALS, credentials.getType() == Credentials.Type.NtlmNative); options.setProperty(HTTPConstants.HTTP_METHOD_PARAMS, params); } // proxy final HttpTransportProperties.ProxyProperties proxyProperties; final HTTPProxyInfo proxy = HTTPProxyInfo.getCurrent(); if (proxy.host != null) { proxyProperties = new HttpTransportProperties.ProxyProperties(); Pair<String, String> domainAndUser = getDomainAndUser(proxy.user); proxyProperties.setProxyName(proxy.host); proxyProperties.setProxyPort(proxy.port); proxyProperties.setDomain(domainAndUser.first); proxyProperties.setUserName(domainAndUser.second); proxyProperties.setPassWord(proxy.password); } else { proxyProperties = null; } options.setProperty(HTTPConstants.PROXY, proxyProperties); }
From source file:org.jetbrains.tfsIntegration.webservice.WebServiceHelper.java
private static void setCredentials(final @NotNull HttpClient httpClient, final @NotNull Credentials credentials, final @NotNull URI serverUri) { if (credentials.getType() == Credentials.Type.Alternate) { HostParams parameters = httpClient.getHostConfiguration().getParams(); Collection<Header> headers = (Collection<Header>) parameters.getParameter(HostParams.DEFAULT_HEADERS); if (headers == null) { headers = new ArrayList<Header>(); parameters.setParameter(HostParams.DEFAULT_HEADERS, headers); }// w w w .j a v a2s. c o m Header authHeader = ContainerUtil.find(headers, new Condition<Header>() { @Override public boolean value(Header header) { return header.getName().equals(HTTPConstants.HEADER_AUTHORIZATION); } }); if (authHeader == null) { authHeader = new Header(HTTPConstants.HEADER_AUTHORIZATION, ""); headers.add(authHeader); } authHeader.setValue(BasicScheme.authenticate( new UsernamePasswordCredentials(credentials.getUserName(), credentials.getPassword()), "UTF-8")); } else { final NTCredentials ntCreds = new NTCredentials(credentials.getUserName(), credentials.getPassword(), serverUri.getHost(), credentials.getDomain()); httpClient.getState().setCredentials(AuthScope.ANY, ntCreds); httpClient.getParams().setBooleanParameter(USE_NATIVE_CREDENTIALS, credentials.getType() == Credentials.Type.NtlmNative); } }