Skip to content

Commit a839beb

Browse files
committed
enable anonymous api
1 parent 79f8f03 commit a839beb

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/security/SecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
145145
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.ORGANIZATION_URL + "/*/datasourceTypes"), // datasource types
146146
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.ORGANIZATION_URL + "/byuser/*"),
147147
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.DATASOURCE_URL + "/jsDatasourcePlugins"),
148+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.NPM_REGISTRY + "/**"),
148149
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/api/docs/**")
149150
)
150151
.permitAll()

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/npm/PrivateNpmRegistryController.java

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,44 @@ public Mono<ResponseEntity<Resource>> getNpmPackageAsset(String applicationId, S
4444

4545
@NotNull
4646
private Mono<ResponseEntity<Resource>> forwardToNodeService(String applicationId, String path, String prefix) {
47+
4748
String withoutLeadingSlash = path.startsWith("/") ? path.substring(1) : path;
48-
return applicationServiceImpl.findById(applicationId).flatMap(application -> organizationService.getById(application.getOrganizationId())).flatMap(orgMember -> organizationService.getOrgCommonSettings(orgMember.getId()).flatMap(organizationCommonSettings -> {
49-
Map<String, Object> config = Map.of("npmRegistries", organizationCommonSettings.get("npmRegistries"), "workspaceId", orgMember.getId());
50-
return WebClientBuildHelper.builder()
51-
.systemProxy()
52-
.build()
53-
.post()
54-
.uri(nodeServerHelper.createUri(prefix + "/" + withoutLeadingSlash))
55-
.contentType(MediaType.APPLICATION_JSON)
56-
.body(BodyInserters.fromValue(config))
57-
.retrieve().toEntity(Resource.class)
58-
.map(response -> {
59-
return ResponseEntity
60-
.status(response.getStatusCode())
61-
.headers(response.getHeaders())
62-
.body(response.getBody());
63-
});
64-
}));
49+
if(applicationId.equals("none")) {
50+
return sessionUserService.getVisitorOrgMemberCache().flatMap(orgMember -> organizationService.getOrgCommonSettings(orgMember.getOrgId()).flatMap(organizationCommonSettings -> {
51+
Map<String, Object> config = Map.of("npmRegistries", organizationCommonSettings.get("npmRegistries"), "workspaceId", orgMember.getOrgId());
52+
return WebClientBuildHelper.builder()
53+
.systemProxy()
54+
.build()
55+
.post()
56+
.uri(nodeServerHelper.createUri(prefix + "/" + withoutLeadingSlash))
57+
.contentType(MediaType.APPLICATION_JSON)
58+
.body(BodyInserters.fromValue(config))
59+
.retrieve().toEntity(Resource.class)
60+
.map(response -> {
61+
return ResponseEntity
62+
.status(response.getStatusCode())
63+
.headers(response.getHeaders())
64+
.body(response.getBody());
65+
});
66+
}));
67+
} else{
68+
return applicationServiceImpl.findById(applicationId).flatMap(application -> organizationService.getById(application.getOrganizationId())).flatMap(orgMember -> organizationService.getOrgCommonSettings(orgMember.getId()).flatMap(organizationCommonSettings -> {
69+
Map<String, Object> config = Map.of("npmRegistries", organizationCommonSettings.get("npmRegistries"), "workspaceId", orgMember.getId());
70+
return WebClientBuildHelper.builder()
71+
.systemProxy()
72+
.build()
73+
.post()
74+
.uri(nodeServerHelper.createUri(prefix + "/" + withoutLeadingSlash))
75+
.contentType(MediaType.APPLICATION_JSON)
76+
.body(BodyInserters.fromValue(config))
77+
.retrieve().toEntity(Resource.class)
78+
.map(response -> {
79+
return ResponseEntity
80+
.status(response.getStatusCode())
81+
.headers(response.getHeaders())
82+
.body(response.getBody());
83+
});
84+
}));
85+
}
6586
}
6687
}

0 commit comments

Comments
 (0)