List of usage examples for org.apache.commons.httpclient.methods HeadMethod getHostAuthState
@Override
public AuthState getHostAuthState()
From source file:org.eclipse.mylyn.internal.phabricator.core.client.TracXmlRpcClient.java
private void probeAuthenticationScheme(IProgressMonitor monitor) throws PhabricatorException { AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY); if (!credentialsValid(credentials)) { return;/*from w w w .j av a2s .com*/ } if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Probing authentication"); //$NON-NLS-1$ } HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor); HeadMethod method = new HeadMethod(getXmlRpcUrl(credentials).toString()); try { // execute without any credentials set int result = WebUtil.execute(httpClient, hostConfiguration, method, new HttpState(), monitor); if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received authentication response (" + result + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } if (result == HttpStatus.SC_UNAUTHORIZED || result == HttpStatus.SC_FORBIDDEN) { AuthScheme authScheme = method.getHostAuthState().getAuthScheme(); if (authScheme instanceof DigestScheme) { this.digestScheme = (DigestScheme) authScheme; if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received digest scheme"); //$NON-NLS-1$ } } else if (authScheme instanceof BasicScheme) { httpClient.getParams().setAuthenticationPreemptive(true); if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received basic scheme"); //$NON-NLS-1$ } } else if (authScheme != null) { if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received scheme (" + authScheme.getClass() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": No authentication scheme received"); //$NON-NLS-1$ } } Header header = method.getResponseHeader("Server"); //$NON-NLS-1$ isTracd = (header != null && header.getValue().startsWith("tracd")); //$NON-NLS-1$ if (DEBUG_AUTH && isTracd) { System.err.println(location.getUrl() + ": Tracd detected"); //$NON-NLS-1$ } // Header header = method.getResponseHeader("WWW-Authenticate"); // if (header != null) { // if (header.getValue().startsWith("Basic")) { // httpClient.getParams().setAuthenticationPreemptive(true); // } else if (header.getValue().startsWith("Digest")) { // DigestScheme scheme = new DigestScheme(); // try { // scheme.processChallenge(header.getValue()); // this.digestScheme = scheme; // } catch (MalformedChallengeException e) { // // ignore // } // } // } } } catch (IOException e) { // ignore } finally { WebUtil.releaseConnection(method, monitor); } }
From source file:org.eclipse.mylyn.internal.trac.core.client.TracXmlRpcClient.java
private void probeAuthenticationScheme(IProgressMonitor monitor) throws TracException { AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY); if (!credentialsValid(credentials)) { return;//from w w w .j av a 2 s. com } if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Probing authentication"); //$NON-NLS-1$ } HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor); HeadMethod method = new HeadMethod(getXmlRpcUrl(credentials).toString()); try { // execute without any credentials set int result = WebUtil.execute(httpClient, hostConfiguration, method, new HttpState(), monitor); if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received authentication response (" + result + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } if (result == HttpStatus.SC_UNAUTHORIZED || result == HttpStatus.SC_FORBIDDEN) { AuthScheme authScheme = method.getHostAuthState().getAuthScheme(); if (authScheme instanceof DigestScheme) { this.digestScheme = (DigestScheme) authScheme; if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received digest scheme"); //$NON-NLS-1$ } } else if (authScheme instanceof BasicScheme) { httpClient.getParams().setAuthenticationPreemptive(true); if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received basic scheme"); //$NON-NLS-1$ } } else if (authScheme != null) { if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": Received scheme (" + authScheme.getClass() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { if (DEBUG_AUTH) { System.err.println(location.getUrl() + ": No authentication scheme received"); //$NON-NLS-1$ } } Header header = method.getResponseHeader("Server"); //$NON-NLS-1$ isTracd = (header != null && header.getValue().startsWith("tracd")); //$NON-NLS-1$ if (DEBUG_AUTH && isTracd) { System.err.println(location.getUrl() + ": Tracd detected"); //$NON-NLS-1$ } // Header header = method.getResponseHeader("WWW-Authenticate"); // if (header != null) { // if (header.getValue().startsWith("Basic")) { // httpClient.getParams().setAuthenticationPreemptive(true); // } else if (header.getValue().startsWith("Digest")) { // DigestScheme scheme = new DigestScheme(); // try { // scheme.processChallenge(header.getValue()); // this.digestScheme = scheme; // } catch (MalformedChallengeException e) { // // ignore // } // } // } } } catch (IOException e) { // ignore } finally { WebUtil.releaseConnection(method, monitor); } }