You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/08/30 15:51:45 UTC

[isis] branch master updated: ISIS-1895: setup the IsisSessionFilter programmatically

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 8bcb3c4  ISIS-1895: setup the IsisSessionFilter programmatically
8bcb3c4 is described below

commit 8bcb3c447c4f2c382b4daec8ebf3eab3a4534ff2
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Aug 30 17:51:40 2018 +0200

    ISIS-1895: setup the IsisSessionFilter programmatically
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1895
---
 .../apache/isis/core/webapp/IsisSessionFilter.java | 30 ++++++++++------------
 .../core/webapp/modules/WebModule_RestEasy.java    | 30 +++++++++++++++++++++-
 2 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java
index 1c7e03f..0cf4869 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java
@@ -32,8 +32,6 @@ import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.annotation.WebFilter;
-import javax.servlet.annotation.WebInitParam;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -57,20 +55,20 @@ import org.apache.isis.core.webapp.content.ResourceCachingFilter;
  * 
  * authenticate user, set up an Isis session
  */
-@WebFilter(
-        servletNames={"RestfulObjectsRestEasyDispatcher"}, // this is mapped to the entire application; 
-            // however the IsisSessionFilter will 
-            // "notice" if the session filter has already been
-            // executed for the request pipeline, and if so will do nothing
-        initParams={
-        @WebInitParam(
-                name="authenticationSessionStrategy", 
-                value="org.apache.isis.viewer.restfulobjects.server.authentication.AuthenticationSessionStrategyBasicAuth"), // authentication required for REST
-        @WebInitParam(
-                name="whenNoSession", // what to do if no session was found ...
-                value="auto"), // ... 401 and a basic authentication challenge if request originates from web browser
-        @WebInitParam(name="passThru", value="/restful/swagger") //TODO[ISIS-1895] the restful path is configured elsewhere
-})
+//@WebFilter(
+//        servletNames={"RestfulObjectsRestEasyDispatcher"}, // this is mapped to the entire application; 
+//            // however the IsisSessionFilter will 
+//            // "notice" if the session filter has already been
+//            // executed for the request pipeline, and if so will do nothing
+//        initParams={
+//        @WebInitParam(
+//                name="authenticationSessionStrategy", 
+//                value="org.apache.isis.viewer.restfulobjects.server.authentication.AuthenticationSessionStrategyBasicAuth"), // authentication required for REST
+//        @WebInitParam(
+//                name="whenNoSession", // what to do if no session was found ...
+//                value="auto"), // ... 401 and a basic authentication challenge if request originates from web browser
+//        @WebInitParam(name="passThru", value="/restful/swagger") //TODO[ISIS-1895] the restful path is configured elsewhere
+//})
 public class IsisSessionFilter implements Filter {
 
     /**
diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/modules/WebModule_RestEasy.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/modules/WebModule_RestEasy.java
index 7069461..462b6ad 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/webapp/modules/WebModule_RestEasy.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/modules/WebModule_RestEasy.java
@@ -26,10 +26,13 @@ import static org.apache.isis.commons.internal.context._Context.getDefaultClassL
 import static org.apache.isis.commons.internal.exceptions._Exceptions.unexpectedCodeReach;
 import static org.apache.isis.commons.internal.resources._Resource.putRestfulPath;
 
+import javax.servlet.FilterRegistration.Dynamic;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletException;
 
+import org.apache.isis.core.webapp.IsisSessionFilter;
+
 /**
  * Package private mixin for WebModule implementing WebModule.
  * 
@@ -74,8 +77,32 @@ final class WebModule_RestEasy implements WebModule  {
 
     @Override
     public ServletContextListener init(ServletContext ctx) throws ServletException {
+
+        // add IsisSessionFilter
+        {
+            final Dynamic filter = ctx.addFilter("IsisSessionFilterForRestfulObjects", IsisSessionFilter.class);
+
+            // this is mapped to the entire application; 
+            // however the IsisSessionFilter will 
+            // "notice" if the session filter has already been
+            // executed for the request pipeline, and if so will do nothing
+            filter.addMappingForServletNames(null, true, RESTEASY_DISPATCHER); 
+            
+            filter.setInitParameter(
+                    "authenticationSessionStrategy", 
+                    "org.apache.isis.viewer.restfulobjects.server.authentication.AuthenticationSessionStrategyBasicAuth");
+            filter.setInitParameter(
+                    "whenNoSession", // what to do if no session was found ...
+                    "auto"); // ... 401 and a basic authentication challenge if request originates from web browser
+            filter.setInitParameter(
+                    "passThru", 
+                    getRestfulPath()+"swagger"); 
+            
+        }
+
+        // add RestEasy
         
-        //  used by RestEasy to determine the JAX-RS resources and other related configuration
+        // used by RestEasy to determine the JAX-RS resources and other related configuration
         ctx.setInitParameter(
                 "javax.ws.rs.Application", 
                 "org.apache.isis.viewer.restfulobjects.server.RestfulObjectsApplication");
@@ -94,6 +121,7 @@ final class WebModule_RestEasy implements WebModule  {
             // guarded against by isAvailable()
             throw unexpectedCodeReach();
         }
+
     }
 
     @Override