1 package org.infoglue.cms.util.workflow; 2 3 import java.util.Iterator ; 4 import java.util.List ; 5 import java.util.Map ; 6 7 import org.apache.log4j.Logger; 8 import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy; 9 import org.infoglue.cms.security.InfoGluePrincipal; 10 import org.infoglue.cms.security.InfoGlueRole; 11 12 import com.opensymphony.module.propertyset.PropertySet; 13 import com.opensymphony.workflow.Condition; 14 import com.opensymphony.workflow.WorkflowContext; 15 16 21 22 public class InfoGlueAuthorizationCondition implements Condition 23 { 24 private final static Logger logger = Logger.getLogger(InfoGlueAuthorizationCondition.class.getName()); 25 26 public boolean passesCondition(Map transientVars, Map args, PropertySet ps) 27 { 28 boolean passesCondition = true; 29 30 try 31 { 32 WorkflowContext context = (WorkflowContext) transientVars.get("context"); 33 String roleName = (String )args.get("roleName"); 34 String userName = (String )args.get("userName"); 35 36 logger.info("passesCondition............."); 37 logger.info("caller:" + context.getCaller()); 38 logger.info("roleName:" + roleName); 39 logger.info("userName:" + userName); 40 41 InfoGluePrincipal principal = UserControllerProxy.getController().getUser(context.getCaller()); 42 43 if(userName != null && userName.length() > 0 && !principal.getName().equals(userName)) 44 passesCondition = false; 45 46 if(roleName != null && roleName.length() > 0) 47 { 48 boolean hasRole = false; 49 List roles = principal.getRoles(); 50 Iterator rolesIterator = roles.iterator(); 51 while(rolesIterator.hasNext()) 52 { 53 InfoGlueRole role = (InfoGlueRole)rolesIterator.next(); 54 if(role.getName().equalsIgnoreCase(roleName)) 55 hasRole = true; 56 } 57 58 if(!hasRole) 59 passesCondition = false; 60 } 61 } 62 catch (Exception e) 63 { 64 logger.error("A severe error occurred when checking workflow authorization:" + e.getMessage(), e); 65 } 66 67 return passesCondition; 68 } 69 } | Popular Tags |