added admin page

This commit is contained in:
Zastian Pretorius
2022-08-29 14:14:38 +01:00
parent a4b271e030
commit 7ab3526d50
8 changed files with 58 additions and 1 deletions

View File

@@ -40,7 +40,9 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers( http.authorizeRequests()
.antMatchers("/admin").hasRole("ADMIN")
.antMatchers(
"/registration**", "/registration**",
"/js/**", "/js/**",
"/css/**", "/css/**",
@@ -57,6 +59,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login?logout") .logoutSuccessUrl("/login?logout")
.permitAll(); .permitAll();
} }
} }

View File

@@ -15,4 +15,9 @@ public class MainController {
public String home() { public String home() {
return "index"; return "index";
} }
@GetMapping("/admin")
public String admin() {
return "admin";
}
} }

View File

@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="ISO-8859-1">
<title>Registration and Login App</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
</head>
<body>
<!-- create navigation bar ( header) -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed"
data-toggle="collapse" data-target="#navbar" aria-expanded="false"
aria-controls="navbar">
<span class="sr-only">Toggle navigation</span> <span
class="icon-bar"></span> <span class="icon-bar"></span> <span
class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#" th:href="@{/}">Registration and
Login Module</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li sec:authorize="isAuthenticated()"><a th:href="@{/logout}">Logout</a></li>
</ul>
</div>
</div>
</nav>
<br>
<br>
<div class="container">
<h1>The good shit</h1>
Welcome <span sec:authentication="principal.username"> Admin</span>
</div>
</body>
</html>

View File

@@ -41,6 +41,8 @@
<h1>Registration and Login with Spring Boot, Spring Security, <h1>Registration and Login with Spring Boot, Spring Security,
Thymeleaf, Hibernate and MySQL</h1> Thymeleaf, Hibernate and MySQL</h1>
Welcome <span sec:authentication="principal.username"> User</span> Welcome <span sec:authentication="principal.username"> User</span>
<button type="button" class="btn btn-primary"
th:href="@{/admin}">admin</button>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -41,6 +41,8 @@
<h1>Registration and Login with Spring Boot, Spring Security, <h1>Registration and Login with Spring Boot, Spring Security,
Thymeleaf, Hibernate and MySQL</h1> Thymeleaf, Hibernate and MySQL</h1>
Welcome <span sec:authentication="principal.username"> User</span> Welcome <span sec:authentication="principal.username"> User</span>
<button type="button" class="btn btn-primary"
th:href="@{/admin}">admin</button>
</div> </div>
</body> </body>
</html> </html>