01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.security.provider;
07:
08: import org.jasig.portal.security.IOpaqueCredentials;
09: import org.jasig.portal.security.PortalSecurityException;
10:
11: /**
12: * <p>This is an implementation of a SecurityContext that checks a user's
13: * credentials against an LDAP directory. It expects to be able to bind
14: * to the LDAP directory as the user so that it can authenticate the
15: * user. The user's credentials are cached.</p>
16: *
17: * @author Russell Tokuyama (University of Hawaii)
18: * @author Ken Weiner, kweiner@unicon.net
19: * @version $Revision: 34778 $
20: * @deprecated As of uPortal 2.1.3, use {@link org.jasig.portal.security.provider.SimpleLdapSecurityContext} chained with {@link org.jasig.portal.security.provider.CacheSecurityContext} instead
21: */
22: public class CacheLdapSecurityContext extends SimpleLdapSecurityContext {
23: private final int CACHELDAPSECURITYAUTHTYPE = 0xFF06;
24: private byte[] cachedCredentials;
25:
26: CacheLdapSecurityContext() {
27: super ();
28: }
29:
30: /**
31: * Returns the type of authentication this class provides.
32: * @return authorization type
33: */
34: public int getAuthType() {
35: /*
36: * What is this for? No one would know what to do with the
37: * value returned. Subclasses might know but our getAuthType()
38: * doesn't return anything easily useful.
39: */
40: return this .CACHELDAPSECURITYAUTHTYPE;
41: }
42:
43: /**
44: * Authenticates the user.
45: */
46: public synchronized void authenticate()
47: throws PortalSecurityException {
48: // Save our credentials before parent's authenticate() method
49: // destroys them.
50: this .cachedCredentials = new byte[this .myOpaqueCredentials.credentialstring.length];
51: System.arraycopy(this .myOpaqueCredentials.credentialstring, 0,
52: this .cachedCredentials, 0,
53: this .myOpaqueCredentials.credentialstring.length);
54:
55: super .authenticate();
56:
57: if (!this .isAuthenticated())
58: this .cachedCredentials = null;
59:
60: }
61:
62: /**
63: * We need to override this method in order to return a class that implements
64: * the NotSoOpaqueCredentals interface.
65: */
66: public IOpaqueCredentials getOpaqueCredentials() {
67: if (this .isauth) {
68: NotSoOpaqueCredentials oc = new CacheOpaqueCredentials();
69: oc.setCredentials(this .cachedCredentials);
70: return oc;
71: } else
72: return null;
73: }
74:
75: /**
76: * This is a new implementation of an OpaqueCredentials class that
77: * implements the less-opaque NotSoOpaqueCredentials.
78: */
79: private class CacheOpaqueCredentials extends
80: ChainingSecurityContext.ChainingOpaqueCredentials implements
81: NotSoOpaqueCredentials {
82:
83: /**
84: * Gets the credentials
85: * @return the credentials
86: */
87: public String getCredentials() {
88: if (this .credentialstring != null)
89: return new String(this.credentialstring);
90: else
91: return null;
92: }
93: }
94: }
|