1 23 24 package org.infoglue.cms.security.interceptors; 25 26 import java.util.Map ; 27 28 import org.apache.log4j.Logger; 29 import org.exolab.castor.jdo.Database; 30 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController; 31 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 32 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionControllerProxy; 33 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController; 34 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionControllerProxy; 35 import org.infoglue.cms.entities.content.ContentVO; 36 import org.infoglue.cms.entities.content.ContentVersionVO; 37 import org.infoglue.cms.entities.management.InterceptionPointVO; 38 import org.infoglue.cms.entities.structure.SiteNodeVersion; 39 import org.infoglue.cms.entities.structure.SiteNodeVersionVO; 40 import org.infoglue.cms.exception.AccessConstraintException; 41 import org.infoglue.cms.exception.ConstraintException; 42 import org.infoglue.cms.exception.SystemException; 43 import org.infoglue.cms.security.InfoGluePrincipal; 44 import org.infoglue.cms.util.AccessConstraintExceptionBuffer; 45 46 47 53 54 public class InfoGlueCommonAccessRightsInterceptor implements InfoGlueInterceptor 55 { 56 private final static Logger logger = Logger.getLogger(InfoGlueCommonAccessRightsInterceptor.class.getName()); 57 58 66 67 public void intercept(InfoGluePrincipal infoGluePrincipal, InterceptionPointVO interceptionPointVO, Map extradata) throws ConstraintException, SystemException, Exception 68 { 69 logger.info("interceptionPointVO:" + interceptionPointVO.getName()); 70 71 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 72 73 if(interceptionPointVO.getName().equalsIgnoreCase("Content.Read")) 74 { 75 Integer contentId = (Integer )extradata.get("contentId"); 76 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 77 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 78 { 79 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 80 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Read", protectedContentId.toString())) 81 ceb.add(new AccessConstraintException("Content.contentId", "1000")); 82 } 83 } 84 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Write")) 85 { 86 Integer contentId = (Integer )extradata.get("contentId"); 87 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 88 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 89 { 90 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 91 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Write", protectedContentId.toString())) 92 ceb.add(new AccessConstraintException("Content.contentId", "1001")); 93 } 94 } 95 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Create")) 96 { 97 Integer contentId = (Integer )extradata.get("contentId"); 98 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 99 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 100 { 101 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 102 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Create", protectedContentId.toString())) 103 ceb.add(new AccessConstraintException("Content.contentId", "1002")); 104 } 105 } 106 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Delete")) 107 { 108 Integer contentId = (Integer )extradata.get("contentId"); 109 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 110 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 111 { 112 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 113 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Delete", protectedContentId.toString())) 114 ceb.add(new AccessConstraintException("Content.contentId", "1003")); 115 } 116 } 117 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Move")) 118 { 119 Integer contentId = (Integer )extradata.get("contentId"); 120 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 121 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 122 { 123 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 124 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Move", protectedContentId.toString())) 125 ceb.add(new AccessConstraintException("Content.contentId", "1004")); 126 } 127 } 128 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.CreateVersion")) 129 { 130 Integer contentId = (Integer )extradata.get("contentId"); 131 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 132 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 133 { 134 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 135 if(ContentVersionControllerProxy.getController().getIsContentProtected(contentId, true) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.CreateVersion", protectedContentId.toString())) 136 ceb.add(new AccessConstraintException("Content.contentId", "1002")); 137 } 138 } 139 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.SubmitToPublish")) 140 { 141 Integer contentId = (Integer )extradata.get("contentId"); 142 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 143 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 144 { 145 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 146 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.SubmitToPublish", protectedContentId.toString())) 147 ceb.add(new AccessConstraintException("Content.contentId", "1005")); 148 } 149 } 150 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.ChangeAccessRights")) 151 { 152 Integer contentId = (Integer )extradata.get("contentId"); 153 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 154 if(!contentVO.getCreatorName().equalsIgnoreCase(infoGluePrincipal.getName())) 155 { 156 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId); 157 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.ChangeAccessRights", protectedContentId.toString())) 158 ceb.add(new AccessConstraintException("Content.contentId", "1006")); 159 } 160 } 161 else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Read")) 162 { 163 Integer contentVersionId = (Integer )extradata.get("contentVersionId"); 164 ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId); 165 if(!contentVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 166 { 167 if(ContentVersionControllerProxy.getController().getIsContentProtected(contentVersionVO.getContentId(), false) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "ContentVersion.Read", contentVersionId.toString())) 168 { 169 ceb.add(new AccessConstraintException("ContentVersion.contentVersionId", "1000")); 170 } 171 else 172 { 173 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentVersionVO.getContentId()); 174 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Read", protectedContentId.toString())) 175 ceb.add(new AccessConstraintException("Content.contentId", "1000")); 176 } 177 } 178 } 179 else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Write")) 180 { 181 Integer contentVersionId = (Integer )extradata.get("contentVersionId"); 182 ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId); 183 if(!contentVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 184 { 185 if(ContentVersionControllerProxy.getController().getIsContentProtected(contentVersionVO.getContentId(), false) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "ContentVersion.Write", contentVersionId.toString())) 186 { 187 ceb.add(new AccessConstraintException("ContentVersion.contentVersionId", "1001")); 188 } 189 else 190 { 191 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentVersionVO.getContentId()); 192 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Write", protectedContentId.toString())) 193 ceb.add(new AccessConstraintException("Content.contentId", "1001")); 194 } 195 } 196 } 197 else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Delete")) 198 { 199 Integer contentVersionId = (Integer )extradata.get("contentVersionId"); 200 ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId); 201 if(!contentVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 202 { 203 if(ContentVersionControllerProxy.getController().getIsContentProtected(contentVersionVO.getContentId(), false) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "ContentVersion.Delete", contentVersionId.toString())) 204 ceb.add(new AccessConstraintException("ContentVersion.contentVersionId", "1003")); 205 } 206 } 207 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Read")) 208 { 209 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 210 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 211 if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 212 { 213 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId); 214 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString())) 215 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeVersionId", "1000")); 216 } 217 } 218 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Write")) 219 { 220 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 221 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 222 if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 223 { 224 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId); 225 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.Write", protectedSiteNodeVersionId.toString())) 226 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeVersionId", "1001")); 227 } 228 } 229 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.CreateSiteNode")) 230 { 231 Integer parentSiteNodeId = (Integer )extradata.get("siteNodeId"); 232 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(parentSiteNodeId); 233 if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 234 { 235 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionVO.getId()); 236 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.CreateSiteNode", siteNodeVersionVO.getSiteNodeVersionId().toString())) 237 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1002")); 238 } 239 } 240 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.DeleteSiteNode")) 241 { 242 Integer siteNodeId = (Integer )extradata.get("siteNodeId"); 243 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(siteNodeId); 244 if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 245 { 246 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionVO.getId()); 247 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.DeleteSiteNode", protectedSiteNodeVersionId.toString())) 248 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1003")); 249 } 250 } 251 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.MoveSiteNode")) 252 { 253 Integer siteNodeId = (Integer )extradata.get("siteNodeId"); 254 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(siteNodeId); 255 if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 256 { 257 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionVO.getId()); 258 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.MoveSiteNode", protectedSiteNodeVersionId.toString())) 259 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1004")); 260 } 261 } 262 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.SubmitToPublish")) 263 { 264 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 265 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 266 if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 267 { 268 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId); 269 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.SubmitToPublish", protectedSiteNodeVersionId.toString())) 270 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1005")); 271 } 272 } 273 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.ChangeAccessRights")) 274 { 275 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 276 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 277 if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 278 { 279 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId); 280 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.ChangeAccessRights", protectedSiteNodeVersionId.toString())) 281 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1006")); 282 } 283 } 284 285 ceb.throwIfNotEmpty(); 286 } 287 288 289 297 298 public void intercept(InfoGluePrincipal infoGluePrincipal, InterceptionPointVO interceptionPointVO, Map extradata, Database db) throws ConstraintException, SystemException, Exception 299 { 300 logger.info("interceptionPointVO:" + interceptionPointVO.getName()); 301 302 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 303 304 if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Read")) 394 { 395 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 396 SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithId(siteNodeVersionId, db); 397 if(!siteNodeVersion.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 398 { 399 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId, db); 400 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString())) 401 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeVersionId", "1000")); 402 } 403 } 404 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Write")) 405 { 406 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 407 SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithId(siteNodeVersionId, db); 408 if(!siteNodeVersion.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 409 { 410 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId, db); 411 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "SiteNodeVersion.Write", protectedSiteNodeVersionId.toString())) 412 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeVersionId", "1001")); 413 } 414 } 415 416 ceb.throwIfNotEmpty(); 417 } 418 } 419 | Popular Tags |