01: package com.technoetic.xplanner.tags;
02:
03: import java.util.Collection;
04: import javax.servlet.jsp.JspException;
05: import javax.servlet.jsp.tagext.Tag;
06:
07: import net.sf.hibernate.HibernateException;
08: import org.apache.struts.util.RequestUtils;
09:
10: import com.technoetic.xplanner.db.hibernate.ThreadSession;
11: import com.technoetic.xplanner.domain.Project;
12: import com.technoetic.xplanner.security.auth.AuthorizationHelper;
13: import com.technoetic.xplanner.tags.db.DatabaseTagSupport;
14:
15: /**
16: * @jira XPR-15 Cannot deploy xplanner.war to Weblogic 8.1
17: */
18: public class IsUserAuthorizedForAnyTag extends DatabaseTagSupport {
19: private Collection collection;
20: private String name;
21: private String property;
22: private String permissions;
23: private int projectId;
24: private boolean negate;
25:
26: public int doStartTag() throws JspException {
27: String[] permissionArray = permissions.split(",");
28: Collection objects = getCollection();
29: boolean isAuthorized = false;
30: try {
31: isAuthorized = AuthorizationHelper.hasPermissionToAny(
32: permissionArray, objects, pageContext.getRequest(),
33: projectId);
34: } catch (Exception e) {
35: throw new JspException(e);
36: }
37: return (negate ? !isAuthorized : isAuthorized) ? Tag.EVAL_BODY_INCLUDE
38: : Tag.SKIP_BODY;
39: }
40:
41: public void release() {
42: collection = null;
43: name = null;
44: property = null;
45: permissions = null;
46: projectId = 0;
47: negate = false;
48: super .release();
49: }
50:
51: private Collection getCollection() throws JspException {
52: if (collection != null) {
53: return collection;
54: }
55: if (name != null) {
56: return (Collection) RequestUtils.lookup(pageContext, name,
57: property, null);
58: }
59: try {
60: return ThreadSession.get().find(
61: "from project in " + Project.class);
62: } catch (HibernateException e) {
63: throw new JspException(e);
64: }
65: }
66:
67: public void setCollection(Collection collection) {
68: this .collection = collection;
69: }
70:
71: public void setName(String name) {
72: this .name = name;
73: }
74:
75: public void setProperty(String property) {
76: this .property = property;
77: }
78:
79: public void setPermissions(String permissions) {
80: this .permissions = permissions;
81: }
82:
83: public void setNegate(boolean negate) {
84: this .negate = negate;
85: }
86:
87: public int getProjectId() {
88: return projectId;
89: }
90:
91: public void setProjectId(int projectId) {
92: this.projectId = projectId;
93: }
94: }
|