1 7 package org.jboss.web.tomcat.tc5.sso; 8 9 import java.security.Principal ; 10 11 import org.apache.catalina.Session; 12 import org.apache.catalina.authenticator.Constants; 13 import org.apache.catalina.authenticator.SingleSignOn; 14 15 22 class SingleSignOnEntry 23 { 24 26 private String authType = null; 27 28 private String password = null; 29 30 private Principal principal = null; 31 32 private Session sessions[] = new Session[0]; 33 34 private String username = null; 35 36 private boolean canReauthenticate = false; 37 38 40 50 SingleSignOnEntry(Principal principal, String authType, 51 String username, String password) 52 { 53 updateCredentials(principal, authType, username, password); 54 } 55 56 58 69 synchronized boolean addSession(SingleSignOn sso, Session session) 70 { 71 for (int i = 0; i < sessions.length; i++) 72 { 73 if (session == sessions[i]) 74 return false; 75 } 76 Session results[] = new Session[sessions.length + 1]; 77 System.arraycopy(sessions, 0, results, 0, sessions.length); 78 results[sessions.length] = session; 79 sessions = results; 80 session.addSessionListener(sso); 81 return true; 82 } 83 84 93 synchronized boolean removeSession(Session session) 94 { 95 if (sessions.length == 0) 96 return false; 97 98 boolean removed = false; 99 Session[] nsessions = new Session[sessions.length - 1]; 100 for (int i = 0, j = 0; i < sessions.length; i++) 101 { 102 if (session == sessions[i]) 103 { 104 removed = true; 105 continue; 106 } 107 else if (!removed && i == nsessions.length) 108 { 109 break; 113 } 114 nsessions[j++] = sessions[i]; 115 } 116 sessions = nsessions; 117 if (removed) 119 sessions = nsessions; 120 return removed; 121 } 122 123 126 synchronized Session[] findSessions() 127 { 128 return (this.sessions); 129 } 130 131 137 String getAuthType() 138 { 139 return (this.authType); 140 } 141 142 149 boolean getCanReauthenticate() 150 { 151 return (this.canReauthenticate); 152 } 153 154 161 String getPassword() 162 { 163 return (this.password); 164 } 165 166 183 Principal getPrincipal() 184 { 185 return (this.principal); 186 } 187 188 192 void setPrincipal(Principal principal) 193 { 194 this.principal = principal; 195 } 196 197 201 int getSessionCount() 202 { 203 return (sessions.length); 204 } 205 206 210 String getUsername() 211 { 212 return (this.username); 213 } 214 215 216 227 synchronized boolean updateCredentials(Principal principal, String authType, 228 String username, String password) 229 { 230 231 boolean changed = 232 (safeEquals(this.principal, principal) 233 || safeEquals(this.authType, authType) 234 || safeEquals(this.username, username) 235 || safeEquals(this.password, password)); 236 237 this.principal = principal; 238 this.authType = authType; 239 this.username = username; 240 this.password = password; 241 this.canReauthenticate = 242 (Constants.BASIC_METHOD.equals(authType) 243 || Constants.FORM_METHOD.equals(authType)); 244 return changed; 245 } 246 247 249 private boolean safeEquals(Object a, Object b) 250 { 251 return ((a == b) 252 || (a != null && a.equals(b)) 253 || (b != null && b.equals(a))); 254 } 255 } | Popular Tags |