Skip to content

Commit 561efe5

Browse files
committed
Update Fix SSL
1 parent e917238 commit 561efe5

File tree

15 files changed

+224
-233
lines changed

15 files changed

+224
-233
lines changed

ai-service/src/main/resources/application.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ server:
55
tomcat:
66
# Ngăn Tomcat chặn nuốt request lớn (giữ nguyên dữ liệu lớn)
77
max-swallow-size: -1
8-
ssl:
9-
enabled: true
10-
key-store: classpath:ssl/ai.p12
11-
key-store-type: PKCS12
12-
key-store-password: changeit
13-
key-alias: ai-https
14-
client-auth: need
15-
trust-store: classpath:ssl/truststore.p12
16-
trust-store-type: PKCS12
17-
trust-store-password: changeit
8+
# ssl:
9+
# enabled: true
10+
# key-store: classpath:ssl/ai.p12
11+
# key-store-type: PKCS12
12+
# key-store-password: changeit
13+
# key-alias: ai-https
14+
# client-auth: need
15+
# trust-store: classpath:ssl/truststore.p12
16+
# trust-store-type: PKCS12
17+
# trust-store-password: changeit
1818

1919
spring:
2020
application:
@@ -63,8 +63,8 @@ spring:
6363

6464
app:
6565
services:
66-
submission: https://localhost:8083/submission
66+
submission: http://localhost:8083/submission
6767
file:
6868
upload-dir: ./uploads
69-
public-base-url: https://localhost:8888/api/v1/ai
69+
public-base-url: http://localhost:8888/api/v1/ai
7070

chat-service/src/main/resources/application.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ app:
3838
event:
3939
profile-events: "profile-events"
4040
services:
41-
profile: https://localhost:8081/profile
42-
identity: https://localhost:8080/identity
43-
file: https://localhost:8082/file
41+
profile: http://localhost:8081/profile
42+
identity: http://localhost:8080/identity
43+
file: http://localhost:8082/file

coding-service/src/main/resources/application.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ server:
22
port: 8084
33
servlet:
44
context-path: /coding
5-
ssl:
6-
enabled: true
7-
key-store: classpath:ssl/coding.p12
8-
key-store-type: PKCS12
9-
key-store-password: changeit
10-
key-alias: coding-https
11-
client-auth: need
12-
trust-store: classpath:ssl/truststore.p12
13-
trust-store-type: PKCS12
14-
trust-store-password: changeit
5+
# ssl:
6+
# enabled: true
7+
# key-store: classpath:ssl/coding.p12
8+
# key-store-type: PKCS12
9+
# key-store-password: changeit
10+
# key-alias: coding-https
11+
# client-auth: need
12+
# trust-store: classpath:ssl/truststore.p12
13+
# trust-store-type: PKCS12
14+
# trust-store-password: changeit
1515

1616
grpc:
1717
server:

gateway-service/src/main/java/com/codecampus/gateway/configuration/client/WebClientConfiguration.java

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
package com.codecampus.gateway.configuration.client;
22

33
import com.codecampus.gateway.repository.client.IdentityClient;
4-
import io.netty.handler.ssl.SslContext;
5-
import io.netty.handler.ssl.SslContextBuilder;
6-
import java.io.InputStream;
7-
import java.security.KeyStore;
84
import java.util.List;
9-
import javax.net.ssl.KeyManagerFactory;
10-
import javax.net.ssl.TrustManagerFactory;
115
import org.springframework.context.annotation.Bean;
126
import org.springframework.context.annotation.Configuration;
13-
import org.springframework.core.io.ClassPathResource;
14-
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
157
import org.springframework.web.cors.CorsConfiguration;
168
import org.springframework.web.cors.reactive.CorsWebFilter;
179
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
1810
import org.springframework.web.reactive.function.client.WebClient;
1911
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
2012
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
21-
import reactor.netty.http.client.HttpClient;
2213

2314
/**
2415
* Lớp cấu hình các bean liên quan đến WebClient và CORS cho Gateway.
@@ -39,44 +30,47 @@ public class WebClientConfiguration {
3930
*/
4031
@Bean
4132
WebClient webClient(IdentityServiceProperties props) {
42-
try {
43-
// ---- KeyStore (client-cert) cho mTLS ----
44-
var ksRes = new ClassPathResource("ssl/gateway.p12");
45-
KeyStore ks = KeyStore.getInstance("PKCS12");
46-
try (InputStream is = ksRes.getInputStream()) {
47-
ks.load(is, "changeit".toCharArray());
48-
}
49-
KeyManagerFactory kmf = KeyManagerFactory.getInstance(
50-
KeyManagerFactory.getDefaultAlgorithm());
51-
kmf.init(ks, "changeit".toCharArray());
52-
53-
// ---- TrustStore (tin CA của server) ----
54-
var tsRes = new ClassPathResource("ssl/truststore.p12");
55-
KeyStore ts = KeyStore.getInstance("PKCS12");
56-
try (InputStream is = tsRes.getInputStream()) {
57-
ts.load(is, "changeit".toCharArray());
58-
}
59-
TrustManagerFactory tmf = TrustManagerFactory.getInstance(
60-
TrustManagerFactory.getDefaultAlgorithm());
61-
tmf.init(ts);
62-
63-
// ---- SSL context cho Reactor Netty ----
64-
SslContext sslContext = SslContextBuilder.forClient()
65-
.keyManager(kmf) // bắt buộc nếu Identity bật client-auth
66-
.trustManager(tmf)
67-
.build();
68-
69-
HttpClient httpClient = HttpClient.create()
70-
.secure(ssl -> ssl.sslContext(sslContext));
71-
72-
return WebClient.builder()
73-
.baseUrl(props.getBaseUrl()) // ví dụ: https://localhost:8080/identity
74-
.clientConnector(new ReactorClientHttpConnector(httpClient))
75-
.build();
76-
77-
} catch (Exception e) {
78-
throw new IllegalStateException("Cannot build WebClient with TLS/mTLS", e);
79-
}
33+
// try {
34+
// // ---- KeyStore (client-cert) cho mTLS ----
35+
// var ksRes = new ClassPathResource("ssl/gateway.p12");
36+
// KeyStore ks = KeyStore.getInstance("PKCS12");
37+
// try (InputStream is = ksRes.getInputStream()) {
38+
// ks.load(is, "changeit".toCharArray());
39+
// }
40+
// KeyManagerFactory kmf = KeyManagerFactory.getInstance(
41+
// KeyManagerFactory.getDefaultAlgorithm());
42+
// kmf.init(ks, "changeit".toCharArray());
43+
//
44+
// // ---- TrustStore (tin CA của server) ----
45+
// var tsRes = new ClassPathResource("ssl/truststore.p12");
46+
// KeyStore ts = KeyStore.getInstance("PKCS12");
47+
// try (InputStream is = tsRes.getInputStream()) {
48+
// ts.load(is, "changeit".toCharArray());
49+
// }
50+
// TrustManagerFactory tmf = TrustManagerFactory.getInstance(
51+
// TrustManagerFactory.getDefaultAlgorithm());
52+
// tmf.init(ts);
53+
//
54+
// // ---- SSL context cho Reactor Netty ----
55+
// SslContext sslContext = SslContextBuilder.forClient()
56+
// .keyManager(kmf) // bắt buộc nếu Identity bật client-auth
57+
// .trustManager(tmf)
58+
// .build();
59+
//
60+
// HttpClient httpClient = HttpClient.create()
61+
// .secure(ssl -> ssl.sslContext(sslContext));
62+
//
63+
// return WebClient.builder()
64+
// .baseUrl(props.getBaseUrl()) // ví dụ: https://localhost:8080/identity
65+
// .clientConnector(new ReactorClientHttpConnector(httpClient))
66+
// .build();
67+
//
68+
// } catch (Exception e) {
69+
// throw new IllegalStateException("Cannot build WebClient with TLS/mTLS", e);
70+
// }
71+
return WebClient.builder()
72+
.baseUrl(props.getBaseUrl())
73+
.build();
8074
}
8175

8276
/**

gateway-service/src/main/resources/application.yml

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
server:
22
port: 8888
3-
ssl:
4-
enabled: true
5-
key-store: classpath:ssl/gateway.p12
6-
key-store-type: PKCS12
7-
key-store-password: changeit
8-
key-alias: gateway-https
9-
client-auth: need
10-
trust-store: classpath:ssl/truststore.p12
11-
trust-store-type: PKCS12
12-
trust-store-password: changeit
3+
# ssl:
4+
# enabled: true
5+
# key-store: classpath:ssl/gateway.p12
6+
# key-store-type: PKCS12
7+
# key-store-password: changeit
8+
# key-alias: gateway-https
9+
# client-auth: need
10+
# trust-store: classpath:ssl/truststore.p12
11+
# trust-store-type: PKCS12
12+
# trust-store-password: changeit
1313
app:
1414
api-prefix: /api/v1
1515

@@ -18,27 +18,26 @@ spring:
1818
name: api-gateway
1919
cloud:
2020
gateway:
21-
# XỬ LÝ CORS TOÀN CỤC
22-
globalcors:
23-
add-to-simple-url-handler-mapping: true
24-
corsConfigurations:
25-
'[/**]':
26-
allowedOrigins:
27-
- http://localhost:4200
28-
allowedMethods: [ GET, POST, PUT, PATCH, DELETE, OPTIONS ]
29-
allowedHeaders: [ "*" ]
30-
allowCredentials: true
31-
httpclient:
32-
ssl:
33-
key-store: classpath:ssl/gateway.p12
34-
key-store-type: PKCS12
35-
key-store-password: changeit
36-
trusted-x509-certificates:
37-
- classpath:ssl/ca.crt
21+
# globalcors:
22+
# add-to-simple-url-handler-mapping: true
23+
# corsConfigurations:
24+
# '[/**]':
25+
# allowedOrigins:
26+
# - http://localhost:4200
27+
# allowedMethods: [ GET, POST, PUT, PATCH, DELETE, OPTIONS ]
28+
# allowedHeaders: [ "*" ]
29+
# allowCredentials: true
30+
# httpclient:
31+
# ssl:
32+
# key-store: classpath:ssl/gateway.p12
33+
# key-store-type: PKCS12
34+
# key-store-password: changeit
35+
# trusted-x509-certificates:
36+
# - classpath:ssl/ca.crt
3837
routes:
3938
- id: identity_service
4039
# uri: https://localhost:8080
41-
uri: https://localhost:8080
40+
uri: http://localhost:8080
4241
predicates:
4342
- Path=${app.api-prefix}/identity/**
4443
filters:
@@ -48,7 +47,7 @@ spring:
4847
routeId: identity_service
4948
- id: profile_service
5049
# uri: https://localhost:8081
51-
uri: https://localhost:8081
50+
uri: http://localhost:8081
5251
predicates:
5352
- Path=${app.api-prefix}/profile/**
5453
filters:
@@ -58,7 +57,7 @@ spring:
5857
routeId: profile_service
5958
- id: file_service
6059
# uri: https://localhost:80820
61-
uri: https://localhost:8082
60+
uri: http://localhost:8082
6261
predicates:
6362
- Path=${app.api-prefix}/file/**
6463
filters:
@@ -68,7 +67,7 @@ spring:
6867
routeId: file_service
6968
- id: submission_service
7069
# uri: https://localhost:8083
71-
uri: https://localhost:8083
70+
uri: http://localhost:8083
7271
predicates:
7372
- Path=${app.api-prefix}/submission/**
7473
filters:
@@ -78,7 +77,7 @@ spring:
7877
routeId: submission_service
7978
- id: coding_service
8079
# uri: https://localhost:8084
81-
uri: https://localhost:8084
80+
uri: http://localhost:8084
8281
predicates:
8382
- Path=${app.api-prefix}/coding/**
8483
filters:
@@ -88,7 +87,7 @@ spring:
8887
routeId: coding_service
8988
- id: quiz_service
9089
# uri: https://localhost:8085
91-
uri: https://localhost:8085
90+
uri: http://localhost:8085
9291
predicates:
9392
- Path=${app.api-prefix}/quiz/**
9493
filters:
@@ -98,7 +97,7 @@ spring:
9897
routeId: quiz_service
9998
- id: ai_service
10099
# uri: https://localhost:8086
101-
uri: https://localhost:8086
100+
uri: http://localhost:8086
102101
predicates:
103102
- Path=${app.api-prefix}/ai/**
104103
filters:
@@ -108,7 +107,7 @@ spring:
108107
routeId: ai_service
109108
- id: search_service
110109
# uri: https://localhost:8087
111-
uri: https://localhost:8087
110+
uri: http://localhost:8087
112111
predicates:
113112
- Path=${app.api-prefix}/search/**
114113
filters:
@@ -118,7 +117,7 @@ spring:
118117
routeId: search_service
119118
- id: notification_service
120119
# uri: https://localhost:8088
121-
uri: https://localhost:8088
120+
uri: http://localhost:8088
122121
predicates:
123122
- Path=${app.api-prefix}/notification/**
124123
filters:
@@ -128,7 +127,7 @@ spring:
128127
routeId: notification_service
129128
- id: chat_service
130129
# uri: https://localhost:8089
131-
uri: https://localhost:8089
130+
uri: http://localhost:8089
132131
predicates:
133132
- Path=${app.api-prefix}/chat/**
134133
filters:
@@ -138,7 +137,7 @@ spring:
138137
routeId: chat_service
139138
- id: post_service
140139
# uri: https://localhost:8090
141-
uri: https://localhost:8090
140+
uri: http://localhost:8090
142141
predicates:
143142
- Path=${app.api-prefix}/post/**
144143
filters:
@@ -148,7 +147,7 @@ spring:
148147
routeId: post_service
149148
- id: payment_service
150149
# uri: https://localhost:8091
151-
uri: https://localhost:8091
150+
uri: http://localhost:8091
152151
predicates:
153152
- Path=${app.api-prefix}/payment/**
154153
filters:
@@ -158,7 +157,7 @@ spring:
158157
routeId: payment_service
159158
- id: organization_service
160159
# uri: https://localhost:8092
161-
uri: https://localhost:8092
160+
uri: http://localhost:8092
162161
predicates:
163162
- Path=${app.api-prefix}/org/**
164163
filters:
@@ -169,7 +168,7 @@ spring:
169168

170169
identity:
171170
service:
172-
base-url: https://localhost:8080/identity
171+
base-url: http://localhost:8080/identity
173172

174173
# Cấu hình rate limiter
175174
rate-limiter:

0 commit comments

Comments
 (0)