-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6e1213
commit 2e8984f
Showing
4 changed files
with
74 additions
and
0 deletions.
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/libraryman_api/security/LoginController.java
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,4 +1,20 @@ | ||
package com.libraryman_api.security; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.security.Principal; | ||
|
||
@RestController | ||
public class LoginController { | ||
|
||
@GetMapping("/api/ajay") | ||
public String login(Principal principal) { | ||
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | ||
System.out.println("Principal Name: " + principal.getName()); | ||
System.out.println("Principal: " + principal); | ||
|
||
return "Hello World"; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/libraryman_api/security/PasswordEncoder.java
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,14 @@ | ||
package com.libraryman_api.security; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
|
||
@Configuration | ||
public class PasswordEncoder { | ||
|
||
@Bean | ||
public BCryptPasswordEncoder bCryptPasswordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/libraryman_api/security/WebConfiguration.java
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,33 @@ | ||
package com.libraryman_api.security; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpMethod; | ||
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.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
import static com.libraryman_api.member.Role.ADMIN; | ||
import static org.springframework.security.config.Customizer.withDefaults; | ||
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS; | ||
|
||
@Configuration | ||
@EnableWebSecurity(debug = true) // Do not use (debug=true) in a production system! as this contain sensitive information. | ||
public class WebConfiguration { | ||
|
||
@Bean | ||
public SecurityFilterChain web(HttpSecurity http) throws Exception { | ||
http | ||
.csrf(AbstractHttpConfigurer::disable) | ||
.authorizeHttpRequests((request) -> request | ||
// make sure it is in order to access the proper Url | ||
|
||
.requestMatchers("/signup").permitAll() | ||
.requestMatchers("/login").permitAll() | ||
) | ||
// .sessionManagement(session -> session.sessionCreationPolicy(STATELESS)) | ||
.formLogin(withDefaults()); | ||
return http.build(); | ||
} | ||
} |