1 17 package org.apache.geronimo.security.jaas.server; 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.Map ; 25 import java.util.Set ; 26 import javax.security.auth.Subject ; 27 import javax.security.auth.login.LoginException ; 28 import javax.security.auth.spi.LoginModule ; 29 30 import org.apache.geronimo.security.DomainPrincipal; 31 import org.apache.geronimo.security.RealmPrincipal; 32 33 34 40 public class JaasSecuritySession { 41 private final String realmName; 42 private final Subject subject; 43 private final Map sharedContext; 44 private final long created; 45 private boolean done; 46 private final JaasLoginModuleConfiguration[] modules; 47 private final LoginModule [] loginModules; 48 private DecouplingCallbackHandler handler = new DecouplingCallbackHandler(); 49 50 public JaasSecuritySession(String realmName, JaasLoginModuleConfiguration[] modules, Map sharedContext, ClassLoader classLoader) { 51 this.realmName = realmName; 52 this.created = System.currentTimeMillis(); 53 this.done = false; 54 this.modules = modules; 55 subject = new Subject (); 56 this.sharedContext = sharedContext; 57 loginModules = new LoginModule [modules.length]; 58 for (int i = 0; i < modules.length; i++) { 59 if (modules[i].isWrapPrincipals()) { 60 loginModules[i] = new WrappingLoginModuleProxy(modules[i].getLoginModule(classLoader), 61 modules[i].getLoginDomainName(), 62 realmName); 63 } else { 64 loginModules[i] = modules[i].getLoginModule(classLoader); 65 } 66 } 67 } 68 69 public Subject getSubject() { 70 return subject; 71 } 72 73 public Map getSharedContext() { 74 return sharedContext; 75 } 76 77 public long getCreated() { 78 return created; 79 } 80 81 public boolean isDone() { 82 return done; 83 } 84 85 public void setDone(boolean done) { 86 this.done = done; 87 } 88 89 public JaasLoginModuleConfiguration[] getModules() { 90 return modules; 91 } 92 93 public LoginModule getLoginModule(int index) throws LoginException { 94 checkRange(index); 95 return loginModules[index]; 96 } 97 98 private void checkRange(int index) throws LoginException { 99 if (index < 0 || index >= loginModules.length) { 100 throw new LoginException ("Invalid index: " + index); 101 } 102 } 103 104 public boolean isServerSide(int index) throws LoginException { 105 checkRange(index); 106 return modules[index].isServerSide(); 107 } 108 109 public String getLoginDomainName(int index) throws LoginException { 110 checkRange(index); 111 return modules[index].getLoginDomainName(); 112 } 113 114 public Map getOptions(int index) throws LoginException { 115 checkRange(index); 116 return modules[index].getOptions(); 117 } 118 119 public DecouplingCallbackHandler getHandler() { 120 return handler; 121 } 122 123 public String getRealmName() { 124 return realmName; 125 } 126 } 127 | Popular Tags |