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/AuthScheme.java $
      3  * $Revision: 537144 $
      4  * $Date: 2007-05-11 02:30:13 -0700 (Fri, 11 May 2007) $
      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 import org.apache.http.Header;
     34 import org.apache.http.HttpRequest;
     35 
     36 /**
     37  * <p>
     38  * This interface represents an abstract challenge-response oriented
     39  * authentication scheme.
     40  * </p>
     41  * <p>
     42  * An authentication scheme should be able to support the following
     43  * functions:
     44  * <ul>
     45  *   <li>Parse and process the challenge sent by the targer server
     46  *       in response to request for a protected resource
     47  *   <li>Provide its textual designation
     48  *   <li>Provide its parameters, if available
     49  *   <li>Provide the realm this authentication scheme is applicable to,
     50  *       if available
     51  *   <li>Generate authorization string for the given set of credentials,
     52  *       request method and URI as specificed in the HTTP request line
     53  *       in response to the actual authorization challenge
     54  * </ul>
     55  * </p>
     56  * <p>
     57  * Authentication schemes may ignore method name and URI parameters
     58  * if they are not relevant for the given authentication mechanism
     59  * </p>
     60  * <p>
     61  * Authentication schemes may be stateful involving a series of
     62  * challenge-response exchanges
     63  * </p>
     64  *
     65  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
     66  * @author <a href="mailto:adrian (at) ephox.com">Adrian Sutton</a>
     67  *
     68  * @since 4.0
     69  *
     70  * @deprecated Please use {@link java.net.URL#openConnection} instead.
     71  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
     72  *     for further details.
     73  */
     74 
     75 @Deprecated
     76 public interface AuthScheme {
     77 
     78     /**
     79      * Processes the given challenge token. Some authentication schemes
     80      * may involve multiple challenge-response exchanges. Such schemes must be able
     81      * to maintain the state information when dealing with sequential challenges
     82      *
     83      * @param header the challenge header
     84      */
     85     void processChallenge(final Header header) throws MalformedChallengeException;
     86 
     87     /**
     88      * Returns textual designation of the given authentication scheme.
     89      *
     90      * @return the name of the given authentication scheme
     91      */
     92     String getSchemeName();
     93 
     94     /**
     95      * Returns authentication parameter with the given name, if available.
     96      *
     97      * @param name The name of the parameter to be returned
     98      *
     99      * @return the parameter with the given name
    100      */
    101     String getParameter(final String name);
    102 
    103     /**
    104      * Returns authentication realm. If the concept of an authentication
    105      * realm is not applicable to the given authentication scheme, returns
    106      * <code>null</code>.
    107      *
    108      * @return the authentication realm
    109      */
    110     String getRealm();
    111 
    112     /**
    113      * Tests if the authentication scheme is provides authorization on a per
    114      * connection basis instead of usual per request basis
    115      *
    116      * @return <tt>true</tt> if the scheme is connection based, <tt>false</tt>
    117      * if the scheme is request based.
    118      */
    119     boolean isConnectionBased();
    120 
    121     /**
    122      * Authentication process may involve a series of challenge-response exchanges.
    123      * This method tests if the authorization process has been completed, either
    124      * successfully or unsuccessfully, that is, all the required authorization
    125      * challenges have been processed in their entirety.
    126      *
    127      * @return <tt>true</tt> if the authentication process has been completed,
    128      * <tt>false</tt> otherwise.
    129      */
    130     boolean isComplete();
    131 
    132     /**
    133      * Produces an authorization string for the given set of {@link Credentials}.
    134      *
    135      * @param credentials The set of credentials to be used for athentication
    136      * @param request The request being authenticated
    137      * @throws AuthenticationException if authorization string cannot
    138      *   be generated due to an authentication failure
    139      *
    140      * @return the authorization string
    141      */
    142     Header authenticate(Credentials credentials, HttpRequest request)
    143             throws AuthenticationException;
    144 
    145 }
    146