Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOSIP-38917] Update TransactionServiceSecurityConfig.java #1983

Open
wants to merge 1 commit into
base: release-1.3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand Down Expand Up @@ -62,7 +63,13 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(csrf -> csrf.disable())
.exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedEntryPoint()))
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests((authz) -> authz.anyRequest().authenticated())
.authorizeHttpRequests(authz -> authz
.requestMatchers(HttpMethod.GET, "/registrationprocessor/v1/registrationtransaction/**").authenticated() // Allow GET for transactions
.requestMatchers(HttpMethod.POST, "/registrationprocessor/v1/registrationtransaction/**").authenticated() // Require authentication for POST
.requestMatchers(HttpMethod.PUT, "/registrationprocessor/v1/registrationtransaction/**").authenticated() // Require authentication for PUT
.requestMatchers(HttpMethod.DELETE, "/transactions/**").denyAll() // Block DELETE globally
.anyRequest().authenticated() // Secure all other requests
)
.userDetailsService(userDetailsService());

return http.build();
Expand Down Expand Up @@ -90,4 +97,4 @@ public UserDetailsService userDetailsService() {
Arrays.asList(new SimpleGrantedAuthority("ROLE_REGISTRATION_ADMIN"))));
return new InMemoryUserDetailsManager(users);
}
}
}