Home | History | Annotate | Download | only in auth
      1 /*
      2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthState.java $
      3  * $Revision: 659971 $
      4  * $Date: 2008-05-25 05:01:22 -0700 (Sun, 25 May 2008) $
      5  *
      6  * ====================================================================
      7  *
      8  *  Licensed to the Apache Software Foundation (ASF) under one or more
      9  *  contributor license agreements.  See the NOTICE file distributed with
     10  *  this work for additional information regarding copyright ownership.
     11  *  The ASF licenses this file to You under the Apache License, Version 2.0
     12  *  (the "License"); you may not use this file except in compliance with
     13  *  the License.  You may obtain a copy of the License at
     14  *
     15  *      http://www.apache.org/licenses/LICENSE-2.0
     16  *
     17  *  Unless required by applicable law or agreed to in writing, software
     18  *  distributed under the License is distributed on an "AS IS" BASIS,
     19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20  *  See the License for the specific language governing permissions and
     21  *  limitations under the License.
     22  * ====================================================================
     23  *
     24  * This software consists of voluntary contributions made by many
     25  * individuals on behalf of the Apache Software Foundation.  For more
     26  * information on the Apache Software Foundation, please see
     27  * <http://www.apache.org/>.
     28  *
     29  */
     30 
     31 package org.apache.http.auth;
     32 
     33 
     34 /**
     35  * This class provides detailed information about the state of the
     36  * authentication process.
     37  *
     38  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
     39  *
     40  * @since 4.0
     41  *
     42  * @deprecated Please use {@link java.net.URL#openConnection} instead.
     43  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
     44  *     for further details.
     45  */
     46 @Deprecated
     47 public class AuthState {
     48 
     49     /** Actual authentication scheme */
     50     private AuthScheme authScheme;
     51 
     52     /** Actual authentication scope */
     53     private AuthScope authScope;
     54 
     55     /** Credentials selected for authentication */
     56     private Credentials credentials;
     57 
     58     /**
     59      * Default constructor.
     60      *
     61      */
     62     public AuthState() {
     63         super();
     64     }
     65 
     66     /**
     67      * Invalidates the authentication state by resetting its parameters.
     68      */
     69     public void invalidate() {
     70         this.authScheme = null;
     71         this.authScope = null;
     72         this.credentials = null;
     73     }
     74 
     75     public boolean isValid() {
     76         return this.authScheme != null;
     77     }
     78 
     79     /**
     80      * Assigns the given {@link AuthScheme authentication scheme}.
     81      *
     82      * @param authScheme the {@link AuthScheme authentication scheme}
     83      */
     84     public void setAuthScheme(final AuthScheme authScheme) {
     85         if (authScheme == null) {
     86             invalidate();
     87             return;
     88         }
     89         this.authScheme = authScheme;
     90     }
     91 
     92     /**
     93      * Returns the {@link AuthScheme authentication scheme}.
     94      *
     95      * @return {@link AuthScheme authentication scheme}
     96      */
     97     public AuthScheme getAuthScheme() {
     98         return this.authScheme;
     99     }
    100 
    101 
    102     /**
    103      * Returns user {@link Credentials} selected for authentication if available
    104      *
    105      * @return user credentials if available, <code>null</code otherwise
    106      */
    107     public Credentials getCredentials() {
    108         return this.credentials;
    109     }
    110 
    111 
    112     /**
    113      * Sets user {@link Credentials} to be used for authentication
    114      *
    115      * @param credentials User credentials
    116      */
    117     public void setCredentials(final Credentials credentials) {
    118         this.credentials = credentials;
    119     }
    120 
    121 
    122     /**
    123      * Returns actual {@link AuthScope} if available
    124      *
    125      * @return actual authentication scope if available, <code>null</code otherwise
    126      */
    127      public AuthScope getAuthScope() {
    128         return this.authScope;
    129      }
    130 
    131      /**
    132       * Sets actual {@link AuthScope}.
    133       *
    134       * @param authScope Authentication scope
    135       */
    136      public void setAuthScope(final AuthScope authScope) {
    137         this.authScope = authScope;
    138      }
    139 
    140 
    141     @Override
    142     public String toString() {
    143         StringBuilder buffer = new StringBuilder();
    144         buffer.append("auth scope [");
    145         buffer.append(this.authScope);
    146         buffer.append("]; credentials set [");
    147         buffer.append(this.credentials != null ? "true" : "false");
    148         buffer.append("]");
    149         return buffer.toString();
    150     }
    151 
    152 }
    153