Skip to content

Commit

Permalink
Merge pull request #28 from stevensblueprint/fix/security_config
Browse files Browse the repository at this point in the history
Spring boot Profile security
  • Loading branch information
miguel-merlin authored Jan 2, 2025
2 parents 0c5c01f + 61da9c8 commit a0bc2d3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/com/sarapis/orservice/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
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;
Expand All @@ -11,11 +12,22 @@
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
@Profile("prod")
public SecurityFilterChain prodSecurityFilterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests(authorize ->
authorize
.requestMatchers("/actuator/**").permitAll()
.requestMatchers("/").permitAll()
.anyRequest().authenticated())
.csrf(AbstractHttpConfigurer::disable).build();
}

@Bean
@Profile("dev")
public SecurityFilterChain devSecurityFilterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests(authorize ->
authorize
.requestMatchers("/**").permitAll()
).build();
}
}

0 comments on commit a0bc2d3

Please sign in to comment.