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.ISecurityContext;
09: import org.jasig.portal.security.PortalSecurityException;
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12:
13: /**
14: * <p>This is an implementation of a SecurityContext that merely checks to see
15: * if the user exists in the UP_USERS database table but otherwise presumes
16: * to be pre-authenticated by the context from which it is called. The typical
17: * system where this might be used is a portal whose main page is protected by
18: * HTTP authentication (BASIC or otherwise).</p>
19: *
20: * @author Andrew Newman, newman@yale.edu
21: * @version $Revision: 34942 $
22: */
23: class TrustSecurityContext extends ChainingSecurityContext implements
24: ISecurityContext {
25:
26: private static final Log log = LogFactory
27: .getLog(TrustSecurityContext.class);
28:
29: private final int TRUSTSECURITYAUTHTYPE = 0xFF01;
30:
31: TrustSecurityContext() {
32: super ();
33: }
34:
35: public int getAuthType() {
36: return this .TRUSTSECURITYAUTHTYPE;
37: }
38:
39: public synchronized void authenticate()
40: throws PortalSecurityException {
41: this .isauth = true;
42: if (this .myPrincipal.UID != null) {
43: try {
44: String first_name, last_name;
45: String acct[] = AccountStoreFactory
46: .getAccountStoreImpl()
47: .getUserAccountInformation(this .myPrincipal.UID);
48: if (acct[0] != null) {
49: first_name = acct[1];
50: last_name = acct[2];
51: this .myPrincipal.FullName = first_name + " "
52: + last_name;
53: if (log.isInfoEnabled())
54: log.info("User " + this .myPrincipal.UID
55: + " is authenticated");
56: this .isauth = true;
57: } else {
58: if (log.isInfoEnabled())
59: log.info("No such user: "
60: + this .myPrincipal.UID);
61: }
62: } catch (Exception e) {
63: PortalSecurityException ep = new PortalSecurityException(
64: "SQL Database Error");
65: log.error(e, e);
66: throw (ep);
67: }
68: } else {
69: log
70: .error("Principal not initialized prior to authenticate");
71: }
72: // Ok...we are now ready to authenticate all of our subcontexts.
73: super.authenticate();
74: return;
75: }
76: }
|