1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2ACL library.
13 *
14 * The Initial Owner of the Original Code is Power Of Two S.R.L.
15 * Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16 * All Rights Reserved.
17 *
18 * Contributor(s):
19 */
20
21 package com.pow2.acl.taglib;
22
23 import com.pow2.acl.Group;
24 import com.pow2.acl.Permission;
25 import com.pow2.acl.dao.ACLDAO;
26
27 import com.pow2.user.User;
28 import com.pow2.util.Util;
29 import javax.servlet.http.HttpServletResponse;
30
31 import javax.servlet.http.HttpSession;
32
33 import javax.servlet.jsp.*;
34 import javax.servlet.jsp.tagext.*;
35
36 /***
37 * HasUserPermission class.
38 * <br>
39 * Check if the user retrieved from the session context
40 * has got the input permission.
41 *
42 * @author Massimiliano Farnea
43 */
44 public class HasUserPermissionTag extends ACLTag
45 {
46
47 /*** Default constructor */
48 public HasUserPermissionTag()
49 {
50 super();
51 }
52
53
54 /***
55 * Process the start tag for this instance.
56 * Eval the body of the tag if User has got the input permission.
57 *
58 * @return Description of the Returned Value
59 * @exception JspTagException if an error occures.
60 */
61 public int doStartTag() throws JspTagException
62 {
63 // cannot be null;
64 User user = getUser();
65
66 try
67 {
68 if (!Util.isNull(permission))
69 {
70 Permission prm = new Permission(permission);
71
72 userAuthenticated = (Util.isNull(group)) ?
73 acldao.hasUserPermission(user, prm) :
74 acldao.hasUserPermission(user, new Group(group), prm);
75 }
76 }
77 catch (Exception e)
78 {
79 cat.error("::doStartTag - exception: ", e);
80 throw new JspTagException("Error: " + e.getMessage());
81 }
82
83 return booleanValue(userAuthenticated) ? EVAL_BODY_INCLUDE : SKIP_BODY;
84 }
85 }
This page was automatically generated by Maven