KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > SecurityAssociationActions


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.security;
8
9 import java.security.PrivilegedAction JavaDoc;
10 import java.security.Principal JavaDoc;
11 import java.security.AccessController JavaDoc;
12
13 import javax.security.auth.Subject JavaDoc;
14
15 /** A PrivilegedAction implementation for setting the SecurityAssociation
16  * principal and credential
17  *
18  * @author Scott.Stark@jboss.org
19  * @version $Revison:$
20  */

21 class SecurityAssociationActions
22 {
23    private static class SetPrincipalInfoAction implements PrivilegedAction JavaDoc
24    {
25       Principal JavaDoc principal;
26       Object JavaDoc credential;
27       Subject JavaDoc subject;
28       SetPrincipalInfoAction(Principal JavaDoc principal, Object JavaDoc credential, Subject JavaDoc subject)
29       {
30          this.principal = principal;
31          this.credential = credential;
32          this.subject = subject;
33       }
34       public Object JavaDoc run()
35       {
36          SecurityAssociation.pushSubjectContext(subject, principal, credential);
37          credential = null;
38          principal = null;
39          subject = null;
40          return null;
41       }
42    }
43    private static class SetServerAction implements PrivilegedAction JavaDoc
44    {
45       static PrivilegedAction JavaDoc ACTION = new SetServerAction();
46       public Object JavaDoc run()
47       {
48          SecurityAssociation.setServer();
49          return null;
50       }
51    }
52    private static class ClearAction implements PrivilegedAction JavaDoc
53    {
54       static PrivilegedAction JavaDoc ACTION = new ClearAction();
55       public Object JavaDoc run()
56       {
57          SecurityAssociation.clear();
58          return null;
59       }
60    }
61    private static class GetSubjectAction implements PrivilegedAction JavaDoc
62    {
63       static PrivilegedAction JavaDoc ACTION = new GetSubjectAction();
64       public Object JavaDoc run()
65       {
66          Subject JavaDoc subject = SecurityAssociation.getSubject();
67          return subject;
68       }
69    }
70    private static class GetPrincipalAction implements PrivilegedAction JavaDoc
71    {
72       static PrivilegedAction JavaDoc ACTION = new GetPrincipalAction();
73       public Object JavaDoc run()
74       {
75          Principal JavaDoc principal = SecurityAssociation.getPrincipal();
76          return principal;
77       }
78    }
79    private static class GetCredentialAction implements PrivilegedAction JavaDoc
80    {
81       static PrivilegedAction JavaDoc ACTION = new GetCredentialAction();
82       public Object JavaDoc run()
83       {
84          Object JavaDoc credential = SecurityAssociation.getCredential();
85          return credential;
86       }
87    }
88
89    static void setPrincipalInfo(Principal JavaDoc principal, Object JavaDoc credential, Subject JavaDoc subject)
90    {
91       SetPrincipalInfoAction action = new SetPrincipalInfoAction(principal, credential, subject);
92       AccessController.doPrivileged(action);
93    }
94    static void setServer()
95    {
96       AccessController.doPrivileged(SetServerAction.ACTION);
97    }
98    static void clear()
99    {
100       AccessController.doPrivileged(ClearAction.ACTION);
101    }
102    static Subject JavaDoc getSubject()
103    {
104       Subject JavaDoc subject = (Subject JavaDoc) AccessController.doPrivileged(GetSubjectAction.ACTION);
105       return subject;
106    }
107    static Principal JavaDoc getPrincipal()
108    {
109       Principal JavaDoc principal = (Principal JavaDoc) AccessController.doPrivileged(GetPrincipalAction.ACTION);
110       return principal;
111    }
112    static Object JavaDoc getCredential()
113    {
114       Object JavaDoc credential = AccessController.doPrivileged(GetCredentialAction.ACTION);
115       return credential;
116    }
117
118 }
119
Popular Tags