Skip to content

Feat/usability updates #211

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

Merged
merged 4 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: add possibility to disable specific endpoints
  • Loading branch information
ludomikula committed Jun 18, 2023
commit 4768b4bd16adbbe38f9712c4c2fc45a6dc821197
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.Set;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.lowcoder.sdk.constants.WorkspaceMode;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;

import lombok.Data;
Expand Down Expand Up @@ -63,6 +65,8 @@ public static class Security {
// support of docker env file.
private String corsAllowedDomainString;

private List<ApiEndpoint> forbiddenEndpoints;

public List<String> getAllCorsAllowedDomains() {
List<String> all = new ArrayList<>();
if (CollectionUtils.isNotEmpty(corsAllowedDomains)) {
Expand All @@ -74,8 +78,19 @@ public List<String> getAllCorsAllowedDomains() {
}
return all;
}

public List<ApiEndpoint> getForbiddenEndpoints()
{
return ListUtils.emptyIfNull(forbiddenEndpoints);
}
}

@Data
public static class ApiEndpoint {
private HttpMethod method;
private String uri;
}

@Data
public static class Workspace {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsConfigurationSource;
Expand Down Expand Up @@ -62,8 +63,17 @@ public class SecurityConfig {
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {


http.cors()
if (!commonConfig.getSecurity().getForbiddenEndpoints().isEmpty())
{
http.authorizeExchange()
.matchers(
commonConfig.getSecurity().getForbiddenEndpoints().stream()
.map(apiEndpoint -> ServerWebExchangeMatchers.pathMatchers(apiEndpoint.getMethod(), apiEndpoint.getUri()))
.toArray(size -> new ServerWebExchangeMatcher[size])
).denyAll();
}

http.cors()
.configurationSource(buildCorsConfigurationSource())
.and()
.csrf().disable()
Expand Down Expand Up @@ -137,6 +147,7 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http.build();
}


/**
* enable CORS
*/
Expand Down