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

Restrict access for POST endpoints to specific role. (if defined) #679

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -67,6 +67,9 @@ public class ApplicationProperties extends GenericApplicationProperties {
@Value("${metastore.metadata.schemaRegistries: }")
private List<String> schemaRegistries;

@Value("${metastore.metadata.schemaRegistries: }")
private String postEnabledForRole;

@Value("${metastore.javers.scope:20}")
private int maxJaversScope;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ public class WebSecurityConfig {
private String allowedOriginPattern;

private static final String[] AUTH_WHITELIST_SWAGGER_UI = {
// -- Swagger UI v2
"/v2/api-docs",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**",
// -- Swagger UI v3 (OpenAPI)
"/v3/api-docs/**",
"/swagger-ui/**"
// other public endpoints of your API may be appended to this array
// -- Swagger UI v2
"/v2/api-docs",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**",
// -- Swagger UI v3 (OpenAPI)
"/v3/api-docs/**",
"/swagger-ui/**"
// other public endpoints of your API may be appended to this array
};

public WebSecurityConfig() {
Expand All @@ -89,16 +89,27 @@ public WebSecurityConfig() {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
HttpSecurity httpSecurity = http.authorizeHttpRequests(
authorize -> authorize.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll().
requestMatchers("/oaipmh").permitAll().
requestMatchers("/static/**").permitAll().
requestMatchers(AUTH_WHITELIST_SWAGGER_UI).permitAll().
requestMatchers(EndpointRequest.to(
InfoEndpoint.class,
HealthEndpoint.class
)).permitAll().
requestMatchers(EndpointRequest.toAnyEndpoint()).hasAnyRole("ANONYMOUS", "ADMIN", "ACTUATOR", "SERVICE_WRITE").
requestMatchers("/**").authenticated()).
authorize -> {
authorize.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll().
requestMatchers("/oaipmh").permitAll().
requestMatchers("/static/**").permitAll().
requestMatchers(AUTH_WHITELIST_SWAGGER_UI).permitAll().
requestMatchers(EndpointRequest.to(
InfoEndpoint.class,
HealthEndpoint.class
)).permitAll();
logger.info("Post enabled for all groups!?");
if (!applicationProperties.getPostEnabledForRole().isBlank()) {
logger.info("Post enabled for group '{}'!", applicationProperties.getPostEnabledForRole());
authorize.
requestMatchers(HttpMethod.POST, "/api/v1/schemas/").hasAnyRole(applicationProperties.getPostEnabledForRole()).
requestMatchers(HttpMethod.POST, "/api/v2/schemas/").hasAnyRole(applicationProperties.getPostEnabledForRole()).
requestMatchers(HttpMethod.POST, "/api/v1/metadata/").hasAnyRole(applicationProperties.getPostEnabledForRole()).
requestMatchers(HttpMethod.POST, "/api/v2/metadata/").hasAnyRole(applicationProperties.getPostEnabledForRole());
}
authorize.requestMatchers(EndpointRequest.toAnyEndpoint()).hasAnyRole("ANONYMOUS", "ADMIN", "ACTUATOR", "SERVICE_WRITE").
requestMatchers("/**").authenticated();
}).
sessionManagement(
session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
if (!enableCsrf) {
Expand Down
Loading
Loading