diff --git a/samples/portlet/pom.xml b/samples/portlet/pom.xml new file mode 100644 index 0000000000..abc7b89914 --- /dev/null +++ b/samples/portlet/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + + org.springframework.security + spring-security-samples + 2.0-SNAPSHOT + + org.springframework.security + spring-security-samples-portlet + Spring Security - Portlet Sample + war + + + org.springframework.security + spring-security-core + ${project.version} + + + org.springframework.security + spring-security-portlet + ${project.version} + + + portlet-api + portlet-api + 1.0 + provided + + + javax.servlet + servlet-api + 2.4 + provided + + + org.springframework + spring + ${spring.version} + + + org.springframework + spring-portlet + ${spring.version} + + + org.springframework + spring-mock + ${spring.version} + test + + + + javax.servlet + jstl + ${jstl.version} + + + taglibs + standard + ${jstl.version} + + + org.apache.commons + commons-io + 1.3.2 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + diff --git a/samples/portlet/src/main/java/org/springframework/web/portlet/sample/SecurityContextPortlet.java b/samples/portlet/src/main/java/org/springframework/web/portlet/sample/SecurityContextPortlet.java new file mode 100644 index 0000000000..ca37c3d213 --- /dev/null +++ b/samples/portlet/src/main/java/org/springframework/web/portlet/sample/SecurityContextPortlet.java @@ -0,0 +1,41 @@ +package org.springframework.web.portlet.sample; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; + +import javax.portlet.GenericPortlet; +import javax.portlet.PortletException; +import javax.portlet.PortletSession; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import org.springframework.security.context.SecurityContextHolder; +import org.springframework.security.ui.AbstractProcessingFilter; + + +/** + * A simple portlet which prints out the contents of the current {@link SecurityContext} + * + * @author Luke Taylor + */ +public class SecurityContextPortlet extends GenericPortlet { + + public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println("

Security Context Display Portlet

"); + out.println("

"); + out.println(new Date()); + out.println("

Current Session " + request.getPortletSession().getId() + "

"); + out.println("

"); + out.println("

The security context contains: " + + SecurityContextHolder.getContext().getAuthentication() + + "

"); + Object lastException = request.getPortletSession().getAttribute(AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY, PortletSession.APPLICATION_SCOPE); + + if (lastException != null) { + out.println("Last Exception: " + lastException); + } + } +} diff --git a/samples/portlet/src/main/resources/applicationContext.xml b/samples/portlet/src/main/resources/applicationContext.xml new file mode 100644 index 0000000000..f9dd69c3ed --- /dev/null +++ b/samples/portlet/src/main/resources/applicationContext.xml @@ -0,0 +1,35 @@ + + + + + + + + + messages + + + + + + + + + + + + + + + + + + notAuthorized + notAvailable + + + + + diff --git a/samples/portlet/src/main/resources/log4j.properties b/samples/portlet/src/main/resources/log4j.properties new file mode 100644 index 0000000000..9abc2b829b --- /dev/null +++ b/samples/portlet/src/main/resources/log4j.properties @@ -0,0 +1,19 @@ +#log4j.debug=TRUE + +#log4j.rootLogger=FATAL, stdout +#log4j.rootLogger=ERROR, stdout +log4j.rootLogger=WARN, stdout +#log4j.rootLogger=INFO, stdout +#log4j.rootLogger=DEBUG, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n + +# spring portlet mvc classes +log4j.logger.org.springframework.web.portlet=INFO + +# spring portlet mvc sample classes +log4j.logger.org.springframework.web.portlet.sample=DEBUG + +log4j.logger.org.springframework.security=DEBUG \ No newline at end of file diff --git a/samples/portlet/src/main/resources/messages.properties b/samples/portlet/src/main/resources/messages.properties new file mode 100644 index 0000000000..b1742329c5 --- /dev/null +++ b/samples/portlet/src/main/resources/messages.properties @@ -0,0 +1,23 @@ + +required=Required +required.java.util.Date=A date of the form 'MM/dd/yyyy' is required + +typeMismatch=Invalid Data Entry +typeMismatch.java.lang.Integer=Must be a number +typeMismatch.java.util.Date=Must be of the form 'MM/dd/yyyy' + +button.home=Home +button.edit=Edit + +exception.generalError.title=General Error + +exception.notAuthorized.title=Access Not Permitted +exception.notAuthorized.message=You do not have permission to access this area. + +exception.notAvailable.title=Resource Not Available +exception.notAvailable.message=That resource is not available. + +exception.contactAdmin=Please contact your System Administrator for assistance. + +portlet.exceptions.title=Sample Exceptions +portlet.exceptions.message=This portlet lets you see what uncaught exceptions will look like in your portlet. Select one of the exceptions below in order to throw it. diff --git a/samples/portlet/src/main/resources/messages_de.properties b/samples/portlet/src/main/resources/messages_de.properties new file mode 100644 index 0000000000..3194b66f1f --- /dev/null +++ b/samples/portlet/src/main/resources/messages_de.properties @@ -0,0 +1,15 @@ + +# Apologies to those fluent in German -- these translations are straight from BabelFish and are only for demonstration purposes. + +exception.generalError.title=Allgemeine Störung + +exception.notAuthorized.title=Zugang Nicht Die Erlaubnis Gehabt +exception.notAuthorized.message=Sie haben nicht Erlaubnis, diesen Bereich zugänglich zu machen. + +exception.notAvailable.title=Hilfsmittel Nicht Vorhanden +exception.notAvailable.message=Dieses Hilfsmittel ist nicht vorhanden. + +exception.contactAdmin=Treten Sie bitte mit Ihrem Systemverwalter für Unterstützung in Verbindung. + +portlet.exceptions.title=Beispielausnahmen +portlet.exceptions.message=Dieses portlet läßt Sie sehen, welche uncaught Ausnahmen wie in Ihrem portlet aussehen. Wählen Sie eine der Ausnahmen unten vor, um sie zu werfen. diff --git a/samples/portlet/src/main/resources/portlet/securityContextPortlet.xml b/samples/portlet/src/main/resources/portlet/securityContextPortlet.xml new file mode 100644 index 0000000000..eca0ef7525 --- /dev/null +++ b/samples/portlet/src/main/resources/portlet/securityContextPortlet.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tomcat + admin + manager + + Administrator + Guest + User + Power User + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/portlet/src/main/webapp/WEB-INF/jsp/defError.jsp b/samples/portlet/src/main/webapp/WEB-INF/jsp/defError.jsp new file mode 100644 index 0000000000..d38febcc7a --- /dev/null +++ b/samples/portlet/src/main/webapp/WEB-INF/jsp/defError.jsp @@ -0,0 +1,10 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + +

+ +

${exception.localizedMessage == null ? exception : exception.localizedMessage }
+

+ +

${exception.class}

+ +

">- -

diff --git a/samples/portlet/src/main/webapp/WEB-INF/jsp/include.jsp b/samples/portlet/src/main/webapp/WEB-INF/jsp/include.jsp new file mode 100644 index 0000000000..1db18553e4 --- /dev/null +++ b/samples/portlet/src/main/webapp/WEB-INF/jsp/include.jsp @@ -0,0 +1,10 @@ +<%@ page contentType="text/html" isELIgnored="false" %> + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + +<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> + +<%@ taglib prefix="html" tagdir="/WEB-INF/tags/html" %> diff --git a/samples/portlet/src/main/webapp/WEB-INF/jsp/notAuthorized.jsp b/samples/portlet/src/main/webapp/WEB-INF/jsp/notAuthorized.jsp new file mode 100644 index 0000000000..ffec8a9c94 --- /dev/null +++ b/samples/portlet/src/main/webapp/WEB-INF/jsp/notAuthorized.jsp @@ -0,0 +1,9 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + +

+ +


+ +

+ +

">- -

diff --git a/samples/portlet/src/main/webapp/WEB-INF/jsp/notAvailable.jsp b/samples/portlet/src/main/webapp/WEB-INF/jsp/notAvailable.jsp new file mode 100644 index 0000000000..c075a946a9 --- /dev/null +++ b/samples/portlet/src/main/webapp/WEB-INF/jsp/notAvailable.jsp @@ -0,0 +1,9 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + +

+ +


+ +

+ +

">- -

diff --git a/samples/portlet/src/main/webapp/WEB-INF/portlet.xml b/samples/portlet/src/main/webapp/WEB-INF/portlet.xml new file mode 100644 index 0000000000..5235b18205 --- /dev/null +++ b/samples/portlet/src/main/webapp/WEB-INF/portlet.xml @@ -0,0 +1,38 @@ + + + + + + Security Context Portlet + + org.springframework.web.portlet.DispatcherPortlet + + + contextConfigLocation + /WEB-INF/classes/portlet/securityContextPortlet.xml + + + text/html + view + + + Spring Security Context Display Portlet + + + + + user.login.id + + + user.name + + + user.name.full + + + diff --git a/samples/portlet/src/main/webapp/WEB-INF/web.xml b/samples/portlet/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..b98ffec13b --- /dev/null +++ b/samples/portlet/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,44 @@ + + + + + Spring Portlet MVC Sample Application + + + log4jConfigLocation + /WEB-INF/classes/log4j.properties + + + + contextConfigLocation + classpath:applicationContext.xml + + + + + org.springframework.web.util.Log4jConfigListener + + + + + + org.springframework.web.context.ContextLoaderListener + + + + + ViewRendererServlet + + org.springframework.web.servlet.ViewRendererServlet + + 1 + + + + ViewRendererServlet + /WEB-INF/servlet/view + + +