1 17 package org.apache.geronimo.security.jaas; 18 19 import java.security.Principal ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.Set ; 25 import javax.security.auth.Subject ; 26 27 import org.apache.geronimo.security.ContextManager; 28 import org.apache.geronimo.security.RealmPrincipal; 29 30 36 public class JaasSecurityContext { 37 private String realmName; 38 private Subject subject; 39 private long created; 40 private boolean done; 41 private JaasLoginModuleConfiguration[] modules; 42 private DecouplingCallbackHandler handler; 43 private Set processedPrincipals = new HashSet (); 44 45 public JaasSecurityContext(String realmName, JaasLoginModuleConfiguration[] modules) { 46 this.realmName = realmName; 47 this.created = System.currentTimeMillis(); 48 this.done = false; 49 this.modules = modules; 50 subject = new Subject (); 51 } 52 53 public Subject getSubject() { 54 return subject; 55 } 56 57 public long getCreated() { 58 return created; 59 } 60 61 public boolean isDone() { 62 return done; 63 } 64 65 public void setDone(boolean done) { 66 this.done = done; 67 } 68 69 public JaasLoginModuleConfiguration[] getModules() { 70 return modules; 71 } 72 73 public DecouplingCallbackHandler getHandler() { 74 if(handler == null) { handler = new DecouplingCallbackHandler(); 76 } 77 return handler; 78 } 79 80 public void processPrincipals(String loginDomainName) { 81 List list = new LinkedList (); 82 for (Iterator it = subject.getPrincipals().iterator(); it.hasNext();) { 83 Principal p = (Principal ) it.next(); 84 if(!(p instanceof RealmPrincipal) && !processedPrincipals.contains(p)) { 85 list.add(ContextManager.registerPrincipal(new RealmPrincipal(loginDomainName, p))); 86 processedPrincipals.add(p); 87 } 88 } 89 subject.getPrincipals().addAll(list); 90 } 91 92 public void processPrincipals(Principal [] principals, String loginDomainName) { 93 List list = new LinkedList (); 94 for (int i = 0; i < principals.length; i++) { 95 Principal p = principals[i]; 96 list.add(p); 97 list.add(ContextManager.registerPrincipal(new RealmPrincipal(loginDomainName, p))); 98 processedPrincipals.add(p); 99 } 100 subject.getPrincipals().addAll(list); 101 } 102 103 public Set getProcessedPrincipals() { 104 return processedPrincipals; 105 } 106 107 public String getRealmName() { 108 return realmName; 109 } 110 } 111 | Popular Tags |