1 package org.nextime.ion.backoffice.security; 2 3 import javax.servlet.jsp.JspException ; 4 import javax.servlet.jsp.tagext.TagSupport ; 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 { 14 15 protected String _action; 16 protected String _publication; 17 protected String _version; 18 protected String _section; 19 protected String _user; 20 21 public int doStartTag() throws JspException { 22 evaluateExpressions(); 23 if (check()) 24 return (EVAL_BODY_INCLUDE); 25 else 26 return (SKIP_BODY); 27 } 28 29 public int doEndTag() throws JspException { 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 e) { 42 } 43 Publication publication = null; 44 try { 45 if (getPublication() != null) { 46 publication = Publication.getInstance(getPublication()); 47 } 48 } catch (Exception e) { 49 } 50 Section section = null; 51 try { 52 if (getSection() != null) { 53 section = Section.getInstance(getSection()); 54 } 55 } catch (Exception 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 e) { 100 e.printStackTrace(); 101 } finally { 102 Mapping.rollback(); 103 } 104 return false; 105 } 106 107 111 public String getAction() { 112 return _action; 113 } 114 115 119 public String getPublication() { 120 return _publication; 121 } 122 123 127 public String getSection() { 128 return _section; 129 } 130 131 135 public String getUser() { 136 return _user; 137 } 138 139 143 public void setAction(String action) { 144 this._action = action; 145 } 146 147 151 public void setPublication(String publication) { 152 this._publication = publication; 153 } 154 155 159 public void setSection(String section) { 160 this._section = section; 161 } 162 163 167 public void setUser(String user) { 168 this._user = user; 169 } 170 171 private void evaluateExpressions() throws JspException { 172 if (_user != null) { 173 _user = 174 ExpressionEvaluatorManager.evaluate( 175 "user", 176 _user, 177 Object .class, 178 this, 179 pageContext) 180 + ""; 181 } 182 if (_publication != null) { 183 _publication = 184 ExpressionEvaluatorManager.evaluate( 185 "publication", 186 _publication, 187 Object .class, 188 this, 189 pageContext) 190 + ""; 191 } 192 if (_section != null) { 193 _section = 194 ExpressionEvaluatorManager.evaluate( 195 "section", 196 _section, 197 Object .class, 198 this, 199 pageContext) 200 + ""; 201 } 202 if (_version != null) { 203 _version = 204 ExpressionEvaluatorManager.evaluate( 205 "version", 206 _version, 207 Object .class, 208 this, 209 pageContext) 210 + ""; 211 } 212 } 213 217 public String getVersion() { 218 return _version; 219 } 220 221 225 public void setVersion(String version) { 226 this._version = version; 227 } 228 229 } 230 | Popular Tags |