1 4 5 package com.sun.j2ee.blueprints.clientstate; 6 7 import javax.servlet.http.HttpSession ; 8 15 public class SessionPasswordStrategy implements PasswordStrategy { 16 17 public static final String DEFAULT_SESSION_KEY_FOR_PASSWORD = "com.sun.j2ee.blueprints.clientside-state.password-key"; 18 public static final int DEFAULT_PASSWORD_LENGTH = 24; 19 20 26 public SessionPasswordStrategy(HttpSession session) { 27 this(session, DEFAULT_PASSWORD_LENGTH, DEFAULT_SESSION_KEY_FOR_PASSWORD); 28 } 29 30 35 public SessionPasswordStrategy(HttpSession session, int passwordLength, String sessionKeyForPassword) { 36 this.session = session; 37 this.passwordLength = passwordLength; 38 this.sessionKeyForPassword = sessionKeyForPassword; 39 } 40 41 42 public String getPassword() { 43 String password = (String ) session.getAttribute(sessionKeyForPassword); 44 if (password == null) { 45 password = (String ) ByteArrayGuard.getRandomString(passwordLength); 46 session.setAttribute(sessionKeyForPassword, password); 47 } 48 return password; 49 } 50 51 private HttpSession session; 52 private String sessionKeyForPassword; 53 private int passwordLength; 54 } 55 | Popular Tags |