SEC-2194: Add Java Config samples
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
package org.springframework.security.samples.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/login","/resources/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.jee()
|
||||
.mappableRoles("USER","ADMIN");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<decorators defaultdir="/WEB-INF/decorators">
|
||||
<decorator name="main" page="main.jsp">
|
||||
<pattern>/*</pattern>
|
||||
</decorator>
|
||||
</decorators>
|
||||
@@ -0,0 +1,130 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
|
||||
xmlns:decorator="http://www.opensymphony.com/sitemesh/decorator"
|
||||
xmlns:page="http://www.opensymphony.com/sitemesh/page"
|
||||
xmlns:form="http://www.springframework.org/tags/form"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:sec="http://www.springframework.org/security/tags"
|
||||
xmlns:tags="urn:jsptagdir:/WEB-INF/tags" version="2.0">
|
||||
|
||||
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8" />
|
||||
<jsp:output omit-xml-declaration="true" />
|
||||
<jsp:output doctype-root-element="HTML"
|
||||
doctype-system="about:legacy-compat" />
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>SecureMail: <decorator:title/></title>
|
||||
<c:url var="faviconUrl" value="/resources/img/favicon.ico"/>
|
||||
<link rel="icon" type="image/x-icon" href="${faviconUrl}"/>
|
||||
<c:url var="bootstrapUrl" value="/resources/css/bootstrap.css"/>
|
||||
<link href="${bootstrapUrl}" rel="stylesheet"></link>
|
||||
<style type="text/css">
|
||||
/* Sticky footer styles
|
||||
-------------------------------------------------- */
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
/* The html and body elements cannot have any padding or margin. */
|
||||
}
|
||||
|
||||
/* Wrapper for page content to push down footer */
|
||||
#wrap {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
/* Negative indent footer by it's height */
|
||||
margin: 0 auto -60px;
|
||||
}
|
||||
|
||||
/* Set the fixed height of the footer here */
|
||||
#push,
|
||||
#footer {
|
||||
height: 60px;
|
||||
}
|
||||
#footer {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* Lastly, apply responsive CSS fixes as necessary */
|
||||
@media (max-width: 767px) {
|
||||
#footer {
|
||||
margin-left: -20px;
|
||||
margin-right: -20px;
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Custom page CSS
|
||||
-------------------------------------------------- */
|
||||
/* Not required for template or sticky footer method. */
|
||||
|
||||
.container {
|
||||
width: auto;
|
||||
max-width: 680px;
|
||||
}
|
||||
.container .credit {
|
||||
margin: 20px 0;
|
||||
text-align: center;
|
||||
}
|
||||
a {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<c:url var="bootstrapResponsiveUrl" value="/resources/css/bootstrap-responsive.css"/>
|
||||
<link href="${bootstrapResponsiveUrl}" rel="stylesheet"></link>
|
||||
|
||||
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<div id="wrap">
|
||||
<div class="navbar navbar-inverse navbar-static-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<c:url var="homeUrl" value="/"/>
|
||||
<c:url var="logoUrl" value="/resources/img/logo.png"/>
|
||||
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
|
||||
<div class="nav-collapse collapse">
|
||||
<ul class="nav">
|
||||
<c:url var="inboxUrl" value="/"/>
|
||||
<li><a href="${inboxUrl}">Inbox</a></li>
|
||||
<c:url var="composeUrl" value="/?form"/>
|
||||
<li><a href="${composeUrl}">Compose</a></li>
|
||||
<c:url var="logoutUrl" value="/logout"/>
|
||||
<li><a href="${logoutUrl}">Log out</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Begin page content -->
|
||||
<div class="container">
|
||||
<decorator:body/>
|
||||
</div>
|
||||
|
||||
<div id="push"><!-- --></div>
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
<div class="container">
|
||||
<p class="muted credit">Visit the <a href="#">Spring Security</a> site for more <a href="#">samples</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,21 @@
|
||||
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||
xmlns:sec="http://www.springframework.org/security/tags"
|
||||
xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
|
||||
<jsp:output omit-xml-declaration="yes" />
|
||||
<jsp:directive.attribute name="url" type="java.lang.String" required="true" description="The url to go to"/>
|
||||
<jsp:directive.attribute name="text" type="java.lang.String" required="true" description="The text for the tab"/>
|
||||
<jsp:directive.attribute name="id" type="java.lang.String" required="true" description="The id for the tab"/>
|
||||
|
||||
<sec:authorize url="${url}">
|
||||
<c:url var="url" value="${url}"/>
|
||||
<c:choose>
|
||||
<c:when test="${id == tab}">
|
||||
<c:set var="css" value=" selected"/>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<c:set var="css" value=""/>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<li class="tab${css}"><a href="${url}">${text}</a></li>
|
||||
</sec:authorize>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,18 @@
|
||||
<jsp:root
|
||||
xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||
xmlns:form="http://www.springframework.org/tags/form"
|
||||
version="2.0">
|
||||
<jsp:directive.page language="java" contentType="text/html"/>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<c:set var="title" value="Access Denied"/>
|
||||
<head>
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${title}</h1>
|
||||
<div class="errors">You do not have sufficient privileges to access this page.</div>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,18 @@
|
||||
<jsp:root
|
||||
xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||
xmlns:form="http://www.springframework.org/tags/form"
|
||||
version="2.0">
|
||||
<jsp:directive.page language="java" contentType="text/html"/>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<c:set var="title" value="Page Not Found"/>
|
||||
<head>
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${title}</h1>
|
||||
<div class="errors">The requested page could not be found.</div>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,18 @@
|
||||
<jsp:root
|
||||
xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||
xmlns:form="http://www.springframework.org/tags/form"
|
||||
version="2.0">
|
||||
<jsp:directive.page language="java" contentType="text/html"/>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<c:set var="title" value="Internal Error"/>
|
||||
<head>
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${title}</h1>
|
||||
<div class="errors">An internal error occurred.</div>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,36 @@
|
||||
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||
xmlns:form="http://www.springframework.org/tags/form" version="2.0">
|
||||
<jsp:directive.page language="java" contentType="text/html" />
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Please Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<c:url value="/j_security_check" var="loginUrl"/>
|
||||
<form name="f" action="${loginUrl}" method="post">
|
||||
<fieldset>
|
||||
<legend>Please Login</legend>
|
||||
<c:if test="${param.error != null}">
|
||||
<div class="alert alert-error">
|
||||
Failed to login.
|
||||
</div>
|
||||
</c:if>
|
||||
<c:if test="${param.logout != null}">
|
||||
<div class="alert alert-success">
|
||||
You have been logged out.
|
||||
</div>
|
||||
</c:if>
|
||||
<label for="j_username">Username</label>
|
||||
<input type="text" id="j_username" name="j_username" value="${username}"/>
|
||||
<label for="j_password">Password</label>
|
||||
<input type="password" id="j_password" name="j_password"/>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn">Log in</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,26 @@
|
||||
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||
xmlns:form="http://www.springframework.org/tags/form" version="2.0">
|
||||
<jsp:directive.page language="java" contentType="text/html" />
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Compose</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Messages : Create</h1>
|
||||
<form:form action="./" method="post" modelAttribute="message">
|
||||
<form:errors path="*" element="div" cssClass="alert alert-error" />
|
||||
<label for="summary">Summary</label>
|
||||
<form:input type="text" path="summary" class="input-xxlarge" />
|
||||
<label for="text">Message</label>
|
||||
<form:textarea path="text" class="input-xxlarge"></form:textarea>
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="Create" />
|
||||
</div>
|
||||
</form:form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,40 @@
|
||||
<jsp:root
|
||||
xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:form="http://www.springframework.org/tags/form"
|
||||
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
|
||||
version="2.0">
|
||||
<jsp:directive.page language="java" contentType="text/html"/>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Inbox</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Inbox</h1>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Created</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:if test="${empty messages}">
|
||||
<tr>
|
||||
<td colspan="2" class="msg">You have not received any mail yet.</td>
|
||||
</tr>
|
||||
</c:if>
|
||||
<c:forEach items="${messages}" var="message">
|
||||
<tr>
|
||||
<td><fmt:formatDate value="${message.created.time}"/></td>
|
||||
<spring:url var="messageUrl" value="/{id}">
|
||||
<spring:param name="id" value="${message.id}"/>
|
||||
</spring:url>
|
||||
<td><a href="${messageUrl}"><c:out value="${message.summary}"/></a></td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,24 @@
|
||||
<jsp:root
|
||||
xmlns:jsp="http://java.sun.com/JSP/Page"
|
||||
xmlns:spring="http://www.springframework.org/tags"
|
||||
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:form="http://www.springframework.org/tags/form"
|
||||
version="2.0">
|
||||
<jsp:directive.page language="java" contentType="text/html"/>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title><c:out value="${message.summary}"/></title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Message : <c:out value="${message.summary}"/></h1>
|
||||
<dl>
|
||||
<dt>Created</dt>
|
||||
<dd><fmt:formatDate value="${message.created.time}"/></dd>
|
||||
<dt>Message</dt>
|
||||
<dd><c:out value="${message.text}"/></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
|
||||
<login-config>
|
||||
<auth-method>FORM</auth-method>
|
||||
<form-login-config>
|
||||
<form-login-page>/login</form-login-page>
|
||||
<form-error-page>/login?error</form-error-page>
|
||||
</form-login-config>
|
||||
</login-config>
|
||||
|
||||
<security-role>
|
||||
<role-name>ROLE_USER</role-name>
|
||||
</security-role>
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<web-resource-name>Public</web-resource-name>
|
||||
<description>Matches unconstrained pages</description>
|
||||
<url-pattern>/login</url-pattern>
|
||||
<url-pattern>/logout</url-pattern>
|
||||
<url-pattern>/resources/*</url-pattern>
|
||||
</web-resource-collection>
|
||||
</security-constraint>
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<web-resource-name>Secured 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>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed 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.springframework.security.samples.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes=SecurityConfig.class)
|
||||
public class SecurityConfigTests {
|
||||
|
||||
@Test
|
||||
public void securityConfigurationLoads() {}
|
||||
}
|
||||
Reference in New Issue
Block a user