KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > web > SingleSignOnEntry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.security.web;
25
26 import java.io.IOException JavaDoc;
27 import java.security.Principal JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.logging.Logger JavaDoc;
32 import java.util.logging.Level JavaDoc;
33
34 import javax.servlet.ServletException JavaDoc;
35 import javax.servlet.http.Cookie JavaDoc;
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38
39 import org.apache.catalina.Container;
40 import org.apache.catalina.HttpRequest;
41 import org.apache.catalina.HttpResponse;
42 import org.apache.catalina.Lifecycle;
43 import org.apache.catalina.LifecycleException;
44 import org.apache.catalina.Request;
45 import org.apache.catalina.Response;
46 import org.apache.catalina.Session;
47 import org.apache.catalina.SessionEvent;
48 import org.apache.catalina.SessionListener;
49 import org.apache.catalina.ValveContext;
50 import org.apache.catalina.authenticator.Constants;
51 import org.apache.catalina.Realm;
52
53 /**
54  * A private class representing entries in the cache of authenticated users.
55  */

56 public class SingleSignOnEntry {
57
58     public String JavaDoc authType = null;
59
60     public String JavaDoc password = null;
61
62     public Principal JavaDoc principal = null;
63
64     public Session sessions[] = new Session[0];
65
66     public String JavaDoc username = null;
67
68     public String JavaDoc realmName = null;
69
70     public long lastAccessTime;
71
72     public SingleSignOnEntry(Principal JavaDoc principal, String JavaDoc authType,
73                              String JavaDoc username, String JavaDoc password, String JavaDoc realmName) {
74         super();
75         this.principal = principal;
76         this.authType = authType;
77         this.username = username;
78         this.password = password;
79         this.realmName = realmName;
80         this.lastAccessTime = System.currentTimeMillis();
81     }
82
83     public synchronized void addSession(SingleSignOn sso, Session session) {
84         for (int i = 0; i < sessions.length; i++) {
85             if (session == sessions[i])
86                 return;
87         }
88         Session results[] = new Session[sessions.length + 1];
89         System.arraycopy(sessions, 0, results, 0, sessions.length);
90         results[sessions.length] = session;
91         sessions = results;
92         session.addSessionListener(sso);
93     }
94
95     public synchronized void removeSession(Session session) {
96         Session[] nsessions = new Session[sessions.length - 1];
97         for (int i = 0, j = 0; i < sessions.length; i++) {
98             if (session == sessions[i])
99                 continue;
100             nsessions[j++] = sessions[i];
101         }
102         sessions = nsessions;
103     }
104
105     public synchronized Session[] findSessions() {
106         return (this.sessions);
107     }
108
109 }
110
Popular Tags