KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > jaas > server > JaasSecuritySession


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.security.jaas.server;
18
19 import java.security.Principal JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.security.auth.Subject JavaDoc;
27 import javax.security.auth.login.LoginException JavaDoc;
28 import javax.security.auth.spi.LoginModule JavaDoc;
29
30 import org.apache.geronimo.security.DomainPrincipal;
31 import org.apache.geronimo.security.RealmPrincipal;
32
33
34 /**
35  * Tracks security information about a single user. This is used before,
36  * during, and after the login.
37  *
38  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
39  */

40 public class JaasSecuritySession {
41     private final String JavaDoc realmName;
42     private final Subject JavaDoc subject;
43     private final Map JavaDoc sharedContext;
44     private final long created;
45     private boolean done;
46     private final JaasLoginModuleConfiguration[] modules;
47     private final LoginModule JavaDoc[] loginModules;
48     private DecouplingCallbackHandler handler = new DecouplingCallbackHandler();
49
50     public JaasSecuritySession(String JavaDoc realmName, JaasLoginModuleConfiguration[] modules, Map JavaDoc sharedContext, ClassLoader JavaDoc classLoader) {
51         this.realmName = realmName;
52         this.created = System.currentTimeMillis();
53         this.done = false;
54         this.modules = modules;
55         subject = new Subject JavaDoc();
56         this.sharedContext = sharedContext;
57         loginModules = new LoginModule JavaDoc[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 JavaDoc getSubject() {
70         return subject;
71     }
72
73     public Map JavaDoc 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 JavaDoc getLoginModule(int index) throws LoginException JavaDoc {
94         checkRange(index);
95         return loginModules[index];
96     }
97
98     private void checkRange(int index) throws LoginException JavaDoc {
99         if (index < 0 || index >= loginModules.length) {
100             throw new LoginException JavaDoc("Invalid index: " + index);
101         }
102     }
103
104     public boolean isServerSide(int index) throws LoginException JavaDoc {
105         checkRange(index);
106         return modules[index].isServerSide();
107     }
108
109     public String JavaDoc getLoginDomainName(int index) throws LoginException JavaDoc {
110         checkRange(index);
111         return modules[index].getLoginDomainName();
112     }
113
114     public Map JavaDoc getOptions(int index) throws LoginException JavaDoc {
115         checkRange(index);
116         return modules[index].getOptions();
117     }
118
119     public DecouplingCallbackHandler getHandler() {
120         return handler;
121     }
122
123     public String JavaDoc getRealmName() {
124         return realmName;
125     }
126 }
127
Popular Tags