mobile/android/thirdparty/ch/boye/httpclientandroidlib/auth/AuthState.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/auth/AuthState.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,145 @@
     1.4 +/*
     1.5 + * ====================================================================
     1.6 + *
     1.7 + *  Licensed to the Apache Software Foundation (ASF) under one or more
     1.8 + *  contributor license agreements.  See the NOTICE file distributed with
     1.9 + *  this work for additional information regarding copyright ownership.
    1.10 + *  The ASF licenses this file to You under the Apache License, Version 2.0
    1.11 + *  (the "License"); you may not use this file except in compliance with
    1.12 + *  the License.  You may obtain a copy of the License at
    1.13 + *
    1.14 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + *  Unless required by applicable law or agreed to in writing, software
    1.17 + *  distributed under the License is distributed on an "AS IS" BASIS,
    1.18 + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.19 + *  See the License for the specific language governing permissions and
    1.20 + *  limitations under the License.
    1.21 + * ====================================================================
    1.22 + *
    1.23 + * This software consists of voluntary contributions made by many
    1.24 + * individuals on behalf of the Apache Software Foundation.  For more
    1.25 + * information on the Apache Software Foundation, please see
    1.26 + * <http://www.apache.org/>.
    1.27 + *
    1.28 + */
    1.29 +
    1.30 +package ch.boye.httpclientandroidlib.auth;
    1.31 +
    1.32 +import ch.boye.httpclientandroidlib.annotation.NotThreadSafe;
    1.33 +
    1.34 +
    1.35 +/**
    1.36 + * This class provides detailed information about the state of the
    1.37 + * authentication process.
    1.38 + *
    1.39 + *
    1.40 + * @since 4.0
    1.41 + */
    1.42 +@NotThreadSafe
    1.43 +public class AuthState {
    1.44 +
    1.45 +    /** Actual authentication scheme */
    1.46 +    private AuthScheme authScheme;
    1.47 +
    1.48 +    /** Actual authentication scope */
    1.49 +    private AuthScope authScope;
    1.50 +
    1.51 +    /** Credentials selected for authentication */
    1.52 +    private Credentials credentials;
    1.53 +
    1.54 +    /**
    1.55 +     * Default constructor.
    1.56 +     *
    1.57 +     */
    1.58 +    public AuthState() {
    1.59 +        super();
    1.60 +    }
    1.61 +
    1.62 +    /**
    1.63 +     * Invalidates the authentication state by resetting its parameters.
    1.64 +     */
    1.65 +    public void invalidate() {
    1.66 +        this.authScheme = null;
    1.67 +        this.authScope = null;
    1.68 +        this.credentials = null;
    1.69 +    }
    1.70 +
    1.71 +    public boolean isValid() {
    1.72 +        return this.authScheme != null;
    1.73 +    }
    1.74 +
    1.75 +    /**
    1.76 +     * Assigns the given {@link AuthScheme authentication scheme}.
    1.77 +     *
    1.78 +     * @param authScheme the {@link AuthScheme authentication scheme}
    1.79 +     */
    1.80 +    public void setAuthScheme(final AuthScheme authScheme) {
    1.81 +        if (authScheme == null) {
    1.82 +            invalidate();
    1.83 +            return;
    1.84 +        }
    1.85 +        this.authScheme = authScheme;
    1.86 +    }
    1.87 +
    1.88 +    /**
    1.89 +     * Returns the {@link AuthScheme authentication scheme}.
    1.90 +     *
    1.91 +     * @return {@link AuthScheme authentication scheme}
    1.92 +     */
    1.93 +    public AuthScheme getAuthScheme() {
    1.94 +        return this.authScheme;
    1.95 +    }
    1.96 +
    1.97 +
    1.98 +    /**
    1.99 +     * Returns user {@link Credentials} selected for authentication if available
   1.100 +     *
   1.101 +     * @return user credentials if available, <code>null</code otherwise
   1.102 +     */
   1.103 +    public Credentials getCredentials() {
   1.104 +        return this.credentials;
   1.105 +    }
   1.106 +
   1.107 +
   1.108 +    /**
   1.109 +     * Sets user {@link Credentials} to be used for authentication
   1.110 +     *
   1.111 +     * @param credentials User credentials
   1.112 +     */
   1.113 +    public void setCredentials(final Credentials credentials) {
   1.114 +        this.credentials = credentials;
   1.115 +    }
   1.116 +
   1.117 +
   1.118 +    /**
   1.119 +     * Returns actual {@link AuthScope} if available
   1.120 +     *
   1.121 +     * @return actual authentication scope if available, <code>null</code otherwise
   1.122 +     */
   1.123 +     public AuthScope getAuthScope() {
   1.124 +        return this.authScope;
   1.125 +     }
   1.126 +
   1.127 +     /**
   1.128 +      * Sets actual {@link AuthScope}.
   1.129 +      *
   1.130 +      * @param authScope Authentication scope
   1.131 +      */
   1.132 +     public void setAuthScope(final AuthScope authScope) {
   1.133 +        this.authScope = authScope;
   1.134 +     }
   1.135 +
   1.136 +
   1.137 +    @Override
   1.138 +    public String toString() {
   1.139 +        StringBuilder buffer = new StringBuilder();
   1.140 +        buffer.append("auth scope [");
   1.141 +        buffer.append(this.authScope);
   1.142 +        buffer.append("]; credentials set [");
   1.143 +        buffer.append(this.credentials != null ? "true" : "false");
   1.144 +        buffer.append("]");
   1.145 +        return buffer.toString();
   1.146 +    }
   1.147 +
   1.148 +}

mercurial