Package org.apache.commons.httpclient.auth

Examples of org.apache.commons.httpclient.auth.ClaimsAuthScheme


    private boolean processClaimsAuthChallenge(HttpMethod method)
            throws MalformedChallengeException, AuthenticationException, IOException
    {
        AuthState authstate = method.getHostAuthState();
        if (authstate.getAuthScheme() == null) {
            authstate.setAuthScheme(new ClaimsAuthScheme());
        }
        ClaimsAuthScheme claims = (ClaimsAuthScheme)authstate.getAuthScheme();

        AuthScope authscope = new AuthScope(
            method.getHostConfiguration().getHost(),
            method.getHostConfiguration().getPort(),
            claims.getRealm(),
            claims.getSchemeName());

        CredentialsProvider cp = (CredentialsProvider)method.getParams().getParameter(
             CredentialsProvider.PROVIDER);
        Credentials creds = (cp == null) ?
            state.getCredentials(AuthScope.ANY) :
            cp.getCredentials(claims, authscope.getHost(), authscope.getPort(), false);
           
        if (adfsLogin(method.getURI().getScheme()
            + "://" + method.getURI().getAuthority(), creds)) {
          claims.setComplete();
          return true;
        }

        this.state.setCredentials(authscope, creds);
        if (method.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
            claims.originalUri = method.getURI();
            method.setRequestHeader(new Header("User-Agent", "Mozilla/4.0"));
            Header xforms = method.getResponseHeader("X-Forms_Based_Auth_Required");
            if (xforms == null) {
                throw new MalformedChallengeException("Status 403 Forbidden received from" +
                    "server, but X-Forms_Based_Auth_Required header missing - not claims " +
                    "based authentication");
            }
            URI xform = new URI(xforms.getValue().split(", ")[0]);
            hostConfiguration.setHost(xform);
            method.setURI(xform);
        } else if (method.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
            Header cookie = method.getResponseHeader("Set-Cookie");
            if (cookie != null && cookie.getValue().startsWith("FedAuth")) {
                method.removeRequestHeader("Authorization");
                method.setURI(claims.originalUri);
                hostConfiguration.setHost(claims.originalUri);
                claims.setComplete();
                authstate.setAuthScheme(null);
            }
        }
        return true;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.auth.ClaimsAuthScheme

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.