KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > authenticator > SingleSignOnEntry


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.catalina.authenticator;
18
19 import java.security.Principal JavaDoc;
20
21 import org.apache.catalina.Session;
22 import org.apache.catalina.authenticator.Constants;
23
24 /**
25  * A class that represents entries in the cache of authenticated users.
26  * This is necessary to make it available to
27  * <code>AuthenticatorBase</code> subclasses that need it in order to perform
28  * reauthentications when SingleSignOn is in use.
29  *
30  * @author B Stansberry, based on work by Craig R. McClanahan
31  * @version $Revision: 467222 $
32  *
33  * @see SingleSignOn
34  * @see AuthenticatorBase#reauthenticateFromSSO
35  */

36 public class SingleSignOnEntry
37 {
38     // ------------------------------------------------------ Instance Fields
39

40     protected String JavaDoc authType = null;
41
42     protected String JavaDoc password = null;
43
44     protected Principal JavaDoc principal = null;
45
46     protected Session sessions[] = new Session[0];
47
48     protected String JavaDoc username = null;
49
50     protected boolean canReauthenticate = false;
51
52     // --------------------------------------------------------- Constructors
53

54     /**
55      * Creates a new SingleSignOnEntry
56      *
57      * @param principal the <code>Principal</code> returned by the latest
58      * call to <code>Realm.authenticate</code>.
59      * @param authType the type of authenticator used (BASIC, CLIENT-CERT,
60      * DIGEST or FORM)
61      * @param username the username (if any) used for the authentication
62      * @param password the password (if any) used for the authentication
63      */

64     public SingleSignOnEntry(Principal JavaDoc principal, String JavaDoc authType,
65                              String JavaDoc username, String JavaDoc password) {
66         super();
67         updateCredentials(principal, authType, username, password);
68     }
69
70     public SingleSignOnEntry() {
71     }
72
73     // ------------------------------------------------------- Package Methods
74

75     /**
76      * Adds a <code>Session</code> to the list of those associated with
77      * this SSO.
78      *
79      * @param sso The <code>SingleSignOn</code> valve that is managing
80      * the SSO session.
81      * @param session The <code>Session</code> being associated with the SSO.
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     /**
96      * Removes the given <code>Session</code> from the list of those
97      * associated with this SSO.
98      *
99      * @param session the <code>Session</code> to remove.
100      */

101     public synchronized void removeSession(Session session) {
102         Session[] nsessions = new Session[sessions.length - 1];
103         for (int i = 0, j = 0; i < sessions.length; i++) {
104             if (session == sessions[i])
105                 continue;
106             nsessions[j++] = sessions[i];
107         }
108         sessions = nsessions;
109     }
110
111     /**
112      * Returns the <code>Session</code>s associated with this SSO.
113      */

114     public synchronized Session[] findSessions() {
115         return (this.sessions);
116     }
117
118     /**
119      * Gets the name of the authentication type originally used to authenticate
120      * the user associated with the SSO.
121      *
122      * @return "BASIC", "CLIENT-CERT", "DIGEST", "FORM" or "NONE"
123      */

124     public String JavaDoc getAuthType() {
125         return (this.authType);
126     }
127
128     /**
129      * Gets whether the authentication type associated with the original
130      * authentication supports reauthentication.
131      *
132      * @return <code>true</code> if <code>getAuthType</code> returns
133      * "BASIC" or "FORM", <code>false</code> otherwise.
134      */

135     public boolean getCanReauthenticate() {
136         return (this.canReauthenticate);
137     }
138
139     /**
140      * Gets the password credential (if any) associated with the SSO.
141      *
142      * @return the password credential associated with the SSO, or
143      * <code>null</code> if the original authentication type
144      * does not involve a password.
145      */

146     public String JavaDoc getPassword() {
147         return (this.password);
148     }
149
150     /**
151      * Gets the <code>Principal</code> that has been authenticated by
152      * the SSO.
153      */

154     public Principal JavaDoc getPrincipal() {
155         return (this.principal);
156     }
157
158     /**
159      * Gets the username provided by the user as part of the authentication
160      * process.
161      */

162     public String JavaDoc getUsername() {
163         return (this.username);
164     }
165
166
167     /**
168      * Updates the SingleSignOnEntry to reflect the latest security
169      * information associated with the caller.
170      *
171      * @param principal the <code>Principal</code> returned by the latest
172      * call to <code>Realm.authenticate</code>.
173      * @param authType the type of authenticator used (BASIC, CLIENT-CERT,
174      * DIGEST or FORM)
175      * @param username the username (if any) used for the authentication
176      * @param password the password (if any) used for the authentication
177      */

178     public void updateCredentials(Principal JavaDoc principal, String JavaDoc authType,
179                                   String JavaDoc username, String JavaDoc password) {
180
181         this.principal = principal;
182         this.authType = authType;
183         this.username = username;
184         this.password = password;
185         this.canReauthenticate =
186             (Constants.BASIC_METHOD.equals(authType)
187                 || Constants.FORM_METHOD.equals(authType));
188     }
189
190 }
191
Popular Tags