-
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.
- Loading branch information
Showing
5 changed files
with
118 additions
and
23 deletions.
There are no files selected for viewing
27 changes: 15 additions & 12 deletions
27
backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.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,34 +1,37 @@ | ||
package com.greenfoxacademy.backend.config; | ||
|
||
import static org.springframework.security.config.Customizer.withDefaults; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; | ||
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.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
|
||
|
||
/** | ||
* To give security permission to all endpoints. | ||
*/ | ||
@Configuration | ||
@EnableWebSecurity(debug = true) | ||
@EnableWebSecurity | ||
@EnableMethodSecurity(securedEnabled = true) | ||
public class SecurityConfig { | ||
|
||
/** | ||
* To give security permission to all endpoints. | ||
*/ | ||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
// @formatter:off | ||
http | ||
.authorizeHttpRequests((authorize) -> authorize | ||
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { | ||
return httpSecurity | ||
.csrf(AbstractHttpConfigurer::disable) | ||
.cors(AbstractHttpConfigurer::disable) | ||
.authorizeHttpRequests(auth -> auth | ||
.anyRequest().permitAll() | ||
) | ||
.httpBasic(withDefaults()) | ||
.formLogin(withDefaults()); | ||
// @formatter:on | ||
return http.build(); | ||
.sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
.build(); | ||
} | ||
} | ||
} | ||
|
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
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