move source to spring-5-security module
This commit is contained in:
parent
2b78cdbafa
commit
a5f6f5e035
|
@ -1,95 +1,110 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-5-security</artifactId>
|
<artifactId>spring-5-security</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>spring-5-security</name>
|
<name>spring-5-security</name>
|
||||||
<description>spring 5 security sample project</description>
|
<description>spring 5 security sample project</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.0.0.M7</version>
|
<version>2.0.0.M7</version>
|
||||||
<relativePath /> <!-- lookup parent from repository -->
|
<relativePath /> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
<!-- oauth2 -->
|
<groupId>org.thymeleaf.extras</groupId>
|
||||||
<dependency>
|
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
|
||||||
<groupId>org.springframework.security</groupId>
|
</dependency>
|
||||||
<artifactId>spring-security-oauth2-client</artifactId>
|
|
||||||
</dependency>
|
<!-- oauth2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-oauth2-jose</artifactId>
|
<artifactId>spring-security-oauth2-client</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
<build>
|
<artifactId>spring-security-oauth2-jose</artifactId>
|
||||||
<plugins>
|
</dependency>
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
<dependency>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
</plugin>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
<plugin>
|
</dependency>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<dependency>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<configuration>
|
<artifactId>spring-security-test</artifactId>
|
||||||
<forkCount>3</forkCount>
|
<scope>test</scope>
|
||||||
<reuseForks>true</reuseForks>
|
</dependency>
|
||||||
<parallel>methods</parallel>
|
</dependencies>
|
||||||
<useUnlimitedThreads>true</useUnlimitedThreads>
|
|
||||||
<excludes>
|
<build>
|
||||||
<exclude>**/*IntegrationTest.java</exclude>
|
<plugins>
|
||||||
<exclude>**/*LiveTest.java</exclude>
|
<plugin>
|
||||||
</excludes>
|
<groupId>org.springframework.boot</groupId>
|
||||||
</configuration>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
|
||||||
</build>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<repositories>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<repository>
|
<configuration>
|
||||||
<id>spring-milestones</id>
|
<forkCount>3</forkCount>
|
||||||
<name>Spring Milestones</name>
|
<reuseForks>true</reuseForks>
|
||||||
<url>https://repo.spring.io/milestone</url>
|
<parallel>methods</parallel>
|
||||||
<snapshots>
|
<useUnlimitedThreads>true</useUnlimitedThreads>
|
||||||
<enabled>false</enabled>
|
<excludes>
|
||||||
</snapshots>
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
</repository>
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
</repositories>
|
</excludes>
|
||||||
<pluginRepositories>
|
</configuration>
|
||||||
<pluginRepository>
|
</plugin>
|
||||||
<id>spring-milestones</id>
|
</plugins>
|
||||||
<name>Spring Milestones</name>
|
</build>
|
||||||
<url>https://repo.spring.io/milestone</url>
|
|
||||||
<snapshots>
|
<repositories>
|
||||||
<enabled>false</enabled>
|
<repository>
|
||||||
</snapshots>
|
<id>spring-milestones</id>
|
||||||
</pluginRepository>
|
<name>Spring Milestones</name>
|
||||||
</pluginRepositories>
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
<properties>
|
<enabled>false</enabled>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
</snapshots>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
</repository>
|
||||||
<java.version>1.8</java.version>
|
</repositories>
|
||||||
</properties>
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
|
||||||
|
public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
||||||
|
|
||||||
|
public static final String SPRING_SECURITY_FORM_DOMAIN_KEY = "domain";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws AuthenticationException {
|
||||||
|
|
||||||
|
if (!request.getMethod()
|
||||||
|
.equals("POST")) {
|
||||||
|
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
|
||||||
|
}
|
||||||
|
|
||||||
|
UsernamePasswordAuthenticationToken authRequest = getAuthRequest(request);
|
||||||
|
setDetails(request, authRequest);
|
||||||
|
return this.getAuthenticationManager()
|
||||||
|
.authenticate(authRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UsernamePasswordAuthenticationToken getAuthRequest(HttpServletRequest request) {
|
||||||
|
String username = obtainUsername(request);
|
||||||
|
String password = obtainPassword(request);
|
||||||
|
String domain = obtainDomain(request);
|
||||||
|
|
||||||
|
if (username == null) {
|
||||||
|
username = "";
|
||||||
|
}
|
||||||
|
if (password == null) {
|
||||||
|
password = "";
|
||||||
|
}
|
||||||
|
if (domain == null) {
|
||||||
|
domain = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String usernameDomain = String.format("%s%s%s", username.trim(),
|
||||||
|
String.valueOf(Character.LINE_SEPARATOR), domain);
|
||||||
|
return new UsernamePasswordAuthenticationToken(usernameDomain, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String obtainDomain(HttpServletRequest request) {
|
||||||
|
return request.getParameter(SPRING_SECURITY_FORM_DOMAIN_KEY);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service("userDetailsService")
|
||||||
|
public class CustomUserDetailsService implements UserDetailsService {
|
||||||
|
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
public CustomUserDetailsService(UserRepository userRepository) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
String[] usernameAndDomain = StringUtils.split(username, String.valueOf(Character.LINE_SEPARATOR));
|
||||||
|
if (usernameAndDomain == null || usernameAndDomain.length != 2) {
|
||||||
|
throw new UsernameNotFoundException("Username and domain must be provided");
|
||||||
|
}
|
||||||
|
User user = userRepository.findUser(usernameAndDomain[0], usernameAndDomain[1]);
|
||||||
|
if (user == null) {
|
||||||
|
throw new UsernameNotFoundException(
|
||||||
|
String.format("Username not found for domain, username=%s, domain=%s",
|
||||||
|
usernameAndDomain[0], usernameAndDomain[1]));
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository("userRepository")
|
||||||
|
public class CustomUserRepository implements UserRepository {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User findUser(String username, String domain) {
|
||||||
|
if (StringUtils.isAnyBlank(username, domain)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
Collection<? extends GrantedAuthority> authorities = new ArrayList<>();
|
||||||
|
User user = new User(username, domain,
|
||||||
|
"$2a$10$U3GhSMpsMSOE8Kqsbn58/edxDBKlVuYMh7qk/7ErApYFjJzi2VG5K", true,
|
||||||
|
true, true, true, authorities);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.security.authentication.AuthenticationProvider;
|
||||||
|
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||||
|
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;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
|
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
|
||||||
|
@EnableWebSecurity
|
||||||
|
@PropertySource("application-extrafields.properties")
|
||||||
|
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDetailsService userDetailsService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
|
||||||
|
http
|
||||||
|
.addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class)
|
||||||
|
.authorizeRequests()
|
||||||
|
.antMatchers("/css/**", "/index").permitAll()
|
||||||
|
.antMatchers("/user/**").authenticated()
|
||||||
|
.and()
|
||||||
|
.formLogin().loginPage("/login")
|
||||||
|
.and()
|
||||||
|
.logout()
|
||||||
|
.logoutUrl("/logout");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomAuthenticationFilter authenticationFilter() throws Exception {
|
||||||
|
CustomAuthenticationFilter filter = new CustomAuthenticationFilter();
|
||||||
|
filter.setAuthenticationManager(authenticationManagerBean());
|
||||||
|
filter.setAuthenticationFailureHandler(failureHandler());
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
|
auth.authenticationProvider(authProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthenticationProvider authProvider() {
|
||||||
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||||
|
provider.setUserDetailsService(userDetailsService);
|
||||||
|
provider.setPasswordEncoder(passwordEncoder());
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleUrlAuthenticationFailureHandler failureHandler() {
|
||||||
|
return new SimpleUrlAuthenticationFailureHandler("/login?error=true");
|
||||||
|
}
|
||||||
|
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringExtraLoginFieldsApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SpringExtraLoginFieldsApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
|
||||||
|
public class User extends org.springframework.security.core.userdetails.User {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private final String domain;
|
||||||
|
|
||||||
|
public User(String username, String domain, String password, boolean enabled,
|
||||||
|
boolean accountNonExpired, boolean credentialsNonExpired,
|
||||||
|
boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
|
||||||
|
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
|
||||||
|
this.domain = domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomain() {
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
public interface UserRepository {
|
||||||
|
|
||||||
|
public User findUser(String username, String domain);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.baeldung.securityextrafields;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class WebController {
|
||||||
|
|
||||||
|
@RequestMapping("/")
|
||||||
|
public String root() {
|
||||||
|
return "redirect:/index";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/index")
|
||||||
|
public String index(Model model) {
|
||||||
|
getDomain().ifPresent(d -> {
|
||||||
|
model.addAttribute("domain", d);
|
||||||
|
});
|
||||||
|
return "index";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/user/index")
|
||||||
|
public String userIndex(Model model) {
|
||||||
|
getDomain().ifPresent(d -> {
|
||||||
|
model.addAttribute("domain", d);
|
||||||
|
});
|
||||||
|
return "user/index";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/login")
|
||||||
|
public String login() {
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<String> getDomain() {
|
||||||
|
Authentication auth = SecurityContextHolder.getContext()
|
||||||
|
.getAuthentication();
|
||||||
|
String domain = null;
|
||||||
|
if (auth != null && !auth.getClass().equals(AnonymousAuthenticationToken.class)) {
|
||||||
|
User user = (User) auth.getPrincipal();
|
||||||
|
domain = user.getDomain();
|
||||||
|
}
|
||||||
|
return Optional.ofNullable(domain);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
spring.thymeleaf.prefix = classpath:/templatesextrafields/
|
|
@ -0,0 +1,18 @@
|
||||||
|
body {
|
||||||
|
font-family: sans;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.error {
|
||||||
|
font-weight: bold;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.logout {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formfield {
|
||||||
|
margin: 0.5em;
|
||||||
|
padding: 0.3em;
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
|
||||||
|
<head>
|
||||||
|
<title>Spring Security - Login With Extra Fields</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="/css/main.css" th:href="@{/css/main.css}" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div th:fragment="logout" class="logout" sec:authorize="isAuthenticated()">
|
||||||
|
Logged in user: <span sec:authentication="name"></span> |
|
||||||
|
domain: <span th:text="${domain}">Some Domain</span>
|
||||||
|
<div>
|
||||||
|
<form action="#" th:action="@{/logout}" method="post">
|
||||||
|
<input type="submit" value="Logout" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<h1>Hello Spring Security</h1>
|
||||||
|
<p>This is an unsecured page, but you can access the secured pages after authenticating.</p>
|
||||||
|
<ul>
|
||||||
|
<li>Go to the <a href="/user/index" th:href="@{/user/index}">secured pages</a></li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Login page</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="/css/main.css" th:href="@{/css/main.css}" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Login page</h1>
|
||||||
|
<p>Example: user / domain / password</p>
|
||||||
|
<p th:if="${param.error}" class="error">Invalid user, password, or domain</p>
|
||||||
|
<form th:action="@{/login}" method="post">
|
||||||
|
<label for="username">Username</label>:
|
||||||
|
<input class="formfield" type="text" id="username" name="username" autofocus="autofocus" /> <br />
|
||||||
|
<label for="domain">Domain</label>:
|
||||||
|
<input class="formfield" type="text" id="domain" name="domain" /> <br />
|
||||||
|
<label for="password">Password</label>:
|
||||||
|
<input class="formfield" type="password" id="password" name="password" /> <br />
|
||||||
|
<input type="submit" value="Log in" />
|
||||||
|
</form>
|
||||||
|
<p><a href="/index" th:href="@{/index}">Back to home page</a></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Spring Security - Login With Extra Fields</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="/css/main.css" th:href="@{/css/main.css}" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div th:replace="index::logout"></div>
|
||||||
|
<h1>This is a secured page!</h1>
|
||||||
|
<p><a href="/index" th:href="@{/index}">Back to home page</a></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue