SEC-576: Tidied up code, added preauth sample demo app.
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
- Sample namespace-based configuration
|
||||
-
|
||||
- $Id: applicationContext-security-ns.xml 2396 2007-12-23 16:36:44Z luke_t $
|
||||
-->
|
||||
|
||||
<b:beans xmlns="http://www.springframework.org/schema/security"
|
||||
xmlns:b="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
|
||||
|
||||
|
||||
<b:bean id="filterChainProxy" class="org.springframework.security.util.FilterChainProxy">
|
||||
<filter-chain-map path-type="ant">
|
||||
<filter-chain pattern="/**" filters="sif,j2eePreAuthFilter,logoutFilter,etf,fsi"/>
|
||||
</filter-chain-map>
|
||||
</b:bean>
|
||||
|
||||
|
||||
<b:bean id="authenticationManager" class="org.springframework.security.providers.ProviderManager">
|
||||
<b:property name="providers">
|
||||
<b:list>
|
||||
<b:ref local="preAuthenticatedAuthenticationProvider"/>
|
||||
</b:list>
|
||||
</b:property>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="sif" class="org.springframework.security.context.HttpSessionContextIntegrationFilter"/>
|
||||
|
||||
<b:bean id="preAuthenticatedAuthenticationProvider" class="org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationProvider">
|
||||
<b:property name="preAuthenticatedUserDetailsService" ref="preAuthenticatedUserDetailsService"/>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="preAuthenticatedUserDetailsService"
|
||||
class="org.springframework.security.providers.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService"/>
|
||||
|
||||
<b:bean id="j2eePreAuthFilter" class="org.springframework.security.ui.preauth.j2ee.J2eePreAuthenticatedProcessingFilter">
|
||||
<b:property name="authenticationManager" ref="authenticationManager"/>
|
||||
<b:property name="authenticationDetailsSource" ref="authenticationDetailsSource"/>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="preAuthenticatedProcessingFilterEntryPoint"
|
||||
class="org.springframework.security.ui.preauth.PreAuthenticatedProcessingFilterEntryPoint"/>
|
||||
|
||||
|
||||
<b:bean id="logoutFilter" class="org.springframework.security.ui.logout.LogoutFilter">
|
||||
<b:constructor-arg value="/"/>
|
||||
<b:constructor-arg>
|
||||
<b:list>
|
||||
<b:bean class="org.springframework.security.ui.logout.SecurityContextLogoutHandler"/>
|
||||
</b:list>
|
||||
</b:constructor-arg>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="authenticationDetailsSource" class="org.springframework.security.ui.preauth.j2ee.J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource">
|
||||
<b:property name="j2eeMappableRolesRetriever">
|
||||
<b:ref local="j2eeMappableRolesRetriever"/>
|
||||
</b:property>
|
||||
|
||||
<b:property name="j2eeUserRoles2GrantedAuthoritiesMapper">
|
||||
<b:ref local="j2eeUserRoles2GrantedAuthoritiesMapper"/>
|
||||
</b:property>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="j2eeUserRoles2GrantedAuthoritiesMapper" class="org.springframework.security.rolemapping.SimpleRoles2GrantedAuthoritiesMapper">
|
||||
<b:property name="convertRoleToUpperCase" value="true"/>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="j2eeMappableRolesRetriever" class="org.springframework.security.ui.preauth.j2ee.WebXmlMappableRolesRetriever">
|
||||
|
||||
<b:property name="webXmlInputStream"><b:bean factory-bean="webXmlResource" factory-method="getInputStream"/>
|
||||
</b:property>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="webXmlResource" class="org.springframework.web.context.support.ServletContextResource">
|
||||
<b:constructor-arg ref="servletContext"/>
|
||||
<b:constructor-arg value="/WEB-INF/web.xml"/>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="servletContext" class="org.springframework.web.context.support.ServletContextFactoryBean"/>
|
||||
|
||||
<b:bean id="etf" class="org.springframework.security.ui.ExceptionTranslationFilter">
|
||||
<b:property name="authenticationEntryPoint">
|
||||
<b:ref local="preAuthenticatedProcessingFilterEntryPoint"/>
|
||||
</b:property>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="httpRequestAccessDecisionManager" class="org.springframework.security.vote.AffirmativeBased">
|
||||
|
||||
<b:property name="allowIfAllAbstainDecisions" value="false"/>
|
||||
<b:property name="decisionVoters">
|
||||
<b:list>
|
||||
<b:ref bean="roleVoter"/>
|
||||
</b:list>
|
||||
</b:property>
|
||||
</b:bean>
|
||||
|
||||
|
||||
<b:bean id="fsi" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
|
||||
<b:property name="authenticationManager" ref="authenticationManager"/>
|
||||
<b:property name="accessDecisionManager">
|
||||
<b:ref local="httpRequestAccessDecisionManager"/>
|
||||
</b:property>
|
||||
|
||||
<b:property name="objectDefinitionSource">
|
||||
<b:value>
|
||||
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
|
||||
PATTERN_TYPE_APACHE_ANT
|
||||
/secure/extreme/**=ROLE_SUPERVISOR
|
||||
/secure/**=ROLE_USER
|
||||
/**=ROLE_USER
|
||||
</b:value>
|
||||
</b:property>
|
||||
</b:bean>
|
||||
|
||||
<b:bean id="roleVoter" class="org.springframework.security.vote.RoleVoter"/>
|
||||
|
||||
<b:bean id="securityContextHolderAwareRequestFilter" class="org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter">
|
||||
<b:property name="wrapperClass" value="org.springframework.security.wrapper.SecurityContextHolderAwareRequestWrapper"/>
|
||||
</b:bean>
|
||||
|
||||
</b:beans>
|
||||
@@ -0,0 +1,20 @@
|
||||
# Global logging configuration
|
||||
log4j.rootLogger=INFO, stdout, fileout
|
||||
|
||||
log4j.logger.org.springframework.security=DEBUG, stdout, fileout
|
||||
|
||||
# Console output...
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.conversionPattern=[%p,%c{1},%t] %m%n
|
||||
|
||||
# Rolling log file output...
|
||||
log4j.appender.fileout=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.fileout.File=spring-security-preauth.log
|
||||
#log4j.appender.fileout.File=${webapp.root}/WEB-INF/log4j.log
|
||||
log4j.appender.fileout.MaxFileSize=1024KB
|
||||
log4j.appender.fileout.MaxBackupIndex=1
|
||||
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.fileout.layout.conversionPattern=%d{ABSOLUTE} %5p %c{1},%t:%L - %m%n
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
- Tutorial web application
|
||||
-
|
||||
- $Id: web.xml 2476 2008-01-18 18:17:09Z luke_t $
|
||||
-->
|
||||
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
|
||||
|
||||
<display-name>Spring Security Preauthentication Demo Application</display-name>
|
||||
|
||||
<!--
|
||||
- Location of the XML file that defines the root application context
|
||||
- Applied by ContextLoaderListener.
|
||||
-->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
/WEB-INF/applicationContext-security.xml
|
||||
</param-value>
|
||||
</context-param>
|
||||
|
||||
<filter>
|
||||
<filter-name>filterChainProxy</filter-name>
|
||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>filterChainProxy</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!--
|
||||
- Loads the root application context of this web app at startup.
|
||||
- The application context is then available via
|
||||
- WebApplicationContextUtils.getWebApplicationContext(servletContext).
|
||||
-->
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!--
|
||||
- Publishes events for session creation and destruction through the application
|
||||
- context. Optional unless concurrent session control is being used.
|
||||
-->
|
||||
<listener>
|
||||
<listener-class>org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
|
||||
</listener>
|
||||
|
||||
<login-config>
|
||||
<auth-method>BASIC</auth-method>
|
||||
<realm-name>Preauth Realm</realm-name>
|
||||
</login-config>
|
||||
|
||||
<security-role>
|
||||
<role-name>ROLE_USER</role-name>
|
||||
</security-role>
|
||||
<security-role>
|
||||
<role-name>ROLE_SUPERVISOR</role-name>
|
||||
</security-role>
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<web-resource-name>All areas</web-resource-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</web-resource-collection>
|
||||
<auth-constraint>
|
||||
<role-name>ROLE_USER</role-name>
|
||||
</auth-constraint>
|
||||
</security-constraint>
|
||||
|
||||
</web-app>
|
||||
@@ -0,0 +1,11 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>Home Page</h1>
|
||||
<p>Anyone can view this page.</p>
|
||||
|
||||
<p>Your principal object is....: <%= request.getUserPrincipal() %></p>
|
||||
|
||||
<p><a href="secure/index.jsp">Secure page</a></p>
|
||||
<p><a href="secure/extreme/index.jsp">Extremely secure page</a></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,15 @@
|
||||
<%@ taglib prefix="authz" uri="http://www.springframework.org/security/tags" %>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<h1>VERY Secure Page</h1>
|
||||
This is a protected page. You can only see me if you are a supervisor.
|
||||
|
||||
<authz:authorize ifAllGranted="ROLE_SUPERVISOR">
|
||||
You have "ROLE_SUPERVISOR" (this text is surrounded by <authz:authorize> tags).
|
||||
</authz:authorize>
|
||||
|
||||
<p><a href="../../">Home</a>
|
||||
<p><a href="../../j_spring_security_logout">Logout</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>Secure Page</h1>
|
||||
This is a protected page. You can get to me if you've been remembered,
|
||||
or if you've authenticated this session.<br><br>
|
||||
|
||||
<%if (request.isUserInRole("ROLE_SUPERVISOR")) { %>
|
||||
You are a supervisor! You can therefore see the <a href="extreme/index.jsp">extremely secure page</a>.<br><br>
|
||||
<% } %>
|
||||
|
||||
|
||||
<p><a href="../">Home</a>
|
||||
<p><a href="../j_spring_security_logout">Logout</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user