roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghu...@apache.org
Subject svn commit: r1589956 - in /roller/trunk/app/src/main: java/org/apache/roller/weblogger/ui/struts2/util/ resources/
Date Fri, 25 Apr 2014 08:59:52 GMT
Author: ghuber
Date: Fri Apr 25 08:59:52 2014
New Revision: 1589956

URL: http://svn.apache.org/r1589956
Log:
Do not call our Interceptors on cancel redirects.

Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionPrepareInterceptor.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
    roller/trunk/app/src/main/resources/struts.xml

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java?rev=1589956&r1=1589955&r2=1589956&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
Fri Apr 25 08:59:52 2014
@@ -18,10 +18,8 @@
 
 package org.apache.roller.weblogger.ui.struts2.util;
 
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
 import javax.servlet.http.HttpServletRequest;
+
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -30,54 +28,64 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.ui.core.RollerSession;
 import org.apache.struts2.StrutsStatics;
 
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
 
 /**
  * A struts2 interceptor for configuring specifics of the weblogger ui.
  */
-public class UIActionInterceptor extends AbstractInterceptor 
-        implements StrutsStatics {
-    
+public class UIActionInterceptor extends MethodFilterInterceptor implements
+        StrutsStatics {
+
+    private static final long serialVersionUID = -6452966127207525616L;
     private static Log log = LogFactory.getLog(UIActionInterceptor.class);
-    
-    
-    public String intercept(ActionInvocation invocation) throws Exception {
-        
-        log.debug("Entering UIActionInterceptor");
-        
+
+    public String doIntercept(ActionInvocation invocation) throws Exception {
+
+        if (log.isDebugEnabled()) {
+            log.debug("Entering UIActionInterceptor");
+        }
+
         final Object action = invocation.getAction();
         final ActionContext context = invocation.getInvocationContext();
-        
-        HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
-        
+
+        HttpServletRequest request = (HttpServletRequest) context
+                .get(HTTP_REQUEST);
+
         // is this one of our own UIAction classes?
         if (action instanceof UIAction) {
-            
-            log.debug("action is a UIAction, setting relevant attributes");
-            
+
+            if (log.isDebugEnabled()) {
+                log.debug("action is a UIAction, setting relevant attributes");
+            }
+
             UIAction theAction = (UIAction) action;
-            
+
             // extract the authenticated user and set it
             RollerSession rses = RollerSession.getRollerSession(request);
-            if(rses != null) {
+            if (rses != null) {
                 theAction.setAuthenticatedUser(rses.getAuthenticatedUser());
             }
-            
+
             // extract the work weblog and set it
             String weblogHandle = theAction.getWeblog();
-            if(!StringUtils.isEmpty(weblogHandle)) {
+            if (!StringUtils.isEmpty(weblogHandle)) {
                 Weblog weblog = null;
                 try {
-                    weblog = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogByHandle(weblogHandle);
-                    if(weblog != null) {
+                    weblog = WebloggerFactory.getWeblogger().getWeblogManager()
+                            .getWeblogByHandle(weblogHandle);
+                    if (weblog != null) {
                         theAction.setActionWeblog(weblog);
                     }
-                } catch(Exception e) {
-                    log.error("Error looking up action weblog - "+weblogHandle, e);
+                } catch (Exception e) {
+                    log.error("Error looking up action weblog - "
+                            + weblogHandle, e);
                 }
             }
         }
-        
+
         return invocation.invoke();
     }
-    
+
 }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionPrepareInterceptor.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionPrepareInterceptor.java?rev=1589956&r1=1589955&r2=1589956&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionPrepareInterceptor.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionPrepareInterceptor.java
Fri Apr 25 08:59:52 2014
@@ -32,44 +32,48 @@ import com.opensymphony.xwork2.intercept
  */
 public class UIActionPrepareInterceptor extends MethodFilterInterceptor {
 
-	private static final long serialVersionUID = 7770184756145702592L;
-	private static Log log = LogFactory
-			.getLog(UIActionPrepareInterceptor.class);
-
-	public String doIntercept(ActionInvocation invocation) throws Exception {
-
-		log.debug("Entering UIActionPrepareInterceptor");
-
-		final Object action = invocation.getAction();
-		//final ActionContext context = invocation.getInvocationContext();
-
-		// is this one of our own UIAction classes?
-		if (action instanceof UIActionPreparable) {
-
-			log.debug("action is UIActionPreparable, calling myPrepare() method");
-
-			// The EntryAdd->EntryEdit chain is the one place where we need
-			// to pass a parameter along the chain, thus this somewhat ugly hack
-			if (invocation.getStack().getRoot().size() > 1) {
-				Object action0 = invocation.getStack().getRoot().get(0);
-				Object action1 = invocation.getStack().getRoot().get(1);
-				if (action0 instanceof EntryEdit && action1 instanceof EntryAdd) {
-					EntryEdit editAction = (EntryEdit) action0;
-					EntryAdd addAction = (EntryAdd) action1;
-					editAction.getBean().setId(addAction.getBean().getId());
-				} else if (action0 instanceof EntryAdd
-						&& action1 instanceof EntryAddWithMediaFile) {
-					EntryAdd addAction = (EntryAdd) action0;
-					EntryAddWithMediaFile mediaAction = (EntryAddWithMediaFile) action1;
-					addAction.setBean(mediaAction.getBean());
-				}
-			}
-
-			UIActionPreparable theAction = (UIActionPreparable) action;
-			theAction.myPrepare();
-		}
+    private static final long serialVersionUID = 7770184756145702592L;
+    private static Log log = LogFactory
+            .getLog(UIActionPrepareInterceptor.class);
+
+    public String doIntercept(ActionInvocation invocation) throws Exception {
+
+        if (log.isDebugEnabled()) {
+            log.debug("Entering UIActionPrepareInterceptor");
+        }
+
+        final Object action = invocation.getAction();
+        // final ActionContext context = invocation.getInvocationContext();
+
+        // is this one of our own UIAction classes?
+        if (action instanceof UIActionPreparable) {
+
+            if (log.isDebugEnabled()) {
+                log.debug("action is UIActionPreparable, calling myPrepare() method");
+            }
+
+            // The EntryAdd->EntryEdit chain is the one place where we need
+            // to pass a parameter along the chain, thus this somewhat ugly hack
+            if (invocation.getStack().getRoot().size() > 1) {
+                Object action0 = invocation.getStack().getRoot().get(0);
+                Object action1 = invocation.getStack().getRoot().get(1);
+                if (action0 instanceof EntryEdit && action1 instanceof EntryAdd)
{
+                    EntryEdit editAction = (EntryEdit) action0;
+                    EntryAdd addAction = (EntryAdd) action1;
+                    editAction.getBean().setId(addAction.getBean().getId());
+                } else if (action0 instanceof EntryAdd
+                        && action1 instanceof EntryAddWithMediaFile) {
+                    EntryAdd addAction = (EntryAdd) action0;
+                    EntryAddWithMediaFile mediaAction = (EntryAddWithMediaFile) action1;
+                    addAction.setBean(mediaAction.getBean());
+                }
+            }
+
+            UIActionPreparable theAction = (UIActionPreparable) action;
+            theAction.myPrepare();
+        }
 
-		return invocation.invoke();
-	}
+        return invocation.invoke();
+    }
 
 }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java?rev=1589956&r1=1589955&r2=1589956&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
Fri Apr 25 08:59:52 2014
@@ -18,8 +18,6 @@
 
 package org.apache.roller.weblogger.ui.struts2.util;
 
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.business.UserManager;
@@ -29,78 +27,99 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.pojos.WeblogPermission;
 
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
 
 /**
  * A struts2 interceptor for configuring specifics of the weblogger ui.
  */
-public class UISecurityInterceptor extends AbstractInterceptor {
-    
+public class UISecurityInterceptor extends MethodFilterInterceptor {
+
+    private static final long serialVersionUID = -7787813271277874462L;
     private static Log log = LogFactory.getLog(UISecurityInterceptor.class);
-    
-    
-    public String intercept(ActionInvocation invocation) throws Exception {
-        
-        log.debug("Entering UISecurityInterceptor");
-        
+
+    public String doIntercept(ActionInvocation invocation) throws Exception {
+
+        if (log.isDebugEnabled()) {
+            log.debug("Entering UISecurityInterceptor");
+        }
+
         final Object action = invocation.getAction();
-        
+
         // is this one of our own UIAction classes?
-        if (action instanceof UISecurityEnforced &&
-                action instanceof UIAction) {
-            
-            log.debug("action is UISecurityEnforced ... enforcing security rules");
-            
+        if (action instanceof UISecurityEnforced && action instanceof UIAction) {
+
+            if (log.isDebugEnabled()) {
+                log.debug("action is UISecurityEnforced ... enforcing security rules");
+            }
+
             final UISecurityEnforced theAction = (UISecurityEnforced) action;
-            
+
             // are we requiring an authenticated user?
             if (theAction.isUserRequired()) {
-                
-                UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
-                
-                User authenticatedUser = ((UIAction)theAction).getAuthenticatedUser();
-                if(authenticatedUser == null) {
-                    log.debug("DENIED: required user not found");
+
+                UserManager umgr = WebloggerFactory.getWeblogger()
+                        .getUserManager();
+
+                User authenticatedUser = ((UIAction) theAction)
+                        .getAuthenticatedUser();
+                if (authenticatedUser == null) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("DENIED: required user not found");
+                    }
                     return "access-denied";
                 }
-                
+
                 // are we also enforcing global permissions?
-                if (theAction.requiredGlobalPermissionActions() != null 
-                        && !theAction.requiredGlobalPermissionActions().isEmpty())
{
-                    GlobalPermission perm = new GlobalPermission(theAction.requiredGlobalPermissionActions());
+                if (theAction.requiredGlobalPermissionActions() != null
+                        && !theAction.requiredGlobalPermissionActions()
+                                .isEmpty()) {
+                    GlobalPermission perm = new GlobalPermission(
+                            theAction.requiredGlobalPermissionActions());
                     if (!umgr.checkPermission(perm, authenticatedUser)) {
-                        log.debug("DENIED: user does not have permission = " + perm.toString());
+                        if (log.isDebugEnabled()) {
+                            log.debug("DENIED: user does not have permission = "
+                                    + perm.toString());
+                        }
                         return "access-denied";
                     }
                 }
-                
+
                 // are we requiring a valid action weblog?
                 if (theAction.isWeblogRequired()) {
-                    
-                    Weblog actionWeblog = ((UIAction)theAction).getActionWeblog();
-                    if(actionWeblog == null) {
-                        log.debug("DENIED: required action weblog not found");
+
+                    Weblog actionWeblog = ((UIAction) theAction)
+                            .getActionWeblog();
+                    if (actionWeblog == null) {
+                        if (log.isDebugEnabled()) {
+                            log.debug("DENIED: required action weblog not found");
+                        }
                         return "access-denied";
                     }
-                    
+
                     // are we also enforcing a specific weblog permission?
-                    if (theAction.requiredWeblogPermissionActions() != null 
-                            && !theAction.requiredWeblogPermissionActions().isEmpty())
{                        
+                    if (theAction.requiredWeblogPermissionActions() != null
+                            && !theAction.requiredWeblogPermissionActions()
+                                    .isEmpty()) {
                         WeblogPermission required = new WeblogPermission(
-                                actionWeblog,  
+                                actionWeblog,
                                 theAction.requiredWeblogPermissionActions());
-                        
+
                         if (!umgr.checkPermission(required, authenticatedUser)) {
-                            log.debug("DENIED: user does not have required weblog permissions
= "+required);
+                            if (log.isDebugEnabled()) {
+                                log.debug("DENIED: user does not have required weblog permissions
= "
+                                        + required);
+                            }
                             return "access-denied";
                         }
                     }
                 }
-                
+
             }
-            
+
         }
-        
+
         return invocation.invoke();
     }
-    
+
 }

Modified: roller/trunk/app/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/struts.xml?rev=1589956&r1=1589955&r2=1589956&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/struts.xml (original)
+++ roller/trunk/app/src/main/resources/struts.xml Fri Apr 25 08:59:52 2014
@@ -47,10 +47,14 @@
                 <interceptor-ref name="conversionError"/>
                 
                 <!-- custom Roller interceptors -->
-                <interceptor-ref name="UIActionInterceptor"/>
-                <interceptor-ref name="UISecurityInterceptor"/>
+                <interceptor-ref name="UIActionInterceptor">
+                    <param name="excludeMethods">cancel</param>
+                </interceptor-ref>
+                <interceptor-ref name="UISecurityInterceptor">
+                    <param name="excludeMethods">cancel</param>
+                </interceptor-ref>
                 <interceptor-ref name="UIActionPrepareInterceptor">
-                    <param name="excludeMethods">input,back,cancel,browse</param>
+                    <param name="excludeMethods">cancel</param>
                 </interceptor-ref>
                 
                 <!-- validation interceptors, MUST come after our custom interceptors
-->



Mime
View raw message