1 7 package org.jboss.security; 8 9 import java.security.PrivilegedAction ; 10 import java.security.Principal ; 11 import java.security.AccessController ; 12 13 import javax.security.auth.Subject ; 14 15 21 class SecurityAssociationActions 22 { 23 private static class SetPrincipalInfoAction implements PrivilegedAction 24 { 25 Principal principal; 26 Object credential; 27 Subject subject; 28 SetPrincipalInfoAction(Principal principal, Object credential, Subject subject) 29 { 30 this.principal = principal; 31 this.credential = credential; 32 this.subject = subject; 33 } 34 public Object 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 44 { 45 static PrivilegedAction ACTION = new SetServerAction(); 46 public Object run() 47 { 48 SecurityAssociation.setServer(); 49 return null; 50 } 51 } 52 private static class ClearAction implements PrivilegedAction 53 { 54 static PrivilegedAction ACTION = new ClearAction(); 55 public Object run() 56 { 57 SecurityAssociation.clear(); 58 return null; 59 } 60 } 61 private static class GetSubjectAction implements PrivilegedAction 62 { 63 static PrivilegedAction ACTION = new GetSubjectAction(); 64 public Object run() 65 { 66 Subject subject = SecurityAssociation.getSubject(); 67 return subject; 68 } 69 } 70 private static class GetPrincipalAction implements PrivilegedAction 71 { 72 static PrivilegedAction ACTION = new GetPrincipalAction(); 73 public Object run() 74 { 75 Principal principal = SecurityAssociation.getPrincipal(); 76 return principal; 77 } 78 } 79 private static class GetCredentialAction implements PrivilegedAction 80 { 81 static PrivilegedAction ACTION = new GetCredentialAction(); 82 public Object run() 83 { 84 Object credential = SecurityAssociation.getCredential(); 85 return credential; 86 } 87 } 88 89 static void setPrincipalInfo(Principal principal, Object credential, Subject 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 getSubject() 103 { 104 Subject subject = (Subject ) AccessController.doPrivileged(GetSubjectAction.ACTION); 105 return subject; 106 } 107 static Principal getPrincipal() 108 { 109 Principal principal = (Principal ) AccessController.doPrivileged(GetPrincipalAction.ACTION); 110 return principal; 111 } 112 static Object getCredential() 113 { 114 Object credential = AccessController.doPrivileged(GetCredentialAction.ACTION); 115 return credential; 116 } 117 118 } 119 | Popular Tags |