KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > security > web > LoginHandler


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
9   * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */

15
16 package com.jdon.security.web;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19
20 import com.jdon.controller.model.Model;
21 import com.jdon.controller.model.ModelIF;
22
23
24 /**
25
26  * 该Sample需è¦?两个è?½å®žï¼š
27  * 1. userPrincipal需è¦?有具体实现
28  * 2. getUserModelAfterLogin其实返回是UserModel
29  *
30  * <p>Copyright: Jdon.com Copyright (c) 2003</p>
31  * <p></p>
32  * @author banq
33  * @version 1.0
34  */

35
36 public class LoginHandler {
37
38
39   //将当å‰?用户登陆å?Žçš„UserModel实例放入HttpSession
40
private AbstractUserPrincipal userPrincipal;
41 // private static UserPrincipal userPrincipal = new UserPrincipalImp();
42

43   public LoginHandler(AbstractUserPrincipal userPrincipal){
44     this.userPrincipal = userPrincipal;
45
46   }
47
48
49
50   /**
51    * 获得登陆å?Žçš„User相关信æ?¯
52    * 本方法必须在上é?¢login执行å?Žï¼Œæˆ–者用户通过j_security_check登陆å?Žæ‰?å?¯æœ‰æ•ˆ
53    * 首先从HttpSession中查询,HttpSession中资料是由getUserFromPrincipal
54    * 第一次执行生æˆ?的。
55    *
56    * @param request
57    * @return UserModel
58    */

59   public Model getUserModelAfterLogin(HttpServletRequest JavaDoc request) {
60     ModelIF model = userPrincipal.getUserFromSession(request);
61     if (model == null)
62      model = userPrincipal.getUserFromPrincipal(request);
63     return (Model)model;
64   }
65
66
67
68   public AbstractUserPrincipal getUserPrincipal() {
69     return userPrincipal;
70   }
71   public void setUserPrincipal(AbstractUserPrincipal userPrincipal) {
72     this.userPrincipal = userPrincipal;
73   }
74
75 }
76
Popular Tags