commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbe...@apache.org
Subject cvs commit: jakarta-commons/httpclient/xdocs authentication.xml
Date Mon, 06 Sep 2004 20:10:02 GMT
mbecke      2004/09/06 13:10:02

  Modified:    httpclient/xdocs authentication.xml
  Added:       httpclient/src/examples CustomAuthenticationExample.java
  Log:
  Added custom authentication docs.
  
  PR: 29769
  Submitted by: Michael Becke
  Reviewed by: Oleg Kalnichevski
  
  Revision  Changes    Path
  1.1                  jakarta-commons/httpclient/src/examples/CustomAuthenticationExample.java
  
  Index: CustomAuthenticationExample.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/examples/CustomAuthenticationExample.java,v
1.1 2004/09/06 20:10:02 mbecke Exp $
   * $Revision: 1.1 $
   * $Date: 2004/09/06 20:10:02 $
   *
   * ====================================================================
   *
   *  Copyright 2002-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  import java.util.ArrayList;
  import java.util.Collection;
  
  import org.apache.commons.httpclient.Credentials;
  import org.apache.commons.httpclient.HttpMethod;
  import org.apache.commons.httpclient.auth.AuthPolicy;
  import org.apache.commons.httpclient.auth.AuthScheme;
  import org.apache.commons.httpclient.auth.AuthenticationException;
  import org.apache.commons.httpclient.auth.MalformedChallengeException;
  import org.apache.commons.httpclient.params.DefaultHttpParams;
  import org.apache.commons.httpclient.params.HttpParams;
  
  /**
   * A simple custom AuthScheme example.  The included auth scheme is meant 
   * for demonstration purposes only.  It does not actually implement a usable
   * authentication method.
   */
  public class CustomAuthenticationExample {
  
      public static void main(String[] args) {
          
          // register the auth scheme
          AuthPolicy.registerAuthScheme(SecretAuthScheme.NAME, SecretAuthScheme.class);
  
          // include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference,
          // this can be done on a per-client or per-method basis but we'll do it
          // globally for this example
          HttpParams params = DefaultHttpParams.getDefaultParams();        
          ArrayList schemes = new ArrayList();
          schemes.add(SecretAuthScheme.NAME);
          schemes.addAll((Collection) params.getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY));
          params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);
          
          // now that our scheme has been registered we can execute methods against
          // servers that require "Secret" authentication... 
      }
      
      /**
       * A custom auth scheme that just uses "Open Sesame" as the authentication
       * string.
       */
      private class SecretAuthScheme implements AuthScheme {
  
          public static final String NAME = "Secret";
  
          public SecretAuthScheme() {
              // All auth schemes must have a no arg constructor.
          }
          public String authenticate(Credentials credentials, HttpMethod method)
              throws AuthenticationException {
              return "Open Sesame";
          }
          public String authenticate(Credentials credentials, String method,
                  String uri) throws AuthenticationException {
              return "Open Sesame";
          }
          public String getID() {
              return NAME;
          }
          public String getParameter(String name) {
              // this scheme does not use parameters, see RFC2617Scheme for an example
              return null;
          }
          public String getRealm() {
              // this scheme does not use realms
              return null;
          }
          public String getSchemeName() {
              return NAME;
          }
          public boolean isConnectionBased() {
              return false;
          }
          public void processChallenge(String challenge)
                  throws MalformedChallengeException {
              // Nothing to do here, this is not a challenge based
              // auth scheme.  See NTLMScheme for a good example.
          }
          public boolean isComplete() {
              // again we're not a challenge based scheme so this is always true
              return true;
          }
      }
  }
  
  
  
  1.13      +48 -8     jakarta-commons/httpclient/xdocs/authentication.xml
  
  Index: authentication.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/xdocs/authentication.xml,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- authentication.xml	29 Jun 2004 20:16:15 -0000	1.12
  +++ authentication.xml	6 Sep 2004 20:10:02 -0000	1.13
  @@ -15,6 +15,30 @@
         <p>HttpClient supports three different types of http authentication schemes:
         Basic, Digest and NTLM.  These can be used to authenticate with http servers
         or proxies.</p>
  +      <subsection name="Contents">
  +        <ul>
  +            <li>
  +                <a href="#Server Authentication">Server Authentication</a>
  +                <ul>
  +                    <li><a href="#Preemptive Authentication">Preemptive Authentication</a></li>
  +                    <li><a href="#Security aspects of server authentication">Security
aspects of server authentication</a></li>
  +                </ul>
  +            </li>
  +            <li><a href="#Proxy Authentication">Proxy Authentication</a></li>
  +            <li>
  +                <a href="#Authentication Schemes">Authentication Schemes</a>
  +                <ul>
  +                    <li><a href="#Basic">Basic</a></li>
  +                    <li><a href="#Digest">Digest</a></li>
  +                    <li><a href="#NTLM">NTLM</a></li>
  +                    <li><a href="#Alternate authentication">Alternate authentication</a></li>
  +                    <li><a href="#Custom authentication scheme">Custom authentication
scheme</a></li>
  +                </ul>
  +            </li>
  +            <li><a href="#Examples">Examples</a></li>
  +            <li><a href="#Troubleshooting">Troubleshooting</a></li>
  +        </ul>
  +      </subsection>
       </section>
   
   	<section name="Server Authentication">
  @@ -190,14 +214,30 @@
   // This will exclude the NTLM authentication scheme
   client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);</source>
       </subsection>
  +	<subsection name="Custom authentication scheme">
  +	   <p>HttpClient natively supports basic, digest, and NTLM authentication. It also
contains
  +        a mechanism to plugin additional custom authentication schemes via the 
  +        <a href="apidocs/org/apache/commons/httpclient/auth/AuthScheme.html">AuthScheme</a>
interface.
  +        The following steps are required to make use of a custom authentication scheme.
  +        <ol>
  +            <li>Implement the <code>AuthScheme</code> interface.</li>
  +            <li>Register the custom <code>AuthScheme</code> with <a
href="apidocs/org/apache/commons/httpclient/auth/AuthPolicy.html#registerAuthScheme(java.lang.String,%20java.lang.Class)">
  +            AuthPolicy.registerAuthScheme()</a>.</li>
  +            <li>Include the custom <code>AuthScheme</code> in the AuthPolicy.AUTH_SCHEME_PRIORITY
preference
  +              (see the <a href="#Alternate authentication">Alternate authentication</a>
section).</li>
  +        </ol>
  +	   </p>
  +	</subsection>
   	</section>
  -
  -  <section name="Examples">
  -      <p>There is an <a href="http://cvs.apache.org/viewcvs.cgi/*checkout*/jakarta-commons/httpclient/src/examples/BasicAuthenticatonExample.java?rev=HEAD&amp;content-type=text/plain">example</a>

  -      of basic authentication available in the       
  -      <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/">example
directory</a> in CVS.
  -      </p>
  -  </section>
  +    <section name="Examples">
  +        <p>There are a number of authentication examples in the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/">example
directory</a>, including:
  +            <ul>
  +                <li><a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/BasicAuthenticationExample.java?view=auto">Basic
authentication</a></li>
  +                <li><a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/CustomAuthenticationExample.java?view=auto">Custom
authentication</a></li>
  +                <li><a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/InteractiveAuthenticationExample.java?view=auto">Interactive
authentication</a></li>
  +            </ul>
  +        </p>
  +    </section>
       
     <section name="Troubleshooting">
         <p>Some authentication schemes may use cryptographic algorithms. It is recommended
to include the
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message