On Wed, 2006-09-13 at 19:23 +0530, Saminda Abeyruwan wrote:
> -----BEGIN PGP SIGNED MESSAGE-----

...

> Hi Oleg
> 
> Thank you very much for the response.
> 
> My custom credential provider is as follows,
> 
> ===========================================================================
> import org.apache.commons.httpclient.auth.*;
> import org.apache.commons.httpclient.Credentials;
> import org.apache.commons.httpclient.NTCredentials;
> import org.apache.commons.httpclient.UsernamePasswordCredentials;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> 
> import java.io.IOException;
> /*
>  *
>  */
> 
> public class HTTPCredentialProvider implements CredentialsProvider {
> 
>     private static Log log =
> LogFactory.getLog(HTTPCredentialProvider.class);
> 
>     private String host;
>     private String realm;
>     private String username;
>     private String password;
> 
> 
>     public HTTPCredentialProvider(String host, String realm, String
> username, String password) {
>         this.host = host;
>         this.realm = realm;
>         this.username = username;
>         this.password = password;
> 
>     }
> 
>     public Credentials getCredentials(AuthScheme authscheme, String
> string, int i, boolean b)
>             throws CredentialsNotAvailableException {
>         if (authscheme == null) {
>             return null;
>         }
>         try {
>             if (authscheme instanceof NTLMScheme) {
>                 log.debug("NTLM Authentication authentication");
>                 if (username == null || password == null || host == null
> || realm == null) {
>                     throw new CredentialsNotAvailableException(
>                             "user or password or host or realm cannot be
> Null");
>                 }
>                 return new NTCredentials(username, password, host, realm);
>             } else if (authscheme instanceof RFC2617Scheme) {
>                 log.debug(host + " : " + " requires authentication with
> the realm '"
>                           + authscheme.getRealm() + "'");
>                 return new UsernamePasswordCredentials(username, password);
>             } else {
>                 throw new CredentialsNotAvailableException("Unsupported
> authentication scheme: " +
> 
> authscheme.getSchemeName());
>             }
>         } catch (IOException e) {
>             throw new CredentialsNotAvailableException(e.getMessage(), e);
>         }
> 
>     }
> 
> }
> ==========================================================================
> Axis2 just need to work with NTLM, Digest and Basic Auth. Would the
> above custom credential class satisfy the necessary requirement as you
> mentioned. Is there any improvement i should do.
> 
> Clients of Axis2, just say "Turn on Auth", and set host,..etc, where
> they set to HTTPCredentialProvider internally and httpclient magically
> do the auth.  Is this the correct way to handle this situation.
> 
> Saminda

Saminda,

This credentials provider will cause HttpClient to enter an infinite
loop if the given credentials are not valid for some reason (due to a
type, for instance).

Essentially all you have to do to get the same net effect is this:

String username = "username";
String password = "password";
String host = "somehost";
String realm = "realm";
NTCredentials creds = new NTCredentials(
  username, password, host, realm);
httpclient.getState().setCredentials(
 new AuthScope(host, AuthScope.ANY_PORT), 
 creds);

NTCredentials is a super class of UsernamePasswordCredentials, so the
same set of credentials will work with Basic and Digest schemes.

Give it a shot.

Hope this helps

Oleg 


> > 
> >>>>
> >>>> Please do help me on this.
> >>>>
> >>>> Looking forward to hearing from you.
> >>>>
> >>>> Saminda
> >>>>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >>>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>>> For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> >>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFFCA1DYmklbLuW6wYRAhslAJ933HFsDmBHh/85h1H/Tui/+Qb9zwCgtZ4C
> 3W1ENt4dXTEHuRx7x+kRUT0=
> =od2a
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to