1 16 package org.jboss.web.tomcat.tc6.sso; 17 18 import java.security.Principal ; 19 20 import org.apache.catalina.Session; 21 import org.apache.catalina.authenticator.Constants; 22 import org.apache.catalina.authenticator.SingleSignOn; 23 24 31 class SingleSignOnEntry 32 { 33 35 private String authType = null; 36 37 private String password = null; 38 39 private Principal principal = null; 40 41 private Session sessions[] = new Session[0]; 42 43 private String username = null; 44 45 private boolean canReauthenticate = false; 46 47 49 59 SingleSignOnEntry(Principal principal, String authType, 60 String username, String password) 61 { 62 updateCredentials(principal, authType, username, password); 63 } 64 65 67 78 synchronized boolean addSession(SingleSignOn sso, Session session) 79 { 80 for (int i = 0; i < sessions.length; i++) 81 { 82 if (session == sessions[i]) 83 return false; 84 } 85 Session results[] = new Session[sessions.length + 1]; 86 System.arraycopy(sessions, 0, results, 0, sessions.length); 87 results[sessions.length] = session; 88 sessions = results; 89 session.addSessionListener(sso); 90 return true; 91 } 92 93 102 synchronized boolean removeSession(Session session) 103 { 104 if (sessions.length == 0) 105 return false; 106 107 boolean removed = false; 108 Session[] nsessions = new Session[sessions.length - 1]; 109 for (int i = 0, j = 0; i < sessions.length; i++) 110 { 111 if (session == sessions[i]) 112 { 113 removed = true; 114 continue; 115 } 116 else if (!removed && i == nsessions.length) 117 { 118 break; 122 } 123 nsessions[j++] = sessions[i]; 124 } 125 sessions = nsessions; 126 if (removed) 128 sessions = nsessions; 129 return removed; 130 } 131 132 135 synchronized Session[] findSessions() 136 { 137 return (this.sessions); 138 } 139 140 146 String getAuthType() 147 { 148 return (this.authType); 149 } 150 151 158 boolean getCanReauthenticate() 159 { 160 return (this.canReauthenticate); 161 } 162 163 170 String getPassword() 171 { 172 return (this.password); 173 } 174 175 192 Principal getPrincipal() 193 { 194 return (this.principal); 195 } 196 197 201 void setPrincipal(Principal principal) 202 { 203 this.principal = principal; 204 } 205 206 210 int getSessionCount() 211 { 212 return (sessions.length); 213 } 214 215 219 String getUsername() 220 { 221 return (this.username); 222 } 223 224 225 236 synchronized boolean updateCredentials(Principal principal, String authType, 237 String username, String password) 238 { 239 240 boolean changed = 241 (safeEquals(this.principal, principal) 242 || safeEquals(this.authType, authType) 243 || safeEquals(this.username, username) 244 || safeEquals(this.password, password)); 245 246 this.principal = principal; 247 this.authType = authType; 248 this.username = username; 249 this.password = password; 250 this.canReauthenticate = 251 (Constants.BASIC_METHOD.equals(authType) 252 || Constants.FORM_METHOD.equals(authType)); 253 return changed; 254 } 255 256 258 private boolean safeEquals(Object a, Object b) 259 { 260 return ((a == b) 261 || (a != null && a.equals(b)) 262 || (b != null && b.equals(a))); 263 } 264 } 265 | Popular Tags |