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/26 11:29:05 UTC
svn commit: r1206423 - in /incubator/isis/trunk/framework:
runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/
runtimes/dflt/webapp/src/main/java/org/apache/isis/runtimes/dflt/webapp/auth/
viewer/json/json-applib/src/main/java/org/...
Author: danhaywood
Date: Sat Nov 26 10:29:02 2011
New Revision: 1206423
URL: http://svn.apache.org/viewvc?rev=1206423&view=rev
Log:
ISIS-136: work on json viewer to allow it to co-exist with html viewer in a single webapp
Added:
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyHeader.java
Modified:
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/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyParams.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyTrusted.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.java
incubator/isis/trunk/framework/viewer/json/src/docbkx/guide/isis-json-viewer.xml
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=1206423&r1=1206422&r2=1206423&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 Sat Nov 26 10:29:02 2011
@@ -29,12 +29,14 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
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.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;
public class IsisSessionFilter implements Filter {
@@ -56,8 +58,16 @@ public class IsisSessionFilter implement
*/
public static final String LOGON_PAGE_KEY = "logonPage";
+ /**
+ * Init parameter key for whether the authentication session may be cached on the HttpSession.
+ */
+ public static final String CACHE_AUTH_SESSION_ON_HTTP_SESSION_KEY = "cacheAuthSessionOnHttpSession";
+
+
private AuthenticationSessionLookupStrategy authSessionLookupStrategy;
private String logonPageIfNoSession;
+
+ private Caching caching;
// /////////////////////////////////////////////////////////////////
// init, destroy
@@ -66,7 +76,8 @@ public class IsisSessionFilter implement
@Override
public void init(final FilterConfig config) throws ServletException {
lookupAuthenticationSessionLookupStrategy(config);
- lookupRedirectIfNoSessionKey(config);
+ lookupLogonPageIfNoSessionKey(config);
+ lookupCacheAuthSessionKey(config);
}
private void lookupAuthenticationSessionLookupStrategy(final FilterConfig config) {
@@ -78,10 +89,14 @@ public class IsisSessionFilter implement
(AuthenticationSessionLookupStrategy) InstanceUtil.createInstance(authLookupStrategyClassName);
}
- private void lookupRedirectIfNoSessionKey(final FilterConfig config) {
+ private void lookupLogonPageIfNoSessionKey(final FilterConfig config) {
logonPageIfNoSession = config.getInitParameter(LOGON_PAGE_KEY);
}
+ private void lookupCacheAuthSessionKey(final FilterConfig config) {
+ caching = Caching.lookup(config.getInitParameter(CACHE_AUTH_SESSION_ON_HTTP_SESSION_KEY));
+ }
+
@Override
public void destroy() {
}
@@ -90,51 +105,112 @@ public class IsisSessionFilter implement
// doFilter
// /////////////////////////////////////////////////////////////////
- @Override
- public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
- throws IOException, ServletException {
-
- final HttpServletRequest httpRequest = (HttpServletRequest) request;
- final HttpServletResponse httpResponse = (HttpServletResponse) response;
+ public enum SessionState {
+
+ UNDEFINED {
+ @Override
+ public void handle(IsisSessionFilter filter, ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+
+ final HttpServletRequest httpRequest = (HttpServletRequest) request;
+ final HttpServletResponse httpResponse = (HttpServletResponse) response;
+
+ // request is to logon page
+ if (requestToLogonPage(filter, httpRequest)) {
+ NO_SESSION_SINCE_REDIRECTING_TO_LOGON_PAGE.setOn(request);
+ try {
+ chain.doFilter(request, response);
+ return;
+ } finally {
+ UNDEFINED.setOn(request);
+ closeSession();
+ }
+ }
- // forward/redirect as required
- final AuthenticationSession authSession = authSessionLookupStrategy.lookup(request, response);
- if (!isValid(authSession)) {
- if (logonPageIfNoSession != null
- && !logonPageIfNoSession.equals(httpRequest.getServletPath())) {
- httpResponse.sendRedirect(logonPageIfNoSession);
- } else {
+ // authenticate
+ final AuthenticationSession validSession = filter.authSessionLookupStrategy.lookupValid(request, response, filter.caching);
+ if (validSession != null) {
+ filter.authSessionLookupStrategy.bind(request, response, validSession, filter.caching);
+
+ openSession(validSession);
+ SESSION_IN_PROGRESS.setOn(request);
+ try {
+ chain.doFilter(request, response);
+ } finally {
+ UNDEFINED.setOn(request);
+ closeSession();
+ }
+ return;
+ }
+
+ // redirect to logon page (if there is one)
+ if (filter.logonPageIfNoSession != null) {
+ // no need to set state, since not proceeding along the filter chain
+ httpResponse.sendRedirect(filter.logonPageIfNoSession);
+ return;
+ }
+
// the destination servlet is expected to know that there
// will be no open context
try {
+ NO_SESSION_SINCE_NOT_AUTHENTICATED.setOn(request);
chain.doFilter(request, response);
} finally {
+ UNDEFINED.setOn(request);
// nothing to do
}
}
- } else {
- // else, is authenticated so open session
- authSessionLookupStrategy.bind(request, response, authSession);
- IsisContext.openSession(authSession);
- try {
- chain.doFilter(request, response);
- } finally {
- IsisContext.closeSession();
+ 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,
+ SESSION_IN_PROGRESS;
+
+ static SessionState lookup(ServletRequest request) {
+ final Object state = request.getAttribute(SESSION_STATE_KEY);
+ return state != null ? (SessionState)state : SessionState.UNDEFINED;
}
- }
- private boolean isValid(final AuthenticationSession authSession) {
- return authSession != null && getAuthenticationManager().isSessionValid(authSession);
- }
- // /////////////////////////////////////////////////////////////////
- // Dependencies (from context)
- // /////////////////////////////////////////////////////////////////
+ boolean isValid(final AuthenticationSession authSession) {
+ return authSession != null && getAuthenticationManager().isSessionValid(authSession);
+ }
+
+ void setOn(ServletRequest request) {
+ request.setAttribute(SESSION_STATE_KEY, this);
+ }
+
+ public void handle(IsisSessionFilter filter, ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+ chain.doFilter(request, response);
+ }
+
+ AuthenticationManager getAuthenticationManager() {
+ return IsisContext.getAuthenticationManager();
+ }
+
+ void openSession(final AuthenticationSession authSession) {
+ IsisContext.openSession(authSession);
+ }
+
+ void closeSession() {
+ IsisContext.closeSession();
+ }
+
+ }
+
+ static final String SESSION_STATE_KEY = IsisSessionFilter.SessionState.class.getName();
- private static AuthenticationManager getAuthenticationManager() {
- return IsisContext.getAuthenticationManager();
+ @Override
+ public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
+ throws IOException, ServletException {
+
+ SessionState sessionState = SessionState.lookup(request);
+ sessionState.handle(this, request, response, chain);
}
+
}
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=1206423&r1=1206422&r2=1206423&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 Sat Nov 26 10:29:02 2011
@@ -21,6 +21,7 @@ package org.apache.isis.runtimes.dflt.we
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpSession;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.runtimes.dflt.webapp.IsisSessionFilter;
@@ -30,7 +31,24 @@ import org.apache.isis.runtimes.dflt.web
*/
public interface AuthenticationSessionLookupStrategy {
- AuthenticationSession lookup(ServletRequest servletRequest, ServletResponse servletResponse);
+ /**
+ * Whether the {@link AuthenticationSession}, if just authenticated,
+ * should be cached on the {@link HttpSession}.
+ */
+ public enum Caching {
+ CACHE,
+ NO_CACHE;
+
+ public static Caching lookup(String booleanStr) {
+ return Boolean.parseBoolean(booleanStr)? CACHE: NO_CACHE;
+ }
- void bind(ServletRequest servletRequest, ServletResponse servletResponse, AuthenticationSession authSession);
+ public boolean isEnabled() {
+ return this == CACHE;
+ }
+ }
+
+ AuthenticationSession lookupValid(ServletRequest servletRequest, ServletResponse servletResponse, Caching caching);
+
+ void bind(ServletRequest servletRequest, ServletResponse servletResponse, AuthenticationSession authSession, Caching caching);
}
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=1206423&r1=1206422&r2=1206423&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 Sat Nov 26 10:29:02 2011
@@ -32,6 +32,7 @@ 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.
@@ -52,16 +53,20 @@ import org.apache.isis.runtimes.dflt.web
public class AuthenticationSessionLookupStrategyDefault extends AuthenticationSessionLookupStrategyAbstract {
@Override
- public AuthenticationSession lookup(final ServletRequest servletRequest, final ServletResponse servletResponse) {
+ public AuthenticationSession lookupValid(final ServletRequest servletRequest, final ServletResponse servletResponse, Caching caching) {
- // use previously authenticated session if available.
+ final AuthenticationManager authenticationManager = getAuthenticationManager();
final HttpSession httpSession = getHttpSession(servletRequest);
- AuthenticationSession authSession =
- (AuthenticationSession) httpSession.getAttribute(WebAppConstants.HTTP_SESSION_AUTHENTICATION_SESSION_KEY);
- if (authSession != null) {
- final boolean sessionValid = getAuthenticationManager().isSessionValid(authSession);
- if (sessionValid) {
- return authSession;
+
+ // use previously authenticated session if available and caching enabled
+ AuthenticationSession authSession = null;
+ if(caching.isEnabled()) {
+ authSession = (AuthenticationSession) httpSession.getAttribute(WebAppConstants.HTTP_SESSION_AUTHENTICATION_SESSION_KEY);
+ if (authSession != null) {
+ final boolean sessionValid = authenticationManager.isSessionValid(authSession);
+ if (sessionValid) {
+ return authSession;
+ }
}
}
@@ -76,7 +81,7 @@ public class AuthenticationSessionLookup
// see if exploration is supported
if (system.getDeploymentType().isExploring()) {
- authSession = getAuthenticationManager().authenticate(new AuthenticationRequestExploration(logonFixture));
+ authSession = authenticationManager.authenticate(new AuthenticationRequestExploration(logonFixture));
if (authSession != null) {
return authSession;
}
@@ -86,15 +91,18 @@ public class AuthenticationSessionLookup
httpSession.getAttribute(WebAppConstants.HTTP_SESSION_LOGGED_ON_PREVIOUSLY_USING_LOGON_FIXTURE_KEY) != null;
if (logonFixture != null && !loggedInUsingLogonFixture) {
httpSession.setAttribute(WebAppConstants.HTTP_SESSION_LOGGED_ON_PREVIOUSLY_USING_LOGON_FIXTURE_KEY, true);
- return getAuthenticationManager().authenticate(new AuthenticationRequestLogonFixture(logonFixture));
+ return authenticationManager.authenticate(new AuthenticationRequestLogonFixture(logonFixture));
}
return null;
}
@Override
- public void bind(final ServletRequest servletRequest, final ServletResponse servletResponse,
- final AuthenticationSession authSession) {
+ public void bind(final ServletRequest servletRequest, final ServletResponse servletResponse, final AuthenticationSession authSession, Caching caching) {
+ // no-op if no caching.
+ if(caching == Caching.NO_CACHE) {
+ return;
+ }
final HttpSession httpSession = getHttpSession(servletRequest);
httpSession.setAttribute(WebAppConstants.HTTP_SESSION_AUTHENTICATION_SESSION_KEY, authSession);
}
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java?rev=1206423&r1=1206422&r2=1206423&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java Sat Nov 26 10:29:02 2011
@@ -48,8 +48,7 @@ import com.google.common.collect.Maps;
/**
- * A wrapper around {@link JsonNode} that provides some additional helper
- * methods, including searching using xpath (requires optional XOM dependency).
+ * A wrapper around {@link JsonNode} that provides some additional helper methods.
*/
public class JsonRepresentation {
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java?rev=1206423&r1=1206422&r2=1206423&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java Sat Nov 26 10:29:02 2011
@@ -34,5 +34,16 @@ public interface HomePageResource {
@Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_HOME_PAGE })
@ClientResponseType(entityType=String.class)
public Response homePage();
+
+
+ /**
+ * Not part of the RO spec; this resource always returns 401, and is intended to be redirected to
+ * if credentials cannot be obtained.
+ */
+ @GET
+ @Path("/notAuthenticated")
+ @Produces({ MediaType.APPLICATION_JSON })
+ @ClientResponseType(entityType=String.class)
+ public Response notAuthenticated();
}
\ No newline at end of file
Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyHeader.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyHeader.java?rev=1206423&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyHeader.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyHeader.java Sat Nov 26 10:29:02 2011
@@ -0,0 +1,58 @@
+/*
+ * 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.viewer.json.viewer.authentication;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.runtime.authentication.standard.SimpleSession;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyDefault;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+
+public class AuthenticationSessionLookupStrategyHeader extends AuthenticationSessionLookupStrategyDefault {
+
+ @Override
+ public AuthenticationSession lookupValid(final ServletRequest servletRequest, final ServletResponse servletResponse, Caching caching) {
+
+ final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+ final String user = httpServletRequest.getHeader("isis.user");
+ final List<String> roles = rolesFrom(httpServletRequest);
+
+ if (Strings.isNullOrEmpty(user)) {
+ return null;
+ }
+ return new SimpleSession(user, roles);
+ }
+
+ protected List<String> rolesFrom(final HttpServletRequest httpServletRequest) {
+ final String rolesStr = httpServletRequest.getHeader("isis.roles");
+ if(rolesStr == null) {
+ return Collections.emptyList();
+ }
+ return Lists.newArrayList(Splitter.on(",").split(rolesStr));
+ }
+}
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyParams.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyParams.java?rev=1206423&r1=1206422&r2=1206423&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyParams.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyParams.java Sat Nov 26 10:29:02 2011
@@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletReq
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.runtime.authentication.AuthenticationRequestPassword;
import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategy.Caching;
import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyDefault;
import com.google.common.base.Strings;
@@ -32,8 +33,8 @@ import com.google.common.base.Strings;
public class AuthenticationSessionLookupStrategyParams extends AuthenticationSessionLookupStrategyDefault {
@Override
- public AuthenticationSession lookup(final ServletRequest servletRequest, final ServletResponse servletResponse) {
- final AuthenticationSession session = super.lookup(servletRequest, servletResponse);
+ public AuthenticationSession lookupValid(final ServletRequest servletRequest, final ServletResponse servletResponse, Caching caching) {
+ final AuthenticationSession session = super.lookupValid(servletRequest, servletResponse, caching);
if (session != null) {
return session;
}
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyTrusted.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyTrusted.java?rev=1206423&r1=1206422&r2=1206423&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyTrusted.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/authentication/AuthenticationSessionLookupStrategyTrusted.java Sat Nov 26 10:29:02 2011
@@ -24,13 +24,14 @@ import javax.servlet.ServletResponse;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.runtimes.dflt.runtime.authentication.exploration.AuthenticationRequestExploration;
import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategy.Caching;
import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyDefault;
public class AuthenticationSessionLookupStrategyTrusted extends AuthenticationSessionLookupStrategyDefault {
@Override
- public AuthenticationSession lookup(final ServletRequest servletRequest, final ServletResponse servletResponse) {
- final AuthenticationSession session = super.lookup(servletRequest, servletResponse);
+ public AuthenticationSession lookupValid(final ServletRequest servletRequest, final ServletResponse servletResponse, Caching caching) {
+ final AuthenticationSession session = super.lookupValid(servletRequest, servletResponse, caching);
if (session != null) {
return session;
}
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java?rev=1206423&r1=1206422&r2=1206423&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java Sat Nov 26 10:29:02 2011
@@ -110,17 +110,21 @@ public abstract class ResourceAbstract {
private ResourceContext resourceContext;
-
+
+ protected void init() {
+ init(RepresentationType.GENERIC);
+ }
protected void init(RepresentationType representationType) {
+ if(!IsisContext.inSession() || getAuthenticationSession() == null) {
+ throw JsonApplicationException.create(HttpStatusCode.UNAUTHORIZED);
+ }
+
this.resourceContext =
new ResourceContext(representationType, httpHeaders, uriInfo, request, httpServletRequest, httpServletResponse,
securityContext, getOidStringifier(), getLocalization(), getAuthenticationSession(), getPersistenceSession(), getAdapterManager(), getSpecificationLoader());
}
- protected void init() {
- init(RepresentationType.GENERIC);
- }
protected ResourceContext getResourceContext() {
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.java?rev=1206423&r1=1206422&r2=1206423&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.java Sat Nov 26 10:29:02 2011
@@ -19,14 +19,18 @@
package org.apache.isis.viewer.json.viewer.resources.home;
+import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.isis.viewer.json.applib.JsonRepresentation;
import org.apache.isis.viewer.json.applib.RepresentationType;
import org.apache.isis.viewer.json.applib.RestfulMediaType;
+import org.apache.isis.viewer.json.applib.RestfulResponse.HttpStatusCode;
import org.apache.isis.viewer.json.applib.homepage.HomePageResource;
+import org.apache.isis.viewer.json.viewer.JsonApplicationException;
import org.apache.isis.viewer.json.viewer.representations.RendererFactory;
import org.apache.isis.viewer.json.viewer.resources.ResourceAbstract;
@@ -50,4 +54,13 @@ public class HomePageResourceServerside
return responseOfOk(renderer, Caching.ONE_DAY).build();
}
+ @Override
+ @GET
+ @Path("/notAuthenticated")
+ @Produces({ MediaType.APPLICATION_JSON } )
+ public Response notAuthenticated() {
+
+ throw JsonApplicationException.create(HttpStatusCode.UNAUTHORIZED);
+ }
+
}
\ No newline at end of file
Modified: incubator/isis/trunk/framework/viewer/json/src/docbkx/guide/isis-json-viewer.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/src/docbkx/guide/isis-json-viewer.xml?rev=1206423&r1=1206422&r2=1206423&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/src/docbkx/guide/isis-json-viewer.xml (original)
+++ incubator/isis/trunk/framework/viewer/json/src/docbkx/guide/isis-json-viewer.xml Sat Nov 26 10:29:02 2011
@@ -235,11 +235,59 @@
<sect1 id="sec.IntroducingRestfulObjects">
<title>The JSON viewer as an RO implementation</title>
- <para></para>
+ <para><emphasis>Restful Objects</emphasis> defines a core set of
+ functionality that all implementations must honour, and also defines a
+ set of capabilities which may be optionally implemented. Implementations
+ indicate the functionality that they support through (the representation
+ of the) "version" resource, specificially the "optionalCapabilities"
+ property map.</para>
- <para>* capabilites</para>
+ <para>As such, the <emphasis>json viewer</emphasis> returns the
+ following representation:</para>
- <para></para>
+ <para><programlisting>** TODO</programlisting></para>
+
+ <para>See the <emphasis>Restful Objects</emphasis> spec for details on
+ each of these capabilities.</para>
+ </sect1>
+
+ <sect1>
+ <title>The JSON viewer modules</title>
+
+ <para>In terms of software, the <emphasis>json viewer</emphasis>
+ comprises a number of Maven modules:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>org.apache.isis.viewer.json</para>
+
+ <para>is the parent module; this also has the site and documentation
+ (this guide)</para>
+ </listitem>
+
+ <listitem>
+ <para>org.apache.isis.viewer.json-applib</para>
+
+ <para>is a client-side library to simplify the task of writing
+ Java-based applications that consume <emphasis>Restful
+ Objects</emphasis> representations</para>
+ </listitem>
+
+ <listitem>
+ <para>org.apache.isis.viewer.json-viewer</para>
+
+ <para>is the server-side implementation of the resources and
+ representations defined by the <emphasis>Restful Objects</emphasis>
+ spec.</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>It isn't mandatory to use the client-side library when writing
+ applications; one could equally write a pure Javascript application, for
+ example. However, the client-side library is worth checking out for
+ Java-based applications, for example in an integration scenario. There
+ is further coverage of its API in <xref
+ linkend="chp.WritingClientSideApps" />.</para>
</sect1>
</chapter>
@@ -264,21 +312,21 @@
<emphasis>Isis</emphasis> quickstart archetype (eg as documented on
<emphasis>Isis</emphasis>' website). Once you've done this, you'll end up
with an set of modules that allow the application to be booted using the
- <emphasis>xhtml viewer</emphasis>. It includes the following
+ <emphasis>json viewer</emphasis>. It includes the following
modules:</para>
<programlisting>myapp/pom.xml
myapp-dom/pom.xml # domain object model
myapp-fixture/pom.xml # fixtures for seeding object store
myapp-objstore-dflt/pom.xml # repository implementations for the default object store
- myapp-quickrun/pom.xml # run the application during development/prototyping
- myapp-viewer-restful/pom.xml # run the application as a webapp using the xhtml viewer</programlisting>
+ myapp-viewer-html/pom.xml # run the application as a webapp using the HTML viewer
+ myapp-viewer-json/pom.xml # run the application as a webapp using the JSON viewer</programlisting>
<para>where 'myapp' is the artifactId specified when you ran the <code>mvn
archetype:generate</code> goal.</para>
<para>This chapter describes in more detail the contents of these modules,
- and then describes how to get started with running the <emphasis>xhtml
+ and then describes how to get started with running the <emphasis>json
viewer</emphasis> for prototyping purposes.</para>
<sect1 id="sec.ParentModule">
@@ -750,11 +798,11 @@ mvn jetty:run</programlisting>
</chapter>
<chapter id="chp.WritingClientSideApps">
- <title>Writing Client-side Applications</title>
+ <title>The JSON Viewer AppLib</title>
<abstract>
<para>How to write custom client-side applications to consume the
- RESTful resources.</para>
+ RESTful resources using the json-viewer's applib.</para>
</abstract>
<para>The point of the <emphasis>json viewer</emphasis> is to provide our
@@ -1060,4 +1108,51 @@ mvn jetty:run</programlisting>
</note></para>
</sect1>
</chapter>
+
+ <chapter>
+ <title>web.xml</title>
+
+ <para></para>
+
+ <para></para>
+
+ <para></para>
+
+ <para></para>
+
+ <sect1>
+ <title></title>
+
+ <para></para>
+
+ <sect2>
+ <title>Reading HTML viewer specific properties</title>
+
+ <para></para>
+
+ <para></para>
+
+ <programlisting><web.xml>
+ ...
+ <context-param>
+ <param-name>isis.viewers</param-name>
+ <param-value>json</param-value>
+ </context-param>
+ ...
+</web.xml></programlisting>
+
+ <para>This will cause the viewer_json.properties file to be read if it
+ is present.</para>
+
+ <para></para>
+
+ <para></para>
+
+ <para>NB: the value for this parameter is actually comma-separated, to
+ allow for multiple viewers to be configured in the same webapp.</para>
+
+ <para></para>
+ </sect2>
+ </sect1>
+ </chapter>
</book>