1 23 24 package org.infoglue.cms.security.interceptors; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import org.apache.log4j.Logger; 30 import org.exolab.castor.jdo.Database; 31 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController; 32 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionControllerProxy; 34 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController; 35 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionControllerProxy; 36 import org.infoglue.cms.entities.content.ContentVO; 37 import org.infoglue.cms.entities.content.ContentVersionVO; 38 import org.infoglue.cms.entities.management.InterceptionPointVO; 39 import org.infoglue.cms.entities.structure.SiteNodeVersion; 40 import org.infoglue.cms.entities.structure.SiteNodeVersionVO; 41 import org.infoglue.cms.exception.AccessConstraintException; 42 import org.infoglue.cms.exception.ConstraintException; 43 import org.infoglue.cms.exception.SystemException; 44 import org.infoglue.cms.security.InfoGluePrincipal; 45 import org.infoglue.cms.util.AccessConstraintExceptionBuffer; 46 47 import com.opensymphony.workflow.Workflow; 48 import com.opensymphony.workflow.basic.BasicWorkflow; 49 import com.opensymphony.workflow.loader.WorkflowDescriptor; 50 51 56 57 public class InfoGlueOSWorkflowInterceptor implements InfoGlueInterceptor 58 { 59 private final static Logger logger = Logger.getLogger(InfoGlueOSWorkflowInterceptor.class.getName()); 60 61 69 70 public void intercept(InfoGluePrincipal infoGluePrincipal, InterceptionPointVO interceptionPointVO, Map extradata) throws ConstraintException, SystemException, Exception 71 { 72 logger.info("interceptionPointVO:" + interceptionPointVO.getName()); 73 74 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 75 76 try 77 { 78 Workflow workflowInit = new BasicWorkflow(infoGluePrincipal.getName()); 79 80 long id = workflowInit.initialize("MattiasWF", 1, new HashMap ()); 81 logger.info("Workflow initialized...."); 82 logger.info("id:" + id); 83 logger.info("name:" + workflowInit.getWorkflowName(id)); 84 85 86 Workflow workflow = workflowInit; 88 int[] actions = workflow.getAvailableActions(id, null); 89 logger.info("actions:" + actions.length); 90 WorkflowDescriptor wd = workflow.getWorkflowDescriptor(workflow.getWorkflowName(id)); 91 92 for (int i = 0; i < actions.length; i++) 93 { 94 int availableActionId = actions[i]; 95 String name = wd.getAction(availableActionId).getName(); 96 logger.info("Action:" + availableActionId + ":" + name); 97 98 } 100 101 Map map = new HashMap (); 102 map.put("userName", "Mattias"); 103 workflow.doAction(id, 1, map); 104 105 actions = workflow.getAvailableActions(id, null); 106 logger.info("actions:" + actions.length); 107 wd = workflow.getWorkflowDescriptor(workflow.getWorkflowName(id)); 108 109 for (int i = 0; i < actions.length; i++) 110 { 111 int availableActionId = actions[i]; 112 String name = wd.getAction(availableActionId).getName(); 113 logger.info("Action:" + availableActionId + ":" + name); 114 115 } 117 118 123 133 } 134 catch(Throwable t) 135 { 136 t.printStackTrace(); 137 } 138 139 if(interceptionPointVO.getName().equalsIgnoreCase("Content.Read")) 140 { 141 Integer contentId = (Integer )extradata.get("contentId"); 142 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 143 144 } 145 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Write")) 146 { 147 Integer contentId = (Integer )extradata.get("contentId"); 148 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 149 150 } 151 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Create")) 152 { 153 Integer contentId = (Integer )extradata.get("contentId"); 154 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 155 156 } 157 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Delete")) 158 { 159 Integer contentId = (Integer )extradata.get("contentId"); 160 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 161 162 } 163 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Move")) 164 { 165 Integer contentId = (Integer )extradata.get("contentId"); 166 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 167 168 } 169 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.CreateVersion")) 170 { 171 Integer contentId = (Integer )extradata.get("contentId"); 172 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 173 174 } 175 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.SubmitToPublish")) 176 { 177 Integer contentId = (Integer )extradata.get("contentId"); 178 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 179 180 } 181 else if(interceptionPointVO.getName().equalsIgnoreCase("Content.ChangeAccessRights")) 182 { 183 Integer contentId = (Integer )extradata.get("contentId"); 184 ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId); 185 186 } 187 else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Read")) 188 { 189 Integer contentVersionId = (Integer )extradata.get("contentVersionId"); 190 ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId); 191 192 } 193 else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Write")) 194 { 195 Integer contentVersionId = (Integer )extradata.get("contentVersionId"); 196 ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId); 197 198 } 199 else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Delete")) 200 { 201 Integer contentVersionId = (Integer )extradata.get("contentVersionId"); 202 ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId); 203 204 } 205 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Read")) 206 { 207 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 208 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 209 210 } 211 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Write")) 212 { 213 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 214 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 215 216 } 217 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.CreateSiteNode")) 218 { 219 Integer parentSiteNodeId = (Integer )extradata.get("siteNodeId"); 220 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(parentSiteNodeId); 221 222 } 223 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.DeleteSiteNode")) 224 { 225 Integer siteNodeId = (Integer )extradata.get("siteNodeId"); 226 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(siteNodeId); 227 228 } 229 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.MoveSiteNode")) 230 { 231 Integer siteNodeId = (Integer )extradata.get("siteNodeId"); 232 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(siteNodeId); 233 234 } 235 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.SubmitToPublish")) 236 { 237 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 238 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 239 240 } 241 else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.ChangeAccessRights")) 242 { 243 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 244 SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 245 246 } 247 248 ceb.throwIfNotEmpty(); 249 } 250 251 252 260 261 public void intercept(InfoGluePrincipal infoGluePrincipal, InterceptionPointVO interceptionPointVO, Map extradata, Database db) throws ConstraintException, SystemException, Exception 262 { 263 logger.info("interceptionPointVO:" + interceptionPointVO.getName()); 264 265 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 266 267 if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Write")) 357 { 358 logger.info("******************************************************"); 359 logger.info("SiteNodeVersion.ChangeAccessRights"); 360 Integer siteNodeVersionId = (Integer )extradata.get("siteNodeVersionId"); 361 SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithId(siteNodeVersionId, db); 362 logger.info("VersionModifier:" + siteNodeVersion.getVersionModifier()); 363 logger.info("infoGluePrincipal:" + infoGluePrincipal.getName()); 364 if(!siteNodeVersion.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName())) 365 { 366 Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId, db); 367 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "SiteNodeVersion.Write", siteNodeVersionId.toString())) 368 ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeVersionId", "1001")); 369 } 370 } 371 372 ceb.throwIfNotEmpty(); 373 } 374 } 375 | Popular Tags |