-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spring Security: in-memory user store
- Loading branch information
1 parent
e657889
commit cb9c028
Showing
10 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package tacos.security; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
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.crypto.factory.PasswordEncoderFactories; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
|
||
@SuppressWarnings("deprecation") | ||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfig extends WebSecurityConfigurerAdapter{ | ||
|
||
@Override | ||
protected void configure(AuthenticationManagerBuilder auth) throws Exception { | ||
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); | ||
auth.inMemoryAuthentication() | ||
.withUser("holo") | ||
.password(encoder.encode("thewisewolf")) | ||
.authorities("ROLE_USER") | ||
.and() | ||
.withUser("mai") | ||
.password(encoder.encode("bunnygirlsenpai")) | ||
.authorities("ROLE_USER"); | ||
System.out.println(org.springframework.security.core.SpringSecurityCoreVersion.getVersion()); | ||
|
||
} | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.csrf().disable().authorizeRequests() | ||
.antMatchers("/design", "/orders").hasRole("USER") | ||
.antMatchers("/", "/**").permitAll() | ||
.and() | ||
.formLogin().loginPage("/login") | ||
.defaultSuccessUrl("/design", true) | ||
.and() | ||
.logout().logoutSuccessUrl("/"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
.validationError { | ||
color: red; | ||
} | ||
.header-container { | ||
text-align: left; | ||
position: relative; | ||
color: white; | ||
} | ||
.header-container .header-bar { | ||
position: absolute; | ||
right: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="header-container" | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:th="http://www.thymeleaf.org" | ||
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"> | ||
<div class="header-bar"> | ||
<th:block sec:authorize="isAuthenticated()"> | ||
<form method="POST" th:action="@{/logout}"> | ||
<input type="submit" value="Logout"/> | ||
</form> | ||
</th:block> | ||
|
||
<th:block sec:authorize="!isAuthenticated()"> | ||
<form method="GET" th:action="@{/login}"> | ||
<input type="submit" value="Login"/> | ||
</form> | ||
</th:block> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<title>Taco Cloud</title> | ||
<link rel="stylesheet" th:href="@{/styles.css?version=1}" /> | ||
</head> | ||
|
||
<body> | ||
<h1>Login</h1> | ||
<img th:src="@{/images/TacoCloud.png}"/> | ||
|
||
<div class="validationError" th:if="${error}"> | ||
Unable to login. Check your username and password. | ||
</div> | ||
|
||
<p>New here? Click | ||
<a th:href="@{/register}">here</a> | ||
to register. | ||
</p> | ||
|
||
<form method="POST" th:action="@{/login}" id="loginForm"> | ||
<label for="username">Username: </label> | ||
<input type="text" name="username" id="username"/><br/> | ||
|
||
<label for="password">Password: </label> | ||
<input type="password" name="password" id="password"/><br/> | ||
|
||
<input type="submit" value="Login"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters