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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /*
     2  * ====================================================================
     3  *
     4  *  Licensed to the Apache Software Foundation (ASF) under one or more
     5  *  contributor license agreements.  See the NOTICE file distributed with
     6  *  this work for additional information regarding copyright ownership.
     7  *  The ASF licenses this file to You under the Apache License, Version 2.0
     8  *  (the "License"); you may not use this file except in compliance with
     9  *  the License.  You may obtain a copy of the License at
    10  *
    11  *      http://www.apache.org/licenses/LICENSE-2.0
    12  *
    13  *  Unless required by applicable law or agreed to in writing, software
    14  *  distributed under the License is distributed on an "AS IS" BASIS,
    15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  *  See the License for the specific language governing permissions and
    17  *  limitations under the License.
    18  * ====================================================================
    19  *
    20  * This software consists of voluntary contributions made by many
    21  * individuals on behalf of the Apache Software Foundation.  For more
    22  * information on the Apache Software Foundation, please see
    23  * <http://www.apache.org/>.
    24  *
    25  */
    27 package ch.boye.httpclientandroidlib.auth;
    29 import ch.boye.httpclientandroidlib.annotation.NotThreadSafe;
    32 /**
    33  * This class provides detailed information about the state of the
    34  * authentication process.
    35  *
    36  *
    37  * @since 4.0
    38  */
    39 @NotThreadSafe
    40 public class AuthState {
    42     /** Actual authentication scheme */
    43     private AuthScheme authScheme;
    45     /** Actual authentication scope */
    46     private AuthScope authScope;
    48     /** Credentials selected for authentication */
    49     private Credentials credentials;
    51     /**
    52      * Default constructor.
    53      *
    54      */
    55     public AuthState() {
    56         super();
    57     }
    59     /**
    60      * Invalidates the authentication state by resetting its parameters.
    61      */
    62     public void invalidate() {
    63         this.authScheme = null;
    64         this.authScope = null;
    65         this.credentials = null;
    66     }
    68     public boolean isValid() {
    69         return this.authScheme != null;
    70     }
    72     /**
    73      * Assigns the given {@link AuthScheme authentication scheme}.
    74      *
    75      * @param authScheme the {@link AuthScheme authentication scheme}
    76      */
    77     public void setAuthScheme(final AuthScheme authScheme) {
    78         if (authScheme == null) {
    79             invalidate();
    80             return;
    81         }
    82         this.authScheme = authScheme;
    83     }
    85     /**
    86      * Returns the {@link AuthScheme authentication scheme}.
    87      *
    88      * @return {@link AuthScheme authentication scheme}
    89      */
    90     public AuthScheme getAuthScheme() {
    91         return this.authScheme;
    92     }
    95     /**
    96      * Returns user {@link Credentials} selected for authentication if available
    97      *
    98      * @return user credentials if available, <code>null</code otherwise
    99      */
   100     public Credentials getCredentials() {
   101         return this.credentials;
   102     }
   105     /**
   106      * Sets user {@link Credentials} to be used for authentication
   107      *
   108      * @param credentials User credentials
   109      */
   110     public void setCredentials(final Credentials credentials) {
   111         this.credentials = credentials;
   112     }
   115     /**
   116      * Returns actual {@link AuthScope} if available
   117      *
   118      * @return actual authentication scope if available, <code>null</code otherwise
   119      */
   120      public AuthScope getAuthScope() {
   121         return this.authScope;
   122      }
   124      /**
   125       * Sets actual {@link AuthScope}.
   126       *
   127       * @param authScope Authentication scope
   128       */
   129      public void setAuthScope(final AuthScope authScope) {
   130         this.authScope = authScope;
   131      }
   134     @Override
   135     public String toString() {
   136         StringBuilder buffer = new StringBuilder();
   137         buffer.append("auth scope [");
   138         buffer.append(this.authScope);
   139         buffer.append("]; credentials set [");
   140         buffer.append(this.credentials != null ? "true" : "false");
   141         buffer.append("]");
   142         return buffer.toString();
   143     }
   145 }

mercurial