You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2011/11/28 10:08:49 UTC

svn commit: r1207027 - in /incubator/isis/trunk/framework: core/webapp/src/main/java/org/apache/isis/core/webapp/content/ runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/ runtimes/dflt/webapp/src/main/java/org/apache/isis/runtim...

Author: danhaywood
Date: Mon Nov 28 09:08:47 2011
New Revision: 1207027

URL: http://svn.apache.org/viewvc?rev=1207027&view=rev
Log:
ISIS-135: refactoring the lookup of AuthenticationSessionLookupStrategy to be consistent between IsisSessionFilter and html viewer's LogonServlet; changed IsisSessionFilter so that it is a no-op if the ResourceCachingFilter says so (nb: order of filters matters in web.xml)

Added:
    incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyConstants.java
    incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyUtils.java
Modified:
    incubator/isis/trunk/framework/core/webapp/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java
    incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/IsisSessionFilter.java
    incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategy.java
    incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyDefault.java
    incubator/isis/trunk/framework/viewer/html/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/embedded/EmbeddedWebViewerJson.java

Modified: incubator/isis/trunk/framework/core/webapp/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/webapp/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java?rev=1207027&r1=1207026&r2=1207027&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/webapp/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java (original)
+++ incubator/isis/trunk/framework/core/webapp/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java Mon Nov 28 09:08:47 2011
@@ -34,6 +34,7 @@ import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 /**
@@ -74,7 +75,25 @@ import javax.servlet.http.HttpServletRes
  * </pre>
  */
 public class ResourceCachingFilter implements Filter {
-
+
+    /**
+     * Attribute set on {@link HttpServletRequest} if the filter has been applied.
+     * 
+     * <p>
+     * This is intended to inform other filters.
+     */
+    private static final String REQUEST_ATTRIBUTE = ResourceCachingFilter.class.getName() + ".resource";
+
+    /**
+     * To allow other filters to ask whether a request is mapped to the resource caching filter.
+     * 
+     * <p>
+     * For example, the <tt>IsisSessionFilter</tt> uses this in order to skip any session handling.
+     */
+    public static boolean isCachedResource(HttpServletRequest request) {
+        return request.getAttribute(REQUEST_ATTRIBUTE) != null;
+    }
+    
     /**
      * The Constant MILLISECONDS_IN_SECOND.
      */
@@ -120,7 +139,7 @@ public class ResourceCachingFilter imple
     private String[][] mReplyHeaders = { {} };
 
     /** The cache time in seconds. */
-    private Long mCacheTime = 0L;
+    private Long cacheTime = 0L;
 
     /**
      * Initializes the Servlet filter with the cache time and sets up the unchanging headers.
@@ -132,11 +151,11 @@ public class ResourceCachingFilter imple
     public void init(final FilterConfig pConfig) {
         final ArrayList<String[]> newReplyHeaders = new ArrayList<String[]>();
         String cacheTime = pConfig.getInitParameter(CACHE_TIME_PARAM_NAME);
-		this.mCacheTime = Long.parseLong(cacheTime != null? cacheTime: CACHE_TIME_PARAM_NAME_DEFAULT);
-        if (this.mCacheTime > 0L) {
-            newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, MAX_AGE_VALUE + this.mCacheTime.longValue() });
-            newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, PRE_CHECK_VALUE + this.mCacheTime.longValue() });
-            newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, POST_CHECK_VALUE + this.mCacheTime.longValue() });
+		this.cacheTime = Long.parseLong(cacheTime != null? cacheTime: CACHE_TIME_PARAM_NAME_DEFAULT);
+        if (this.cacheTime > 0L) {
+            newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, MAX_AGE_VALUE + this.cacheTime.longValue() });
+            newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, PRE_CHECK_VALUE + this.cacheTime.longValue() });
+            newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, POST_CHECK_VALUE + this.cacheTime.longValue() });
         } else {
             newReplyHeaders.add(new String[] { PRAGMA_HEADER, NO_CACHE_VALUE });
             newReplyHeaders.add(new String[] { EXPIRES_HEADER, ZERO_STRING_VALUE });
@@ -146,13 +165,16 @@ public class ResourceCachingFilter imple
         this.mReplyHeaders = new String[newReplyHeaders.size()][2];
         newReplyHeaders.toArray(this.mReplyHeaders);
     }
-
+
+    
+    
+    
     /**
      * Do filter.
      *
-     * @param pRequest the request
-     * @param pResponse the response
-     * @param pChain the chain
+     * @param servletRequest the request
+     * @param servletResponse the response
+     * @param chain the chain
      *
      * @throws IOException Signals that an I/O exception has occurred.
      * @throws ServletException the servlet exception
@@ -160,24 +182,26 @@ public class ResourceCachingFilter imple
      * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
      *      javax.servlet.FilterChain)
      */
-    public void doFilter(final ServletRequest pRequest, final ServletResponse pResponse, final FilterChain pChain)
+    public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain chain)
             throws IOException, ServletException {
         // Apply the headers
-        final HttpServletResponse httpResponse = (HttpServletResponse) pResponse;
+        final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
+        final HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
         for (final String[] replyHeader : this.mReplyHeaders) {
             final String name = replyHeader[0];
             final String value = replyHeader[1];
             httpResponse.addHeader(name, value);
         }
-        if (this.mCacheTime > 0L) {
+        if (this.cacheTime > 0L) {
             final long now = System.currentTimeMillis();
             final DateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
             httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
             httpResponse.addHeader(LAST_MODIFIED_HEADER, httpDateFormat.format(new Date(now)));
             httpResponse.addHeader(EXPIRES_HEADER, httpDateFormat.format(new Date(now
-                    + (this.mCacheTime.longValue() * MILLISECONDS_IN_SECOND))));
-        }
-        pChain.doFilter(pRequest, pResponse);
+                    + (this.cacheTime.longValue() * MILLISECONDS_IN_SECOND))));
+        }
+        httpRequest.setAttribute(REQUEST_ATTRIBUTE, true);
+        chain.doFilter(servletRequest, servletResponse);
     }
 
     /**

Modified: incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/IsisSessionFilter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/IsisSessionFilter.java?rev=1207027&r1=1207026&r2=1207027&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/IsisSessionFilter.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/IsisSessionFilter.java Mon Nov 28 09:08:47 2011
@@ -20,10 +20,6 @@
 package org.apache.isis.runtimes.dflt.webapp;
 
 import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Pattern;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -35,32 +31,16 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.factory.InstanceUtil;
 import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.webapp.content.ResourceCachingFilter;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategy;
 import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategy.Caching;
-import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyDefault;
-
-import com.google.common.base.Function;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyUtils;
 
 public class IsisSessionFilter implements Filter {
 
     /**
-     * Init parameter key to lookup implementation of {@link AuthenticationSessionLookupStrategy}.
-     */
-    public static final String AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY = "authenticationSessionLookupStrategy";
-
-    /**
-     * Default value for {@link #AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY} if not specified.
-     */
-    public static final String AUTHENTICATION_SESSION_LOOKUP_STRATEGY_DEFAULT =
-        AuthenticationSessionLookupStrategyDefault.class.getName();
-
-    /**
      * Init parameter key for (typically, a logon) page to redirect to if the {@link AuthenticationSession} cannot be
      * found or is invalid.
      */
@@ -71,20 +51,9 @@ public class IsisSessionFilter implement
      */
     public static final String CACHE_AUTH_SESSION_ON_HTTP_SESSION_KEY = "cacheAuthSessionOnHttpSession";
 
-    /**
-     * Init parameter key for which extensions should be ignored (typically, static content).
-     * 
-     * <p>
-     * The value is expected as a comma separated list, for example:
-     * <pre>css,png,js,gif</pre>
-     */
-    public static final String IGNORE_EXTENSIONS_KEY = "ignoreExtensions";
-
-    
     private AuthenticationSessionLookupStrategy authSessionLookupStrategy;
     private String logonPageIfNoSession;
     private Caching caching;
-    private Collection<Pattern> ignoreExtensions;
 
     // /////////////////////////////////////////////////////////////////
     // init, destroy
@@ -92,20 +61,11 @@ public class IsisSessionFilter implement
 
     @Override
     public void init(final FilterConfig config) throws ServletException {
-        lookupAuthenticationSessionLookupStrategy(config);
+        authSessionLookupStrategy = AuthenticationSessionLookupStrategyUtils.lookup(config);
         lookupLogonPageIfNoSessionKey(config);
         lookupCacheAuthSessionKey(config);
-        lookupIgnorePatterns(config);
     }
 
-    private void lookupAuthenticationSessionLookupStrategy(final FilterConfig config) {
-        String authLookupStrategyClassName = config.getInitParameter(AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY);
-        if (authLookupStrategyClassName == null) {
-            authLookupStrategyClassName = AUTHENTICATION_SESSION_LOOKUP_STRATEGY_DEFAULT;
-        }
-        authSessionLookupStrategy =
-            (AuthenticationSessionLookupStrategy) InstanceUtil.createInstance(authLookupStrategyClassName);
-    }
 
     private void lookupLogonPageIfNoSessionKey(final FilterConfig config) {
         logonPageIfNoSession = config.getInitParameter(LOGON_PAGE_KEY);
@@ -115,25 +75,6 @@ public class IsisSessionFilter implement
         caching = Caching.lookup(config.getInitParameter(CACHE_AUTH_SESSION_ON_HTTP_SESSION_KEY));
     }
 
-    private void lookupIgnorePatterns(final FilterConfig config) {
-        ignoreExtensions = Collections.unmodifiableCollection(parseIgnorePatterns(config));
-    }
-
-    private Collection<Pattern> parseIgnorePatterns(final FilterConfig config) {
-        final String ignoreExtensionsStr = config.getInitParameter(IGNORE_EXTENSIONS_KEY);
-        if(ignoreExtensionsStr != null) {
-            final List<String> ignoreExtensions = Lists.newArrayList(Splitter.on(",").split(ignoreExtensionsStr));
-            return Collections2.transform(ignoreExtensions, new Function<String,Pattern>() {
-                @Override
-                public Pattern apply(String input) {
-                    return Pattern.compile(".*\\." + input);
-                }
-                
-            });
-        }
-        return Lists.newArrayList();
-    }
-
     @Override
     public void destroy() {
     }
@@ -151,7 +92,7 @@ public class IsisSessionFilter implement
                 final HttpServletRequest httpRequest = (HttpServletRequest) request;
                 final HttpServletResponse httpResponse = (HttpServletResponse) response;
 
-                if(requestIsIgnoreExtension(filter, httpRequest)) {
+                if(ResourceCachingFilter.isCachedResource(httpRequest)) {
                     try {
                         chain.doFilter(request, response);
                         return;
@@ -206,21 +147,10 @@ public class IsisSessionFilter implement
                 }
             }
 
-            private boolean requestIsIgnoreExtension(IsisSessionFilter filter, HttpServletRequest httpRequest) {
-                final String servletPath = httpRequest.getServletPath();
-                for (final Pattern extension : filter.ignoreExtensions) {
-                    if(extension.matcher(servletPath).matches()) {
-                        return true;
-                    }
-                }
-                return false;
-            }
-
             private boolean requestToLogonPage(IsisSessionFilter filter, HttpServletRequest httpRequest) {
                 return filter.logonPageIfNoSession != null &&
                        filter.logonPageIfNoSession.equals(httpRequest.getServletPath());
             }
-
         },
         NO_SESSION_SINCE_REDIRECTING_TO_LOGON_PAGE,
         NO_SESSION_SINCE_NOT_AUTHENTICATED,

Modified: incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategy.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategy.java?rev=1207027&r1=1207026&r2=1207027&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategy.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategy.java Mon Nov 28 09:08:47 2011
@@ -24,6 +24,7 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpSession;
 
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
 import org.apache.isis.runtimes.dflt.webapp.IsisSessionFilter;
 
 /**
@@ -53,6 +54,9 @@ public interface AuthenticationSessionLo
         }
     }
 
+    /**
+     * Returns a {@link AuthenticationManager#isSessionValid(AuthenticationSession) still-valid} {@link AuthenticationSession}.
+     */
     AuthenticationSession lookupValid(ServletRequest servletRequest, ServletResponse servletResponse, Caching caching);
 
     void bind(ServletRequest servletRequest, ServletResponse servletResponse, AuthenticationSession authSession, Caching caching);

Added: incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyConstants.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyConstants.java?rev=1207027&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyConstants.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyConstants.java Mon Nov 28 09:08:47 2011
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.runtimes.dflt.webapp.auth;
+
+
+public class AuthenticationSessionLookupStrategyConstants {
+
+    /**
+     * Default value for {@link AuthenticationSessionLookupStrategyConstants#AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY} if not specified.
+     */
+    public static final String AUTHENTICATION_SESSION_LOOKUP_STRATEGY_DEFAULT =
+        AuthenticationSessionLookupStrategyDefault.class.getName();
+
+    /**
+     * Recommended standard init parameter key for filters and servlets to lookup an implementation of {@link AuthenticationSessionLookupStrategy}.
+     */
+    public static final String AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY = "authenticationSessionLookupStrategy";
+
+    private AuthenticationSessionLookupStrategyConstants(){}
+    
+}

Modified: incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyDefault.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyDefault.java?rev=1207027&r1=1207026&r2=1207027&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyDefault.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyDefault.java Mon Nov 28 09:08:47 2011
@@ -32,7 +32,6 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.isis.runtimes.dflt.runtime.system.IsisSystem;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.webapp.WebAppConstants;
-import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategy.Caching;
 
 /**
  * Returns a valid {@link AuthenticationSession} through a number of mechanisms.

Added: incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyUtils.java?rev=1207027&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyUtils.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/AuthenticationSessionLookupStrategyUtils.java Mon Nov 28 09:08:47 2011
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.runtimes.dflt.webapp.auth;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletConfig;
+
+import org.apache.isis.core.commons.factory.InstanceUtil;
+
+
+public final class AuthenticationSessionLookupStrategyUtils {
+    
+    private AuthenticationSessionLookupStrategyUtils(){}
+
+    public static AuthenticationSessionLookupStrategy lookup(final FilterConfig filterConfig) {
+        String authLookupStrategyClassName = filterConfig.getInitParameter(AuthenticationSessionLookupStrategyConstants.AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY);
+        return lookup(authLookupStrategyClassName);
+    }
+
+    public static AuthenticationSessionLookupStrategy lookup(final ServletConfig servletConfig) {
+        String authLookupStrategyClassName = servletConfig.getInitParameter(AuthenticationSessionLookupStrategyConstants.AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY);
+        return lookup(authLookupStrategyClassName);
+    }
+
+    private static AuthenticationSessionLookupStrategy lookup(String authLookupStrategyClassName) {
+        if (authLookupStrategyClassName == null) {
+            authLookupStrategyClassName = AuthenticationSessionLookupStrategyConstants.AUTHENTICATION_SESSION_LOOKUP_STRATEGY_DEFAULT;
+        }
+        return (AuthenticationSessionLookupStrategy) InstanceUtil.createInstance(authLookupStrategyClassName);
+    }
+
+    
+}

Modified: incubator/isis/trunk/framework/viewer/html/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/html/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java?rev=1207027&r1=1207026&r2=1207027&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/html/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java (original)
+++ incubator/isis/trunk/framework/viewer/html/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java Mon Nov 28 09:08:47 2011
@@ -33,8 +33,9 @@ import org.apache.isis.runtimes.dflt.mon
 import org.apache.isis.runtimes.dflt.runtime.authentication.exploration.AuthenticationRequestExploration;
 import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
 import org.apache.isis.runtimes.dflt.webapp.WebAppConstants;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategy;
 import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategy.Caching;
-import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyDefault;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyUtils;
 import org.apache.isis.viewer.html.component.html.HtmlComponentFactory;
 import org.apache.isis.viewer.html.component.html.LogonFormPage;
 import org.apache.isis.viewer.html.context.Context;
@@ -42,9 +43,17 @@ import org.apache.log4j.Logger;
 
 public class LogonServlet extends AbstractHtmlViewerServlet {
     
-    private static final Logger LOG = Logger.getLogger(LogonServlet.class);
     private static final long serialVersionUID = 1L;
     
+    private static final Logger LOG = Logger.getLogger(LogonServlet.class);
+    
+    private AuthenticationSessionLookupStrategy authenticationSessionLookupStrategy;
+
+    @Override
+    public void init() throws ServletException {
+        authenticationSessionLookupStrategy = AuthenticationSessionLookupStrategyUtils.lookup(getServletConfig());
+    }
+
     @Override
     protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
         IOException {
@@ -55,38 +64,52 @@ public class LogonServlet extends Abstra
     protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
         throws ServletException, IOException {
 
-        AuthenticationSession authSession = new AuthenticationSessionLookupStrategyDefault().lookupValid(request, response, Caching.CACHE);
-        if (authSession != null) {
-            final boolean sessionValid = getAuthenticationManager().isSessionValid(authSession);
-            if (sessionValid) {
-                loggedIn(response, authSession.getUserName());
-                return;
-            }
+        // existing valid session
+        AuthenticationSession existingAuthSession = authenticationSessionLookupStrategy.lookupValid(request, response, Caching.CACHE);
+        if (existingAuthSession != null) {
+            redirectToStartPage(response, existingAuthSession.getUserName());
+            return;
         }
 
+        // prompt
         final String user = request.getParameter("username");
         final String password = request.getParameter("password");
-
         if (user == null && !getDeploymentType().isExploring()) {
-            prompt(response, "", "", "");
+            renderPrompt(response, "", "", "");
             return;
         }
 
-        authSession = authenticate(user, password);
+        // authenticate; re-prompt if required
+        final AuthenticationSession authSession = authenticate(user, password);
         if (authSession == null) {
-            prompt(response, user, password, "error");
+            renderPrompt(response, user, password, "error");
             return;
         }
 
-        final HttpSession httpSession = request.getSession(true);
-        httpSession.setAttribute(WebAppConstants.HTTP_SESSION_AUTHENTICATION_SESSION_KEY, authSession);
+        // authenticated
+        authenticationSessionLookupStrategy.bind(request, response, authSession, Caching.CACHE);
 
         final Context context = new Context(new HtmlComponentFactory(getHtmlViewerContext()));
         context.setSession(authSession);
         authSession.setAttribute(HtmlServletConstants.AUTHENTICATION_SESSION_CONTEXT_KEY, context);
 
-        LOG.info("created session: " + httpSession);
-        loggedIn(response, user);
+        LOG.info("created session");
+        redirectToStartPage(response, user);
+    }
+
+    private void redirectToStartPage(final HttpServletResponse response, final String user) throws IOException {
+        Monitor.addEvent("Web", "Logon - " + user);
+        response.sendRedirect(pathTo(HtmlServletConstants.START_PAGE));
+    }
+
+    private void renderPrompt(
+            final HttpServletResponse response, 
+            final String user, final String password,
+            final String message) throws IOException {
+        response.setContentType("text/html");
+        final HtmlComponentFactory factory = new HtmlComponentFactory(getHtmlViewerContext());
+        final LogonFormPage page = factory.createLogonPage(user, password);
+        page.write(response.getWriter());
     }
 
     private AuthenticationSession authenticate(final String user, final String password) {
@@ -99,17 +122,5 @@ public class LogonServlet extends Abstra
         return getAuthenticationManager().authenticate(request);
     }
 
-    private void prompt(final HttpServletResponse response, final String user, final String password,
-        final String message) throws IOException {
-        response.setContentType("text/html");
-        final HtmlComponentFactory factory = new HtmlComponentFactory(getHtmlViewerContext());
-        final LogonFormPage page = factory.createLogonPage(user, password);
-        page.write(response.getWriter());
-    }
-
-    private void loggedIn(final HttpServletResponse response, final String user) throws IOException {
-        Monitor.addEvent("Web", "Logon - " + user);
-        response.sendRedirect(pathTo(HtmlServletConstants.START_PAGE));
-    }
 
 }

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/embedded/EmbeddedWebViewerJson.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/embedded/EmbeddedWebViewerJson.java?rev=1207027&r1=1207026&r2=1207027&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/embedded/EmbeddedWebViewerJson.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/embedded/EmbeddedWebViewerJson.java Mon Nov 28 09:08:47 2011
@@ -24,6 +24,7 @@ import org.apache.isis.core.webapp.conte
 import org.apache.isis.runtimes.dflt.runtime.viewer.web.WebAppSpecification;
 import org.apache.isis.runtimes.dflt.runtime.web.EmbeddedWebViewer;
 import org.apache.isis.runtimes.dflt.webapp.IsisSessionFilter;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyConstants;
 import org.apache.isis.viewer.json.viewer.JsonApplication;
 import org.apache.isis.viewer.json.viewer.authentication.AuthenticationSessionLookupStrategyTrusted;
 import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
@@ -41,7 +42,7 @@ final class EmbeddedWebViewerJson extend
         webAppSpec.addServletContextListener(ResteasyBootstrap.class);
 
         webAppSpec.addFilterSpecification(IsisSessionFilter.class, MapUtils.asMap(
-            IsisSessionFilter.AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY,
+            AuthenticationSessionLookupStrategyConstants.AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY,
             AuthenticationSessionLookupStrategyTrusted.class.getName()), JsonViewerInstaller.EVERYTHING);
         webAppSpec.addServletSpecification(HttpServletDispatcher.class, JsonViewerInstaller.ROOT);