1 22 package org.jboss.web.tomcat.security.authenticators; 23 24 import java.security.PrivilegedAction ; 25 import java.security.Principal ; 26 import java.security.AccessController ; 27 28 import javax.security.auth.Subject ; 29 30 import org.jboss.security.SecurityAssociation; 31 import org.jboss.security.RunAsIdentity; 32 33 39 class SecurityAssociationActions 40 { 41 public static final String AUTH_EXCEPTION_KEY = "org.jboss.security.exception"; 42 43 private static class SetPrincipalInfoAction implements PrivilegedAction 44 { 45 Principal principal; 46 Object credential; 47 Subject subject; 48 SetPrincipalInfoAction(Principal principal, Object credential, Subject subject) 49 { 50 this.principal = principal; 51 this.credential = credential; 52 this.subject = subject; 53 } 54 55 public Object run() 56 { 57 SecurityAssociation.pushSubjectContext(subject, principal, credential); 58 credential = null; 59 principal = null; 60 subject = null; 61 return null; 62 } 63 } 64 private static class SetServerAction implements PrivilegedAction 65 { 66 static PrivilegedAction ACTION = new SetServerAction(); 67 public Object run() 68 { 69 SecurityAssociation.setServer(); 70 return null; 71 } 72 } 73 private static class ClearAction implements PrivilegedAction 74 { 75 static PrivilegedAction ACTION = new ClearAction(); 76 public Object run() 77 { 78 SecurityAssociation.clear(); 79 return null; 80 } 81 } 82 private static class GetSubjectAction implements PrivilegedAction 83 { 84 static PrivilegedAction ACTION = new GetSubjectAction(); 85 public Object run() 86 { 87 Subject subject = SecurityAssociation.getSubject(); 88 return subject; 89 } 90 } 91 private static class GetPrincipalAction implements PrivilegedAction 92 { 93 static PrivilegedAction ACTION = new GetPrincipalAction(); 94 public Object run() 95 { 96 Principal principal = SecurityAssociation.getPrincipal(); 97 return principal; 98 } 99 } 100 private static class GetCredentialAction implements PrivilegedAction 101 { 102 static PrivilegedAction ACTION = new GetCredentialAction(); 103 public Object run() 104 { 105 Object credential = SecurityAssociation.getCredential(); 106 return credential; 107 } 108 } 109 private static class PushRunAsRoleAction implements PrivilegedAction 110 { 111 RunAsIdentity principal; 112 PushRunAsRoleAction(RunAsIdentity principal) 113 { 114 this.principal = principal; 115 } 116 public Object run() 117 { 118 SecurityAssociation.pushRunAsIdentity(principal); 119 return null; 120 } 121 } 122 123 private static class PopRunAsRoleAction implements PrivilegedAction 124 { 125 static PrivilegedAction ACTION = new PopRunAsRoleAction(); 126 public Object run() 127 { 128 RunAsIdentity principal = SecurityAssociation.popRunAsIdentity(); 129 return principal; 130 } 131 } 132 private static class GetAuthExceptionAction implements PrivilegedAction 133 { 134 static PrivilegedAction ACTION = new GetAuthExceptionAction(); 135 public Object run() 136 { 137 Object exception = SecurityAssociation.getContextInfo(AUTH_EXCEPTION_KEY); 138 return exception; 139 } 140 } 141 private static class ClearAuthExceptionAction implements PrivilegedAction 142 { 143 static PrivilegedAction ACTION = new ClearAuthExceptionAction(); 144 public Object run() 145 { 146 Object exception = SecurityAssociation.setContextInfo(AUTH_EXCEPTION_KEY, null); 147 return exception; 148 } 149 } 150 151 static void setPrincipalInfo(Principal principal, Object credential, Subject subject) 152 { 153 SetPrincipalInfoAction action = new SetPrincipalInfoAction(principal, credential, subject); 154 AccessController.doPrivileged(action); 155 } 156 static void setServer() 157 { 158 AccessController.doPrivileged(SetServerAction.ACTION); 159 } 160 static void clear() 161 { 162 AccessController.doPrivileged(ClearAction.ACTION); 163 } 164 static Subject getSubject() 165 { 166 Subject subject = (Subject ) AccessController.doPrivileged(GetSubjectAction.ACTION); 167 return subject; 168 } 169 static Principal getPrincipal() 170 { 171 Principal principal = (Principal ) AccessController.doPrivileged(GetPrincipalAction.ACTION); 172 return principal; 173 } 174 static Object getCredential() 175 { 176 Object credential = AccessController.doPrivileged(GetCredentialAction.ACTION); 177 return credential; 178 } 179 static void pushRunAsIdentity(RunAsIdentity principal) 180 { 181 PushRunAsRoleAction action = new PushRunAsRoleAction(principal); 182 AccessController.doPrivileged(action); 183 } 184 static RunAsIdentity popRunAsIdentity() 185 { 186 RunAsIdentity principal = (RunAsIdentity) AccessController.doPrivileged(PopRunAsRoleAction.ACTION); 187 return principal; 188 } 189 190 static Throwable getAuthException() 191 { 192 Throwable ex = (Throwable ) AccessController.doPrivileged(GetAuthExceptionAction.ACTION); 193 return ex; 194 } 195 static void clearAuthException() 196 { 197 AccessController.doPrivileged(ClearAuthExceptionAction.ACTION); 198 } 199 } 200 | Popular Tags |