KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > security > CanAccessTag


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.security;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
21
22 import dlog4j.formbean.UserForm;
23 import web.security.Operation;
24 import web.security.Privilege;
25 import web.security.Range;
26 import web.security.Resource;
27 import web.security.impl.PrivilegeImpl;
28
29 /**
30  * 用来在页面上进行判断用户时候有访问的权限
31  * @author Winter Lau
32  */

33 public class CanAccessTag extends TagSupport JavaDoc {
34
35     protected String JavaDoc resource;
36     protected String JavaDoc operation;
37     protected String JavaDoc range;
38     
39     public int doStartTag() throws JspException JavaDoc {
40         UserForm user = UserForm.getLoginUser((HttpServletRequest JavaDoc)pageContext.getRequest());
41         if(user==null)
42             return SKIP_BODY;
43         DlogRole role = user.getRole();
44         if(role==null)
45             return SKIP_BODY;
46         return role.canDo(getPrivilege())?EVAL_BODY_INCLUDE:SKIP_BODY;
47     }
48
49     protected Privilege getPrivilege() {
50         try{
51             SecurityConfig sc = SecurityConfig.getConfig();
52             Resource res = sc.getResourceByName(resource);
53             Operation opt = sc.getOperationByName(operation);
54             Range rng = sc.getRangeByName(range);
55             return new PrivilegeImpl(res,opt,rng);
56         }catch(Exception JavaDoc e){
57             pageContext.getServletContext().log("",e);
58         }
59         return null;
60     }
61     public String JavaDoc getOperation() {
62         return operation;
63     }
64     public void setOperation(String JavaDoc operation) {
65         this.operation = operation;
66     }
67     public String JavaDoc getRange() {
68         return range;
69     }
70     public void setRange(String JavaDoc range) {
71         this.range = range;
72     }
73     public String JavaDoc getResource() {
74         return resource;
75     }
76     public void setResource(String JavaDoc resource) {
77         this.resource = resource;
78     }
79 }
80
Popular Tags