List of usage examples for org.apache.commons.httpclient.auth AuthScheme getSchemeName
public abstract String getSchemeName();
From source file:net.adamcin.httpsig.http.apache3.SignerCredentialsProvider.java
public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (Constants.SCHEME.equals(scheme.getSchemeName())) { if (signer == null) { throw new CredentialsNotAvailableException("SSHKey Signer not available"); } else {//from w w w . j a v a 2 s . c o m return new SignerCredentials(signer); } } else { if (this.delegatee != null) { return this.delegatee.getCredentials(scheme, host, port, proxy); } } return null; }
From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProvider.java
/** * Builds a key with the specified data. * @param scheme the scheme/*from w ww . j a v a 2 s. c o m*/ * @param host the server name * @param port the server port * @param proxy is proxy * @return the new key */ protected Object buildKey(final AuthScheme scheme, final String host, final int port, final boolean proxy) { return scheme.getSchemeName() + " " + scheme.getRealm() + " " + host + ":" + port + " " + proxy; }
From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProvider.java
/** * @param scheme the request scheme for which Credentials are asked * @param scope the configured authorization scope * @return <code>true</code> if the scope's scheme matches the provided one *//*from ww w .java 2s .c om*/ protected boolean matchScheme(final AuthScope scope, final AuthScheme scheme) { return scope.getScheme() == AuthScope.ANY_SCHEME || scope.getScheme().equals(scheme.getSchemeName()); }
From source file:br.org.acessobrasil.silvinha.vista.panels.PainelSenha.java
public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (authscheme == null) { return null; }/* www.jav a 2 s . c o m*/ try { if (authscheme instanceof NTLMScheme) { this.getPassword(); if (cancelAuth) { return null; } return new NTCredentials(this.user, this.password, host, host); } else if (authscheme instanceof RFC2617Scheme) { this.getPassword(); if (cancelAuth) { return null; } return new UsernamePasswordCredentials(user, password); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + authscheme.getSchemeName()); } } catch (IOException e) { log.error(e.getMessage(), e); throw new CredentialsNotAvailableException(e.getMessage(), e); } }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.WsdlRequestCredentialsProvider.java
public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (checkedCredentials) throw new CredentialsNotAvailableException("Missing valid credentials"); if (authscheme == null) { return null; }/*from w w w .ja v a 2 s.com*/ try { String password = wsdlRequest.getPassword(); if (password == null) password = ""; if (authscheme instanceof NTLMScheme) { logger.info(host + ":" + port + " requires Windows authentication"); return new NTCredentials(wsdlRequest.getUsername(), password, host, wsdlRequest.getDomain()); } else if (authscheme instanceof RFC2617Scheme) { logger.info(host + ":" + port + " requires authentication with the realm '" + authscheme.getRealm() + "'"); return new UsernamePasswordCredentials(wsdlRequest.getUsername(), password); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + authscheme.getSchemeName()); } } catch (IOException e) { throw new CredentialsNotAvailableException(e.getMessage(), e); } finally { checkedCredentials = true; } }
From source file:com.globalsight.everest.webapp.applet.util.AuthenticationPrompter.java
/** * Returns the appropriate credentials for authentication. This method * may be called many times, but the username,password entered the first * time is re-used so the user is not prompted multiple times if the connection * isn't kept alive.//from w w w. ja va 2 s . c o m * * @param authscheme * @param host * @param port * @param proxy * @return Credentials * @exception CredentialsNotAvailableException */ public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (authscheme == null) { System.out.println("----No Proxy Authentication Required."); return null; } try { if (authscheme instanceof NTLMScheme) { System.out.println("----" + host + ":" + port + " requires Windows authentication"); if (m_askForAuth) askForAuthentication(); return new NTCredentials(m_username, m_password, host, m_domain); } else if (authscheme instanceof RFC2617Scheme) { System.out.println("----" + host + ":" + port + " requires authentication with the realm '" + authscheme.getRealm() + "'"); if (m_askForAuth) askForAuthentication(); return new UsernamePasswordCredentials(m_username, m_password); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + authscheme.getSchemeName()); } } catch (Exception e) { throw new CredentialsNotAvailableException(e.getMessage(), e); } }
From source file:com.esri.gpt.framework.http.HttpClientRequest.java
/** * Executes the HTTP request.// w ww . j av a 2s. com * @throws IOException if an Exception occurs */ public void execute() throws IOException { // initialize this.executionLog.setLength(0); StringBuffer log = this.executionLog; ResponseInfo respInfo = this.getResponseInfo(); respInfo.reset(); InputStream responseStream = null; HttpMethodBase method = null; try { log.append("HTTP Client Request\n").append(this.getUrl()); // make the Apache HTTPClient HttpClient client = this.batchHttpClient; if (client == null) { client = new HttpClient(); boolean alwaysClose = Val.chkBool(Val.chkStr(ApplicationContext.getInstance().getConfiguration() .getCatalogConfiguration().getParameters().getValue("httpClient.alwaysClose")), false); if (alwaysClose) { client.setHttpConnectionManager(new SimpleHttpConnectionManager(true)); } } // setting timeout info client.getHttpConnectionManager().getParams().setConnectionTimeout(getConnectionTimeOutMs()); client.getHttpConnectionManager().getParams().setSoTimeout(getResponseTimeOutMs()); // setting retries int retries = this.getRetries(); // create the client and method, apply authentication and proxy settings method = this.createMethod(); //method.setFollowRedirects(true); if (retries > -1) { // TODO: not taking effect yet? DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(retries, true); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); } this.applyAuthAndProxySettings(client, this.getUrl()); // execute the method, determine basic information about the response respInfo.setResponseCode(client.executeMethod(method)); this.determineResponseInfo(method); // collect logging info if (LOGGER.isLoggable(Level.FINER)) { log.append("\n>>").append(method.getStatusLine()); log.append("\n--Request Header"); for (Header hdr : method.getRequestHeaders()) { log.append("\n ").append(hdr.getName() + ": " + hdr.getValue()); } log.append("\n--Response Header"); for (Header hdr : method.getResponseHeaders()) { log.append("\n ").append(hdr.getName() + ": " + hdr.getValue()); } //log.append(" responseCode=").append(this.getResponseInfo().getResponseCode()); //log.append(" responseContentType=").append(this.getResponseInfo().getContentType()); //log.append(" responseContentEncoding=").append(this.getResponseInfo().getContentEncoding()); //log.append(" responseContentLength=").append(this.getResponseInfo().getContentLength()); if (this.getContentProvider() != null) { String loggable = this.getContentProvider().getLoggableContent(); if (loggable != null) { log.append("\n--Request Content------------------------------------\n").append(loggable); } } } // throw an exception if an error is encountered if ((respInfo.getResponseCode() < 200) || (respInfo.getResponseCode() >= 300)) { String msg = "HTTP Request failed: " + method.getStatusLine(); if (respInfo.getResponseCode() == HttpStatus.SC_UNAUTHORIZED) { AuthState authState = method.getHostAuthState(); AuthScheme authScheme = authState.getAuthScheme(); HttpClient401Exception authException = new HttpClient401Exception(msg); authException.setUrl(this.getUrl()); authException.setRealm(authState.getRealm()); authException.setScheme(authScheme.getSchemeName()); if ((authException.getRealm() == null) || (authException.getRealm().length() == 0)) { authException.setRealm(authException.generateHostBasedRealm()); } throw authException; } else { throw new HttpClientException(respInfo.getResponseCode(), msg); } } // handle the response if (this.getContentHandler() != null) { if (getContentHandler().onBeforeReadResponse(this)) { responseStream = getResponseStream(method); if (responseStream != null) { this.getContentHandler().readResponse(this, responseStream); } } // log thre response content String loggable = this.getContentHandler().getLoggableContent(); long nBytesRead = this.getResponseInfo().getBytesRead(); long nCharsRead = this.getResponseInfo().getCharactersRead(); if ((nBytesRead >= 0) || (nCharsRead >= 0) || (loggable != null)) { log.append("\n--Response Content------------------------------------"); if (nBytesRead >= 0) log.append("\n(").append(nBytesRead).append(" bytes read)"); if (nCharsRead >= 0) log.append("\n(").append(nCharsRead).append(" characters read)"); if (loggable != null) log.append("\n").append(loggable); } } } finally { // cleanup try { if (responseStream != null) responseStream.close(); } catch (Throwable t) { LOGGER.log(Level.SEVERE, "Unable to close HTTP response stream.", t); } try { if (method != null) method.releaseConnection(); } catch (Throwable t) { LOGGER.log(Level.SEVERE, "Unable to release HttpMethod", t); } // log the request/response if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer(this.getExecutionLog().toString()); } } }
From source file:com.sun.jersey.client.apache.config.DefaultCredentialsProvider.java
public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (scheme == null) { return null; }/* ww w . ja v a 2s . com*/ try { JTextField userField = new JTextField(); JPasswordField passwordField = new JPasswordField(); int response; if (scheme instanceof NTLMScheme) { JTextField domainField = new JTextField(); Object[] msg = { host + ":" + port + " requires Windows authentication", "Domain", domainField, "User Name", userField, "Password", passwordField }; response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION); if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) { throw new CredentialsNotAvailableException("User cancled windows authentication."); } return new NTCredentials(userField.getText(), new String(passwordField.getPassword()), host, domainField.getText()); } else if (scheme instanceof RFC2617Scheme) { Object[] msg = { host + ":" + port + " requires authentication with the realm '" + scheme.getRealm() + "'", "User Name", userField, "Password", passwordField }; response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION); if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) { throw new CredentialsNotAvailableException("User cancled windows authentication."); } return new UsernamePasswordCredentials(userField.getText(), new String(passwordField.getPassword())); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + scheme.getSchemeName()); } } catch (IOException ioe) { throw new CredentialsNotAvailableException(ioe.getMessage(), ioe); } }
From source file:org.eclipse.ecf.internal.provider.filetransfer.httpclient.HttpClientProxyCredentialProvider.java
/** * @throws CredentialsNotAvailableException *//*from ww w . ja va 2 s . c o m*/ public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean isProxyAuthenticating) throws CredentialsNotAvailableException { if (!isProxyAuthenticating) { return null; } Proxy proxy = getECFProxy(); if (proxy == null) { return null; } Object provideKey = makeProvidedKey(scheme, host, port, isProxyAuthenticating); if (provided.contains(provideKey)) { // HttpClient asks about credentials only once. // If already provided don't use them again. return null; } provided.add(provideKey); if ("ntlm".equalsIgnoreCase(scheme.getSchemeName())) { //$NON-NLS-1$ return getNTLMCredentials(proxy); } else if ("basic".equalsIgnoreCase(scheme.getSchemeName()) || //$NON-NLS-1$ "digest".equalsIgnoreCase(scheme.getSchemeName())) { //$NON-NLS-1$ final String proxyUsername = proxy.getUsername(); final String proxyPassword = proxy.getPassword(); if (proxyUsername != null) { Credentials credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword); return credentials; } } return null; }
From source file:org.eclipse.ecf.provider.filetransfer.httpclient.NTLMProxyDetector.java
public static boolean detectNTLMProxy(HttpMethodBase method) { if (method == null) return false; AuthState authState = method.getProxyAuthState(); if (authState == null) return false; AuthScheme authScheme = authState.getAuthScheme(); if (authScheme == null) return false; String schemeName = authScheme.getSchemeName(); if (schemeName == null) return false; return schemeName.equalsIgnoreCase(PROXY_NTLM_VALUE); }