File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
lowcoder-sdk/src/main/java/org/lowcoder/sdk/config
lowcoder-server/src/main/java/org/lowcoder/api/framework/security Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 88import java .util .Set ;
99
1010import org .apache .commons .collections4 .CollectionUtils ;
11+ import org .apache .commons .collections4 .ListUtils ;
1112import org .apache .commons .lang3 .StringUtils ;
1213import org .lowcoder .sdk .constants .WorkspaceMode ;
1314import org .springframework .boot .context .properties .ConfigurationProperties ;
15+ import org .springframework .http .HttpMethod ;
1416import org .springframework .stereotype .Component ;
1517
1618import lombok .Data ;
@@ -63,6 +65,8 @@ public static class Security {
6365 // support of docker env file.
6466 private String corsAllowedDomainString ;
6567
68+ private List <ApiEndpoint > forbiddenEndpoints ;
69+
6670 public List <String > getAllCorsAllowedDomains () {
6771 List <String > all = new ArrayList <>();
6872 if (CollectionUtils .isNotEmpty (corsAllowedDomains )) {
@@ -74,8 +78,19 @@ public List<String> getAllCorsAllowedDomains() {
7478 }
7579 return all ;
7680 }
81+
82+ public List <ApiEndpoint > getForbiddenEndpoints ()
83+ {
84+ return ListUtils .emptyIfNull (forbiddenEndpoints );
85+ }
7786 }
7887
88+ @ Data
89+ public static class ApiEndpoint {
90+ private HttpMethod method ;
91+ private String uri ;
92+ }
93+
7994 @ Data
8095 public static class Workspace {
8196
Original file line number Diff line number Diff line change 3434import org .springframework .security .config .web .server .ServerHttpSecurity ;
3535import org .springframework .security .web .server .SecurityWebFilterChain ;
3636import org .springframework .security .web .server .ServerAuthenticationEntryPoint ;
37+ import org .springframework .security .web .server .util .matcher .ServerWebExchangeMatcher ;
3738import org .springframework .security .web .server .util .matcher .ServerWebExchangeMatchers ;
3839import org .springframework .web .cors .CorsConfiguration ;
3940import org .springframework .web .cors .reactive .CorsConfigurationSource ;
@@ -62,8 +63,17 @@ public class SecurityConfig {
6263 @ Bean
6364 public SecurityWebFilterChain securityWebFilterChain (ServerHttpSecurity http ) {
6465
65-
66- http .cors ()
66+ if (!commonConfig .getSecurity ().getForbiddenEndpoints ().isEmpty ())
67+ {
68+ http .authorizeExchange ()
69+ .matchers (
70+ commonConfig .getSecurity ().getForbiddenEndpoints ().stream ()
71+ .map (apiEndpoint -> ServerWebExchangeMatchers .pathMatchers (apiEndpoint .getMethod (), apiEndpoint .getUri ()))
72+ .toArray (size -> new ServerWebExchangeMatcher [size ])
73+ ).denyAll ();
74+ }
75+
76+ http .cors ()
6777 .configurationSource (buildCorsConfigurationSource ())
6878 .and ()
6979 .csrf ().disable ()
@@ -137,6 +147,7 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
137147 return http .build ();
138148 }
139149
150+
140151 /**
141152 * enable CORS
142153 */
You can’t perform that action at this time.
0 commit comments