Use xml / javaconfig folders for samples
Fixes gh-3752
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
|
||||
|
||||
/**
|
||||
* No customizations of {@link AbstractSecurityWebApplicationInitializer} are necessary.
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public class MessageSecurityWebApplicationInitializer extends
|
||||
AbstractSecurityWebApplicationInitializer {
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
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;
|
||||
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
// @formatter:off
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/resources/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login")
|
||||
.permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.permitAll();
|
||||
}
|
||||
// @formatter:on
|
||||
|
||||
// @formatter:off
|
||||
@Autowired
|
||||
public void configureGlobal(
|
||||
AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth
|
||||
.inMemoryAuthentication()
|
||||
.withUser("user").password("password").roles("USER");
|
||||
}
|
||||
// @formatter:on
|
||||
}
|
||||
12
samples/javaconfig/form/src/main/resources/logback.xml
Normal file
12
samples/javaconfig/form/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<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>
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
27
samples/javaconfig/form/src/main/resources/views/login.html
Normal file
27
samples/javaconfig/form/src/main/resources/views/login.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title tiles:fragment="title">Please Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<div tiles:fragment="content">
|
||||
<form name="f" th:action="@{/login}" method="post">
|
||||
<fieldset>
|
||||
<legend>Please Login</legend>
|
||||
<div th:if="${param.error}" class="alert alert-error">
|
||||
Invalid username and password.
|
||||
</div>
|
||||
<div th:if="${param.logout}" class="alert alert-success">
|
||||
You have been logged out.
|
||||
</div>
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username"/>
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password"/>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn">Log in</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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="/login" var="loginUrl"/>
|
||||
<form:form name="f" action="${loginUrl}" method="post">
|
||||
<fieldset>
|
||||
<legend>Please Login</legend>
|
||||
<c:if test="${param.error != null}">
|
||||
<div class="alert alert-error">
|
||||
Invalid username and password.
|
||||
</div>
|
||||
</c:if>
|
||||
<c:if test="${param.logout != null}">
|
||||
<div class="alert alert-success">
|
||||
You have been logged out.
|
||||
</div>
|
||||
</c:if>
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" value="${username}"/>
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password"/>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn">Log in</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form: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>
|
||||
Reference in New Issue
Block a user