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 java.util.Enumeration;
09:
10: import org.jasig.portal.security.ISecurityContext;
11: import org.jasig.portal.security.PortalSecurityException;
12:
13: /**
14: * <p>A simple extension of ChainingSecurityContext that acts merely as a placeholder
15: * but considers itself in an "authenticated" state if any of its subcontexts
16: * are "authenticated."</p>
17: *
18: * @author Shawn Bayern
19: * @version $Revision: 36777 $ $Date: 2006-12-21 13:41:00 -0700 (Thu, 21 Dec 2006) $
20: */
21: class UnionSecurityContext extends ChainingSecurityContext {
22: private final int UNION_SECURITY_AUTHTYPE = 0xFF0A;
23:
24: public int getAuthType() {
25: return this .UNION_SECURITY_AUTHTYPE;
26: }
27:
28: public synchronized void authenticate()
29: throws PortalSecurityException {
30: // lets chaining invoke authetication on all subcontexts
31: // then sets resulting principal, descriptor and isauth based on
32: // first authenticated context.
33:
34: super .authenticate();
35:
36: Enumeration e = getSubContexts();
37: while (e.hasMoreElements()) {
38: ISecurityContext subCtx = (ISecurityContext) e
39: .nextElement();
40: if (subCtx.isAuthenticated()) {
41: this .myPrincipal = new ChainingPrincipal(subCtx
42: .getPrincipal());
43: this .myAdditionalDescriptor = subCtx
44: .getAdditionalDescriptor();
45: this .isauth = true;
46: break;
47: }
48: }
49: }
50:
51: public String toString() {
52: StringBuffer sb = new StringBuffer();
53: sb.append(this .getClass().getName());
54: sb.append(" principal:").append(this .myPrincipal);
55: sb.append(" additionalDescriptor:").append(
56: this .myAdditionalDescriptor);
57: sb.append(" isAuth:").append(this.isauth);
58: sb.append(this.mySubContexts);
59: return sb.toString();
60: }
61:
62: }
|