[BAEL-1556]:fixes according to a review

This commit is contained in:
kwandzel 2018-02-19 22:45:40 +01:00
parent b021e6b01a
commit 94421b7d38
6 changed files with 39 additions and 45 deletions

View File

@ -12,26 +12,32 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll().failureUrl("/loginError").successForwardUrl("/index")
.and()
.loginPage("/login")
.permitAll()
.successForwardUrl("/index")
.and()
.logout()
.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login");
.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("admin").roles("ADMIN");
.withUser("user")
.password("password")
.roles("USER")
.and()
.withUser("admin")
.password("admin")
.roles("ADMIN");
}
}

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringSecurityThymeleafApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSecurityThymeleafApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(SpringSecurityThymeleafApplication.class, args);
}
}

View File

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

View File

@ -8,8 +8,11 @@
<p>Spring Security Thymeleaf tutorial</p>
<div sec:authorize="hasRole('USER')">Text visible to user.</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>
<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>
</html>

View File

@ -7,9 +7,9 @@
<h2>Custom Login Page</h2>
<form th:action="@{/login}" method="post">
<label for="username">Username</label>: <input type="text"
id="username" name="username" autofocus="autofocus" /> <br /> <label
id="username" name="username" autofocus="autofocus" /> <label
for="password">Password</label>: <input type="password" id="password"
name="password" /> <br /> <input type="submit" value="Log in" />
name="password" /><input type="submit" value="Log in" />
</form>
</body>
</html>

View File

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Login error page</title>
</head>
<body>
<h2>Login Error Page</h2>
</body>
</html>