improvements, additional security dialect

This commit is contained in:
kwandzel 2018-02-17 16:59:50 +01:00
parent 6642fc53a4
commit 77735a57fd
4 changed files with 11 additions and 9 deletions

View File

@ -30,9 +30,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth auth.inMemoryAuthentication()
.inMemoryAuthentication() .withUser("user").password("password").roles("USER").and()
.withUser("user").password("password").roles("USER").and() .withUser("admin").password("admin").roles("ADMIN");
.withUser("admin").password("admin").roles("ADMIN");
} }
} }

View File

@ -5,17 +5,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Controller @Controller
public class ViewController { public class ViewController {
@RequestMapping("/login") @RequestMapping("/login")
public String login() { public String login() {
return "login"; return "login";
} }
@RequestMapping({"/index", "/"}) @RequestMapping({ "/index", "/" })
public String index() { public String index() {
return "index"; return "index";
} }
@RequestMapping("/loginError") @RequestMapping("/loginError")
public String loginError() { public String loginError() {
return "loginError"; return "loginError";

View File

@ -8,5 +8,8 @@
<p>Spring Security Thymeleaf tutorial</p> <p>Spring Security Thymeleaf tutorial</p>
<div sec:authorize="hasRole('USER')">Text visible to user.</div> <div sec:authorize="hasRole('USER')">Text visible to user.</div>
<div sec:authorize="hasRole('ADMIN')">Text visible to admin.</div> <div sec:authorize="hasRole('ADMIN')">Text visible to admin.</div>
<div sec:authorize="isAuthenticated()">Text visible only to authenticated users.</div>
Authenticated username: <div sec:authentication="name"></div>
Authenticated user roles: <div sec:authentication="principal.authorities"></div>
</body> </body>
</html> </html>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
<title>Insert title here</title> <title>Custom Login Page</title>
</head> </head>
<body> <body>
<h2>Custom Login Page</h2> <h2>Custom Login Page</h2>