KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > smb > NtlmAuthenticator


1 /* jcifs smb client library in Java
2  * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package jcifs.smb;
20
21 /**
22 This class can be extended by applications that wish to trap authentication related exceptions and automatically retry the exceptional operation with different credentials. Read <a HREF="../../../authhandler.html">jCIFS Exceptions and NtlmAuthenticator</a> for complete details.
23  */

24
25 public abstract class NtlmAuthenticator {
26
27     private static NtlmAuthenticator auth;
28
29     private String JavaDoc url;
30     private SmbAuthException sae;
31
32     private void reset() {
33         url = null;
34         sae = null;
35     }
36
37 /**
38 Set the default <tt>NtlmAuthenticator</tt>. Once the default authenticator is set it cannot be changed. Calling this metho again will have no effect.
39  */

40
41     public synchronized static void setDefault( NtlmAuthenticator a ) {
42         if( auth != null ) {
43             return;
44         }
45         auth = a;
46     }
47
48     protected final String JavaDoc getRequestingURL() {
49         return url;
50     }
51     protected final SmbAuthException getRequestingException() {
52         return sae;
53     }
54
55 /**
56 Used internally by jCIFS when an <tt>SmbAuthException</tt> is trapped to retrieve new user credentials.
57  */

58
59     public static NtlmPasswordAuthentication
60                 requestNtlmPasswordAuthentication( String JavaDoc url, SmbAuthException sae ) {
61         if( auth == null ) {
62             return null;
63         }
64         synchronized( auth ) {
65             auth.url = url;
66             auth.sae = sae;
67             return auth.getNtlmPasswordAuthentication();
68         }
69     }
70 /**
71 An application extending this class must provide an implementation for this method that returns new user credentials try try when accessing SMB resources described by the <tt>getRequestingURL</tt> and <tt>getRequestingException</tt> methods.
72 If this method returns <tt>null</tt> the <tt>SmbAuthException</tt> that triggered the authenticator check will simply be rethrown. The default implementation returns <tt>null</tt>.
73 */

74     protected NtlmPasswordAuthentication getNtlmPasswordAuthentication() {
75         return null;
76     }
77 }
78
Popular Tags