01: /* jcifs smb client library in Java
02: * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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 com.knowgate.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 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 getRequestingURL() {
49: return url;
50: }
51:
52: protected final SmbAuthException getRequestingException() {
53: return sae;
54: }
55:
56: /**
57: Used internally by jCIFS when an <tt>SmbAuthException</tt> is trapped to retrieve new user credentials.
58: */
59:
60: public static NtlmPasswordAuthentication requestNtlmPasswordAuthentication(
61: String url, SmbAuthException sae) {
62: if (auth == null) {
63: return null;
64: }
65: synchronized (auth) {
66: auth.url = url;
67: auth.sae = sae;
68: return auth.getNtlmPasswordAuthentication();
69: }
70: }
71:
72: /**
73: 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.
74: 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>.
75: */
76: protected NtlmPasswordAuthentication getNtlmPasswordAuthentication() {
77: return null;
78: }
79: }
|