1 17 package org.alfresco.filesys.server.auth; 18 19 import org.alfresco.service.cmr.repository.NodeRef; 20 21 import net.sf.acegisecurity.Authentication; 22 23 31 public class ClientInfo 32 { 33 34 36 public final static int LogonNormal = 0; 37 public final static int LogonGuest = 1; 38 public final static int LogonNull = 2; 39 public final static int LogonAdmin = 3; 40 41 43 private static final String [] _logonTypStr = { "Normal", "Guest", "Null", "Administrator" }; 44 45 47 private String m_user; 48 private byte[] m_password; 49 50 52 private byte[] m_ansiPwd; 53 54 56 private int m_logonType; 57 58 60 private String m_domain; 61 62 64 private String m_opsys; 65 66 68 private String m_ipAddr; 69 70 72 private Authentication m_authToken; 73 74 76 private NodeRef m_homeNode; 77 78 84 public ClientInfo(String user, byte[] pwd) 85 { 86 setUserName(user); 87 setPassword(pwd); 88 } 89 90 95 public final String getDomain() 96 { 97 return m_domain; 98 } 99 100 105 public final String getOperatingSystem() 106 { 107 return m_opsys; 108 } 109 110 115 public final byte[] getPassword() 116 { 117 return m_password; 118 } 119 120 125 public final String getPasswordAsString() 126 { 127 if (m_password != null) 128 return new String (m_password); 129 return null; 130 } 131 132 137 public final char[] getPasswordAsCharArray() 138 { 139 char[] cpwd = null; 140 141 if (m_password != null) 142 { 143 String pwd = new String (m_password); 144 cpwd = new char[pwd.length()]; 145 pwd.getChars(0, pwd.length(), cpwd, 0); 146 } 147 return cpwd; 148 } 149 150 155 public final boolean hasANSIPassword() 156 { 157 return m_ansiPwd != null ? true : false; 158 } 159 160 165 public final byte[] getANSIPassword() 166 { 167 return m_ansiPwd; 168 } 169 170 175 public final String getANSIPasswordAsString() 176 { 177 if (m_ansiPwd != null) 178 return new String (m_ansiPwd); 179 return null; 180 } 181 182 187 public final String getUserName() 188 { 189 return m_user; 190 } 191 192 197 public final int getLogonType() 198 { 199 return m_logonType; 200 } 201 202 207 public final String getLogonTypeString() 208 { 209 return _logonTypStr[m_logonType]; 210 } 211 212 217 public final boolean isGuest() 218 { 219 return m_logonType == LogonGuest ? true : false; 220 } 221 222 227 public final boolean isNullSession() 228 { 229 return m_logonType == LogonNull ? true : false; 230 } 231 232 237 public final boolean isAdministrator() 238 { 239 return m_logonType == LogonAdmin ? true : false; 240 } 241 242 247 public final boolean hasClientAddress() 248 { 249 return m_ipAddr != null ? true : false; 250 } 251 252 257 public final String getClientAddress() 258 { 259 return m_ipAddr; 260 } 261 262 267 public final boolean hasAuthenticationToken() 268 { 269 return m_authToken != null ? true : false; 270 } 271 272 277 public final Authentication getAuthenticationToken() 278 { 279 return m_authToken; 280 } 281 282 287 public final boolean hasHomeFolder() 288 { 289 return m_homeNode != null ? true : false; 290 } 291 292 297 public final NodeRef getHomeFolder() 298 { 299 return m_homeNode; 300 } 301 302 307 public final void setDomain(String domain) 308 { 309 m_domain = domain; 310 } 311 312 317 public final void setOperatingSystem(String opsys) 318 { 319 m_opsys = opsys; 320 } 321 322 327 public final void setPassword(byte[] pwd) 328 { 329 m_password = pwd; 330 } 331 332 337 public final void setANSIPassword(byte[] pwd) 338 { 339 m_ansiPwd = pwd; 340 } 341 342 347 public final void setPassword(String pwd) 348 { 349 if (pwd != null) 350 m_password = pwd.getBytes(); 351 else 352 m_password = null; 353 } 354 355 360 public final void setUserName(String user) 361 { 362 m_user = user; 363 } 364 365 370 public final void setLogonType(int logonType) 371 { 372 m_logonType = logonType; 373 } 374 375 380 public final void setGuest(boolean guest) 381 { 382 setLogonType(guest == true ? LogonGuest : LogonNormal); 383 } 384 385 390 public final void setClientAddress(String addr) 391 { 392 m_ipAddr = addr; 393 } 394 395 400 public final void setAuthenticationToken(Authentication token) 401 { 402 m_authToken = token; 403 } 404 405 410 public final void setHomeFolder(NodeRef homeNode) 411 { 412 m_homeNode = homeNode; 413 } 414 415 420 public String toString() 421 { 422 StringBuffer str = new StringBuffer (); 423 str.append("["); 424 str.append(getUserName()); 425 str.append(":"); 426 str.append(getPassword()); 427 str.append(","); 428 str.append(getDomain()); 429 str.append(","); 430 str.append(getOperatingSystem()); 431 432 if (hasClientAddress()) 433 { 434 str.append(","); 435 str.append(getClientAddress()); 436 } 437 438 if ( hasAuthenticationToken()) 439 { 440 str.append(",token="); 441 str.append(getAuthenticationToken()); 442 } 443 444 if (isGuest()) 445 str.append(",Guest"); 446 str.append("]"); 447 448 return str.toString(); 449 } 450 } | Popular Tags |