SEC-2194: Add Java Config samples
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
- Sample namespace-based configuration
|
||||
-
|
||||
-->
|
||||
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/security"
|
||||
xmlns:beans="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-3.0.xsd
|
||||
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
|
||||
|
||||
<debug />
|
||||
|
||||
<global-method-security pre-post-annotations="enabled" />
|
||||
|
||||
<http pattern="/static/**" security="none"/>
|
||||
<http pattern="/loggedout.jsp" security="none"/>
|
||||
|
||||
<http use-expressions="true">
|
||||
<intercept-url pattern="/secure/extreme/**" access="hasRole('supervisor')"/>
|
||||
<intercept-url pattern="/secure/**" access="isAuthenticated()" />
|
||||
<!--
|
||||
Allow all other requests. In a real application you should
|
||||
adopt a whitelisting approach where access is not allowed by default
|
||||
-->
|
||||
<intercept-url pattern="/**" access="permitAll" />
|
||||
<form-login />
|
||||
<logout logout-success-url="/loggedout.jsp" delete-cookies="JSESSIONID"/>
|
||||
<remember-me />
|
||||
<!--
|
||||
Uncomment to enable X509 client authentication support
|
||||
<x509 />
|
||||
-->
|
||||
<!-- Uncomment to limit the number of sessions a user can have -->
|
||||
<session-management invalid-session-url="/timeout.jsp">
|
||||
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
|
||||
</session-management>
|
||||
|
||||
</http>
|
||||
|
||||
<!--
|
||||
Usernames/Passwords are
|
||||
rod/koala
|
||||
dianne/emu
|
||||
scott/wombat
|
||||
peter/opal
|
||||
-->
|
||||
<beans:bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
|
||||
|
||||
<authentication-manager>
|
||||
<authentication-provider>
|
||||
<password-encoder ref="encoder"/>
|
||||
<user-service>
|
||||
<user name="rod" password="$2a$10$75pBjapg4Nl8Pzd.3JRnUe7PDJmk9qBGwNEJDAlA3V.dEJxcDKn5O" authorities="supervisor, user, teller" />
|
||||
<user name="dianne" password="$2a$04$bCMEyxrdF/7sgfUiUJ6Ose2vh9DAMaVBldS1Bw2fhi1jgutZrr9zm" authorities="user,teller" />
|
||||
<user name="scott" password="$2a$06$eChwvzAu3TSexnC3ynw4LOSw1qiEbtNItNeYv5uI40w1i3paoSfLu" authorities="user" />
|
||||
<user name="peter" password="$2a$04$8.H8bCMROLF4CIgd7IpeQ.tcBXLP5w8iplO0n.kCIkISwrIgX28Ii" authorities="user" />
|
||||
</user-service>
|
||||
</authentication-provider>
|
||||
</authentication-manager>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans xmlns="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-3.0.xsd">
|
||||
|
||||
<bean name="/listAccounts.html" class="bigbank.web.ListAccounts">
|
||||
<constructor-arg ref="bankService"/>
|
||||
</bean>
|
||||
|
||||
<bean name="/post.html" class="bigbank.web.PostAccounts">
|
||||
<constructor-arg ref="bankService"/>
|
||||
</bean>
|
||||
|
||||
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/WEB-INF/jsp/"/>
|
||||
<property name="suffix" value=".jsp"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,14 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework.security" level="DEBUG"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,53 @@
|
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" href="<c:url value='/static/css/tutorial.css'/>" type="text/css" />
|
||||
<title>Accounts</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
|
||||
<h1>Accounts</h1>
|
||||
<p>
|
||||
Anyone can view this page, but posting to an Account requires login and must be authorized. Below are some users to try posting to Accounts with.
|
||||
</p>
|
||||
<ul>
|
||||
<li>rod/koala - can post to any Account</li>
|
||||
<li>dianne/emu - can post to Accounts as long as the balance remains above the overdraft amount</li>
|
||||
<li>scott/wombat - cannot post to any Accounts</li>
|
||||
</ul>
|
||||
|
||||
<a href="index.jsp">Home</a><br><br>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>ID</b></td>
|
||||
<td><b>Holder</b></td>
|
||||
<td><b>Balance</b></td>
|
||||
<td><b>Overdraft</b></td>
|
||||
<td><b>Operations</b></td>
|
||||
</tr>
|
||||
<c:forEach var="account" items="${accounts}">
|
||||
<tr>
|
||||
<td>${account.id}</td>
|
||||
<td>${account.holder}</td>
|
||||
<td>${account.balance}</td>
|
||||
<td>${account.overdraft}</td>
|
||||
<td>
|
||||
<a href="post.html?id=${account.id}&amount=-20.00">-$20</a>
|
||||
<a href="post.html?id=${account.id}&amount=-5.00">-$5</a>
|
||||
<a href="post.html?id=${account.id}&amount=5.00">+$5</a>
|
||||
<a href="post.html?id=${account.id}&amount=20.00">+$20</a>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</table>
|
||||
|
||||
<p><a href="j_spring_security_logout">Logout</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
73
samples/tutorial-xml/src/main/webapp/WEB-INF/web.xml
Normal file
73
samples/tutorial-xml/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
- Tutorial web application
|
||||
-
|
||||
-->
|
||||
|
||||
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
||||
|
||||
<display-name>Spring Security Tutorial 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>
|
||||
classpath:applicationContext-business.xml
|
||||
/WEB-INF/applicationContext-security.xml
|
||||
</param-value>
|
||||
</context-param>
|
||||
|
||||
<context-param>
|
||||
<param-name>webAppRootKey</param-name>
|
||||
<param-value>tutorial.root</param-value>
|
||||
</context-param>
|
||||
|
||||
<filter>
|
||||
<filter-name>springSecurityFilterChain</filter-name>
|
||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>springSecurityFilterChain</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!--
|
||||
- Loads the root application context of this web app at startup.
|
||||
-->
|
||||
<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.web.session.HttpSessionEventPublisher</listener-class>
|
||||
</listener>
|
||||
|
||||
<!--
|
||||
- Provides core MVC application controller. See bank-servlet.xml.
|
||||
-->
|
||||
<servlet>
|
||||
<servlet-name>bank</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>bank</servlet-name>
|
||||
<url-pattern>*.html</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>index.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
</web-app>
|
||||
42
samples/tutorial-xml/src/main/webapp/index.jsp
Normal file
42
samples/tutorial-xml/src/main/webapp/index.jsp
Normal file
@@ -0,0 +1,42 @@
|
||||
<%@ page session="false" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" href="<c:url value='/static/css/tutorial.css'/>" type="text/css" />
|
||||
<title>Home Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1>Home Page</h1>
|
||||
<p>
|
||||
Anyone can view this page.
|
||||
</p>
|
||||
<p>
|
||||
While anyone can also view the <a href="listAccounts.html">list accounts</a> page, you must be authorized to post to an Account from the list accounts page.
|
||||
</p>
|
||||
<p>
|
||||
Your principal object is....: <%= request.getUserPrincipal() %>
|
||||
</p>
|
||||
<sec:authorize url='/secure/index.jsp'>
|
||||
<p>
|
||||
You can currently access "/secure" URLs.
|
||||
</p>
|
||||
</sec:authorize>
|
||||
<sec:authorize url='/secure/extreme/index.jsp'>
|
||||
<p>
|
||||
You can currently access "/secure/extreme" URLs.
|
||||
</p>
|
||||
</sec:authorize>
|
||||
|
||||
<p>
|
||||
<a href="secure/index.jsp">Secure page</a></p>
|
||||
<p><a href="secure/extreme/index.jsp">Extremely secure page</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
20
samples/tutorial-xml/src/main/webapp/loggedout.jsp
Normal file
20
samples/tutorial-xml/src/main/webapp/loggedout.jsp
Normal file
@@ -0,0 +1,20 @@
|
||||
<%@page session="false" %>
|
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" href="<c:url value='/static/css/tutorial.css'/>" type="text/css" />
|
||||
<title>Logged Out</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h2>Logged Out</h2>
|
||||
<p>
|
||||
You have been logged out. <a href="<c:url value='/'/>">Start again</a>.
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
<%@ taglib prefix="authz" uri="http://www.springframework.org/security/tags" %>
|
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" href="<c:url value='/static/css/tutorial.css'/>" type="text/css" />
|
||||
<title>Secure Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1>VERY Secure Page</h1>
|
||||
This is a protected page. You can only see me if you are a supervisor.
|
||||
|
||||
<authz:authorize access="hasRole('supervisor')">
|
||||
You have authority "supervisor" (this text is surrounded by <authz:authorize> tags).
|
||||
</authz:authorize>
|
||||
|
||||
<p><a href="../../">Home</a></p>
|
||||
<p><a href="../../j_spring_security_logout">Logout</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
49
samples/tutorial-xml/src/main/webapp/secure/index.jsp
Normal file
49
samples/tutorial-xml/src/main/webapp/secure/index.jsp
Normal file
@@ -0,0 +1,49 @@
|
||||
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
|
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" href="<c:url value='/static/css/tutorial.css'/>" type="text/css" />
|
||||
<title>Secure Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
|
||||
<h1>Secure Page</h1>
|
||||
<p>
|
||||
This is a protected page. You can get to me if you've been remembered,
|
||||
or if you've authenticated this session.
|
||||
</p>
|
||||
<p>
|
||||
<sec:authorize access="hasRole('supervisor')">
|
||||
You are a supervisor! You can therefore see the <a href="extreme/index.jsp">extremely secure page</a>.<br/><br/>
|
||||
</sec:authorize>
|
||||
</p>
|
||||
<h3>Properties obtained using <sec:authentication /> tag</h3>
|
||||
<table border="1">
|
||||
<tr><th>Tag</th><th>Value</th></tr>
|
||||
<tr>
|
||||
<td><sec:authentication property='name' /></td><td><sec:authentication property="name"/></td>
|
||||
</tr>
|
||||
<sec:authorize access="isAuthenticated()">
|
||||
<tr>
|
||||
<td><sec:authentication property='principal.username' /></td><td><sec:authentication property="principal.username"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><sec:authentication property='principal.enabled' /></td><td><sec:authentication property="principal.enabled"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><sec:authentication property='principal.accountNonLocked' /></td><td><sec:authentication property="principal.accountNonLocked"/></td>
|
||||
</tr>
|
||||
</sec:authorize>
|
||||
</table>
|
||||
|
||||
|
||||
<p><a href="../">Home</a></p>
|
||||
<p><a href="../j_spring_security_logout">Logout</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
13
samples/tutorial-xml/src/main/webapp/static/css/tutorial.css
Normal file
13
samples/tutorial-xml/src/main/webapp/static/css/tutorial.css
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
body {
|
||||
font-family:"Palatino Linotype","Book Antiqua",Palatino,serif;
|
||||
}
|
||||
|
||||
#content {
|
||||
margin: 5em auto;
|
||||
width: 40em;
|
||||
}
|
||||
|
||||
.securityHiddenUI, .securityHiddenUI * {
|
||||
background-color: #ff4500;
|
||||
}
|
||||
20
samples/tutorial-xml/src/main/webapp/timeout.jsp
Normal file
20
samples/tutorial-xml/src/main/webapp/timeout.jsp
Normal file
@@ -0,0 +1,20 @@
|
||||
<%@page session="false" %>
|
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" href="<c:url value='/static/css/tutorial.css'/>" type="text/css" />
|
||||
<title>Session Timeout</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h2>Invalid Session</h2>
|
||||
|
||||
<p>
|
||||
Your session appears to have timed out. Please <a href="<c:url value='/'/>">start again</a>.
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user