| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ksb.messaging.web; |
| 17 | |
|
| 18 | |
|
| 19 | |
import java.util.HashMap; |
| 20 | |
import java.util.Iterator; |
| 21 | |
import java.util.Map; |
| 22 | |
|
| 23 | |
import javax.servlet.http.HttpServletRequest; |
| 24 | |
import javax.servlet.http.HttpServletResponse; |
| 25 | |
|
| 26 | |
import org.apache.struts.action.ActionErrors; |
| 27 | |
import org.apache.struts.action.ActionForm; |
| 28 | |
import org.apache.struts.action.ActionForward; |
| 29 | |
import org.apache.struts.action.ActionMapping; |
| 30 | |
import org.apache.struts.action.ActionMessages; |
| 31 | |
import org.apache.struts.actions.DispatchAction; |
| 32 | |
import org.kuali.rice.kew.web.session.UserSession; |
| 33 | |
import org.kuali.rice.kim.bo.Person; |
| 34 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
| 35 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
| 36 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 37 | |
import org.kuali.rice.kim.util.KimCommonUtils; |
| 38 | |
import org.kuali.rice.kim.util.KimConstants; |
| 39 | |
import org.kuali.rice.kns.exception.AuthorizationException; |
| 40 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 41 | |
import org.kuali.rice.kns.service.KualiModuleService; |
| 42 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | 0 | public abstract class KSBAction extends DispatchAction { |
| 51 | |
|
| 52 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KSBAction.class); |
| 53 | |
|
| 54 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 55 | |
|
| 56 | 0 | checkAuthorization(form, ""); |
| 57 | |
|
| 58 | |
try { |
| 59 | |
|
| 60 | |
|
| 61 | 0 | ActionMessages messages = null; |
| 62 | 0 | messages = establishRequiredState(request, form); |
| 63 | 0 | if (messages != null && !messages.isEmpty()) { |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | 0 | if (messages instanceof ActionErrors) { |
| 72 | 0 | saveErrors(request, (ActionErrors) messages); |
| 73 | |
} else { |
| 74 | 0 | saveMessages(request, messages); |
| 75 | |
} |
| 76 | 0 | return mapping.findForward("requiredStateError"); |
| 77 | |
} |
| 78 | 0 | LOG.info(request.getQueryString()); |
| 79 | 0 | ActionForward returnForward = null; |
| 80 | |
|
| 81 | 0 | if (request.getParameterMap() != null) { |
| 82 | 0 | for (Iterator iter = request.getParameterMap().entrySet().iterator(); iter.hasNext();) { |
| 83 | 0 | String parameterName = (String) ((Map.Entry) iter.next()).getKey(); |
| 84 | 0 | if (parameterName.startsWith("methodToCall.") && parameterName.endsWith(".x")) { |
| 85 | 0 | String methodToCall = parameterName.substring(parameterName.indexOf("methodToCall.") + 13, parameterName.lastIndexOf(".x")); |
| 86 | 0 | if (methodToCall != null && methodToCall.length() > 0) { |
| 87 | 0 | returnForward = this.dispatchMethod(mapping, form, request, response, methodToCall); |
| 88 | |
} |
| 89 | |
} |
| 90 | 0 | } |
| 91 | |
} |
| 92 | 0 | if (returnForward == null) { |
| 93 | 0 | if (request.getParameter("methodToCall") != null && !"".equals(request.getParameter("methodToCall")) && !"execute".equals(request.getParameter("methodToCall"))) { |
| 94 | 0 | LOG.info("dispatch to methodToCall " + request.getParameter("methodToCall") + " called"); |
| 95 | 0 | returnForward = super.execute(mapping, form, request, response); |
| 96 | |
} else { |
| 97 | 0 | LOG.info("dispatch to default start methodToCall"); |
| 98 | 0 | returnForward = start(mapping, form, request, response); |
| 99 | |
} |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | 0 | messages = establishFinalState(request, form); |
| 105 | 0 | if (messages != null && !messages.isEmpty()) { |
| 106 | 0 | saveMessages(request, messages); |
| 107 | 0 | return mapping.findForward("finalStateError"); |
| 108 | |
} |
| 109 | 0 | return returnForward; |
| 110 | 0 | } catch (Exception e) { |
| 111 | 0 | LOG.error("Error processing action " + mapping.getPath(), e); |
| 112 | 0 | throw new RuntimeException(e); |
| 113 | |
} |
| 114 | |
} |
| 115 | |
|
| 116 | |
protected void checkAuthorization( ActionForm form, String methodToCall) throws AuthorizationException |
| 117 | |
{ |
| 118 | 0 | String principalId = UserSession.getAuthenticatedUser().getPrincipalId(); |
| 119 | 0 | AttributeSet roleQualifier = new AttributeSet(getRoleQualification(form, methodToCall)); |
| 120 | 0 | AttributeSet permissionDetails = KimCommonUtils.getNamespaceAndActionClass(this.getClass()); |
| 121 | |
|
| 122 | 0 | if (!KIMServiceLocator.getIdentityManagementService().isAuthorizedByTemplateName(principalId, KNSConstants.KNS_NAMESPACE, |
| 123 | |
KimConstants.PermissionTemplateNames.USE_SCREEN, permissionDetails, roleQualifier )) |
| 124 | |
{ |
| 125 | 0 | throw new AuthorizationException(UserSession.getAuthenticatedUser().getPrincipalName(), |
| 126 | |
methodToCall, |
| 127 | |
this.getClass().getSimpleName()); |
| 128 | |
} |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
protected Map<String,String> getRoleQualification(ActionForm form, String methodToCall) { |
| 135 | 0 | return new HashMap<String,String>(); |
| 136 | |
} |
| 137 | |
|
| 138 | |
public abstract ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception; |
| 139 | |
|
| 140 | |
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 141 | 0 | return start(mapping, form, request, response); |
| 142 | |
} |
| 143 | |
|
| 144 | |
public abstract ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception; |
| 145 | |
|
| 146 | |
public ActionMessages establishFinalState(HttpServletRequest request, ActionForm form) throws Exception { |
| 147 | 0 | return null; |
| 148 | |
} |
| 149 | |
|
| 150 | |
public ActionForward noOp(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 151 | 0 | return mapping.findForward("basic"); |
| 152 | |
} |
| 153 | |
|
| 154 | |
protected static KualiModuleService getKualiModuleService() { |
| 155 | 0 | return KNSServiceLocator.getKualiModuleService(); |
| 156 | |
} |
| 157 | |
|
| 158 | |
} |