1 15 16 package com.jdon.security.web; 17 18 import java.security.Principal ; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpSession ; 22 23 import com.jdon.controller.model.Model; 24 import com.jdon.controller.model.ModelIF; 25 import com.jdon.controller.pool.Poolable; 26 import com.jdon.util.Debug; 27 28 33 public abstract class AbstractUserPrincipal implements UserPrincipal, Poolable { 34 35 public final static String USERMODEL = "USERMODEL"; 36 37 private final static String module = AbstractUserPrincipal.class.getName(); 38 39 45 public ModelIF getUserFromPrincipal(HttpServletRequest request) { 46 Debug.logVerbose("[JdonFramework]--> enter getUserFromPrincipal", module); 47 Principal principal = request.getUserPrincipal(); 48 if (principal == null) { 49 Debug.logVerbose("[JdonFramework]principal is null, not login by JAAS", module); 50 return null; 51 } 52 String username = principal.getName(); 53 Debug.logVerbose("[JdonFramework]--> find the logined username=" + username, module); 54 HttpSession session = request.getSession(); 55 ModelIF model = (ModelIF) session.getAttribute(USERMODEL); 56 if (model == null) { 57 model = findUserModelIFByName(request, username); 58 session.setAttribute(USERMODEL, model); 59 } 60 return model; 61 } 62 63 public void saveModeltoSession(HttpServletRequest request, ModelIF model) { 64 HttpSession session = request.getSession(); 65 session.setAttribute(USERMODEL, model); 66 } 67 68 73 public ModelIF getUserFromSession(HttpServletRequest request) { 74 Debug.logVerbose("[JdonFramework]--> enter getUserFromSession", module); 75 HttpSession session = request.getSession(); 76 ModelIF model = (ModelIF) session.getAttribute(USERMODEL); 77 return model; 78 } 79 80 public ModelIF findUserModelIFByName(HttpServletRequest request, 81 String key){ 82 return findUserModelByName(request, key); 83 } 84 85 public abstract Model findUserModelByName(HttpServletRequest request, 86 String key); 87 } 88 | Popular Tags |