01: /*
02: * JOSSO: Java Open Single Sign-On
03: *
04: * Copyright 2004-2008, Atricore, Inc.
05: *
06: * This is free software; you can redistribute it and/or modify it
07: * under the terms of the GNU Lesser General Public License as
08: * published by the Free Software Foundation; either version 2.1 of
09: * the License, or (at your option) any later version.
10: *
11: * This software is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this software; if not, write to the Free
18: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20: */
21:
22: package org.josso.jb4.agent;
23:
24: import javax.security.auth.Subject;
25: import java.security.AccessController;
26: import java.security.Principal;
27: import java.security.PrivilegedAction;
28:
29: /**
30: * A PrivilegedAction implementation for setting the SecurityAssociation
31: * principal and credential for JBoss.
32: * <p>
33: * This class is used by the JBossCatalinaRealm class to set the authenticated Principal
34: * using the SetPrincipalInfoAction PrivilegedAction class.
35: *
36: * @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
37: * @version CVS $Id: JBossSecurityAssociationActions.java 508 2008-02-18 13:32:29Z sgonzalez $
38: */
39: class JBossSecurityAssociationActions {
40:
41: private static class SetPrincipalInfoAction implements
42: PrivilegedAction {
43: Principal principal;
44: Object credential;
45: Subject subject;
46:
47: SetPrincipalInfoAction(Principal principal, Object credential,
48: Subject subject) {
49: this .principal = principal;
50: this .credential = credential;
51: this .subject = subject;
52: }
53:
54: public Object run() {
55: org.jboss.security.SecurityAssociation.pushSubjectContext(
56: subject, principal, credential);
57: credential = null;
58: principal = null;
59: subject = null;
60: return null;
61: }
62: }
63:
64: static void setPrincipalInfo(Principal principal,
65: Object credential, Subject subject) {
66: SetPrincipalInfoAction action = new SetPrincipalInfoAction(
67: principal, credential, subject);
68: AccessController.doPrivileged(action);
69: }
70:
71: }
|