KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > security > SecurityTag


1 package org.nextime.ion.backoffice.security;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
5
6 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
7
8 import org.nextime.ion.framework.business.Publication;
9 import org.nextime.ion.framework.business.Section;
10 import org.nextime.ion.framework.business.User;
11 import org.nextime.ion.framework.mapping.Mapping;
12
13 public class SecurityTag extends TagSupport JavaDoc {
14
15     protected String JavaDoc _action;
16     protected String JavaDoc _publication;
17     protected String JavaDoc _version;
18     protected String JavaDoc _section;
19     protected String JavaDoc _user;
20
21     public int doStartTag() throws JspException JavaDoc {
22         evaluateExpressions();
23         if (check())
24             return (EVAL_BODY_INCLUDE);
25         else
26             return (SKIP_BODY);
27     }
28
29     public int doEndTag() throws JspException JavaDoc {
30         return (EVAL_PAGE);
31     }
32
33     protected boolean check() {
34         try {
35             Mapping.begin();
36             User user = null;
37             try {
38                 if (getUser() != null) {
39                     user = User.getInstance(getUser());
40                 }
41             } catch (Exception JavaDoc e) {
42             }
43             Publication publication = null;
44             try {
45                 if (getPublication() != null) {
46                     publication = Publication.getInstance(getPublication());
47                 }
48             } catch (Exception JavaDoc e) {
49             }
50             Section section = null;
51             try {
52                 if (getSection() != null) {
53                     section = Section.getInstance(getSection());
54                 }
55             } catch (Exception JavaDoc e) {
56             }
57             if ("canAdminResources".equals(getAction())) {
58                 return SecurityManagerFactory.getInstance().canAdminResources(
59                     user);
60             }
61             if ("canAdminSecurity".equals(getAction())) {
62                 return SecurityManagerFactory.getInstance().canAdminSecurity(
63                     user);
64             }
65             if ("canCreatePublication".equals(getAction())) {
66                 return SecurityManagerFactory
67                     .getInstance()
68                     .canCreatePublication(
69                     section,
70                     user);
71             }
72             if ("canCreateSection".equals(getAction())) {
73                 return SecurityManagerFactory.getInstance().canCreateSection(
74                     section,
75                     user);
76             }
77             if ("canDeletePublication".equals(getAction())) {
78                 return SecurityManagerFactory
79                     .getInstance()
80                     .canDeletePublication(
81                     publication,
82                     user);
83             }
84             if ("canDeleteSection".equals(getAction())) {
85                 return SecurityManagerFactory.getInstance().canDeleteSection(
86                     section,
87                     user);
88             }
89             if ("canEditPublication".equals(getAction())) {
90                 return SecurityManagerFactory.getInstance().canEditPublication(
91                     publication, Integer.parseInt(getVersion()),
92                     user);
93             }
94             if ("canEditSection".equals(getAction())) {
95                 return SecurityManagerFactory.getInstance().canEditSection(
96                     section,
97                     user);
98             }
99         } catch (Exception JavaDoc e) {
100             e.printStackTrace();
101         } finally {
102             Mapping.rollback();
103         }
104         return false;
105     }
106
107     /**
108      * Returns the action.
109      * @return String
110      */

111     public String JavaDoc getAction() {
112         return _action;
113     }
114
115     /**
116      * Returns the publication.
117      * @return String
118      */

119     public String JavaDoc getPublication() {
120         return _publication;
121     }
122
123     /**
124      * Returns the section.
125      * @return String
126      */

127     public String JavaDoc getSection() {
128         return _section;
129     }
130
131     /**
132      * Returns the user.
133      * @return String
134      */

135     public String JavaDoc getUser() {
136         return _user;
137     }
138
139     /**
140      * Sets the action.
141      * @param action The action to set
142      */

143     public void setAction(String JavaDoc action) {
144         this._action = action;
145     }
146
147     /**
148      * Sets the publication.
149      * @param publication The publication to set
150      */

151     public void setPublication(String JavaDoc publication) {
152         this._publication = publication;
153     }
154
155     /**
156      * Sets the section.
157      * @param section The section to set
158      */

159     public void setSection(String JavaDoc section) {
160         this._section = section;
161     }
162
163     /**
164      * Sets the user.
165      * @param user The user to set
166      */

167     public void setUser(String JavaDoc user) {
168         this._user = user;
169     }
170
171     private void evaluateExpressions() throws JspException JavaDoc {
172         if (_user != null) {
173             _user =
174                 ExpressionEvaluatorManager.evaluate(
175                     "user",
176                     _user,
177                     Object JavaDoc.class,
178                     this,
179                     pageContext)
180                     + "";
181         }
182         if (_publication != null) {
183             _publication =
184                 ExpressionEvaluatorManager.evaluate(
185                     "publication",
186                     _publication,
187                     Object JavaDoc.class,
188                     this,
189                     pageContext)
190                     + "";
191         }
192         if (_section != null) {
193             _section =
194                 ExpressionEvaluatorManager.evaluate(
195                     "section",
196                     _section,
197                     Object JavaDoc.class,
198                     this,
199                     pageContext)
200                     + "";
201         }
202         if (_version != null) {
203             _version =
204                 ExpressionEvaluatorManager.evaluate(
205                     "version",
206                     _version,
207                     Object JavaDoc.class,
208                     this,
209                     pageContext)
210                     + "";
211         }
212     }
213     /**
214      * Returns the version.
215      * @return String
216      */

217     public String JavaDoc getVersion() {
218         return _version;
219     }
220
221     /**
222      * Sets the version.
223      * @param version The version to set
224      */

225     public void setVersion(String JavaDoc version) {
226         this._version = version;
227     }
228
229 }
230
Popular Tags