Skip to content

Commit 6226ad4

Browse files
committed
Merge branch 'grad-release'
2 parents 0883278 + 9e7867e commit 6226ad4

File tree

12 files changed

+469
-36
lines changed

12 files changed

+469
-36
lines changed

.github/workflows/on.pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
distribution: 'corretto'
2727
java-version: 18
28-
- uses: actions/cache@v1
28+
- uses: actions/cache@v4
2929
with:
3030
path: ~/.m2/repository
3131
key: ${{ runner.os }}-maven-5Jun-${{ hashFiles('**/pom.xml') }}

api/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ca.bc.gov.educ</groupId>
88
<artifactId>educ-grad-student-graduation-api</artifactId>
9-
<version>1.8.47</version>
9+
<version>1.8.48</version>
1010
<name>educ-grad-student-graduation-api</name>
1111
<description>Ministry of Education GRAD STUDENT GRADUATION API</description>
1212

@@ -29,7 +29,8 @@
2929
src/main/java/ca/bc/gov/educ/api/studentgraduation/util/**,
3030
src/main/java/ca/bc/gov/educ/api/studentgraduation/repository/**,
3131
src/main/java/ca/bc/gov/educ/api/studentgraduation/config/**,
32-
src/test/java/ca/bc/gov/educ/api/studentgraduation/**,
32+
src/main/java/ca/bc/gov/educ/api/studentgraduation/controller/APIMetadataController.java,
33+
src/test/java/ca/bc/gov/educ/api/studentgraduation/**
3334
</sonar.coverage.exclusions>
3435
<!--GRAD2-1899, upgrading to spring boot 3.0.2-->
3536
<java.version>18</java.version>

api/src/main/java/ca/bc/gov/educ/api/studentgraduation/config/GradStudentGraduationConfig.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
package ca.bc.gov.educ.api.studentgraduation.config;
22

3+
import ca.bc.gov.educ.api.studentgraduation.util.EducGradStudentGraduationApiConstants;
4+
import ca.bc.gov.educ.api.studentgraduation.util.LogHelper;
5+
import ca.bc.gov.educ.api.studentgraduation.util.ThreadLocalStateUtil;
36
import org.modelmapper.ModelMapper;
7+
import org.springframework.beans.factory.annotation.Autowired;
48
import org.springframework.boot.web.client.RestTemplateBuilder;
59
import org.springframework.context.annotation.Bean;
610
import org.springframework.context.annotation.Configuration;
711
import org.springframework.web.client.RestTemplate;
12+
import org.springframework.web.reactive.function.client.ClientRequest;
13+
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
814
import org.springframework.web.reactive.function.client.WebClient;
915
import reactor.netty.http.client.HttpClient;
1016

1117
@Configuration
1218
public class GradStudentGraduationConfig {
1319

20+
EducGradStudentGraduationApiConstants constants;
21+
LogHelper logHelper;
22+
23+
@Autowired
24+
public GradStudentGraduationConfig(EducGradStudentGraduationApiConstants constants, LogHelper logHelper) {
25+
this.constants = constants;
26+
this.logHelper = logHelper;
27+
}
28+
1429
@Bean
1530
public ModelMapper modelMapper() {
1631

@@ -24,13 +39,39 @@ public ModelMapper modelMapper() {
2439
public WebClient webClient() {
2540
HttpClient client = HttpClient.create();
2641
client.warmup().block();
27-
return WebClient.builder().build();
42+
return WebClient.builder()
43+
.filter(setRequestHeaders())
44+
.filter(this.log())
45+
.build();
2846
}
2947

3048
@Bean
3149
public RestTemplate restTemplate(RestTemplateBuilder builder) {
3250
return builder.build();
3351
}
3452

53+
private ExchangeFilterFunction setRequestHeaders() {
54+
return (clientRequest, next) -> {
55+
ClientRequest modifiedRequest = ClientRequest.from(clientRequest)
56+
.header(EducGradStudentGraduationApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID())
57+
.header(EducGradStudentGraduationApiConstants.USER_NAME, ThreadLocalStateUtil.getCurrentUser())
58+
.header(EducGradStudentGraduationApiConstants.REQUEST_SOURCE, EducGradStudentGraduationApiConstants.API_NAME)
59+
.build();
60+
return next.exchange(modifiedRequest);
61+
};
62+
}
63+
64+
private ExchangeFilterFunction log() {
65+
return (clientRequest, next) -> next
66+
.exchange(clientRequest)
67+
.doOnNext((clientResponse -> logHelper.logClientHttpReqResponseDetails(
68+
clientRequest.method(),
69+
clientRequest.url().toString(),
70+
clientResponse.statusCode().value(),
71+
clientRequest.headers().get(EducGradStudentGraduationApiConstants.CORRELATION_ID),
72+
clientRequest.headers().get(EducGradStudentGraduationApiConstants.REQUEST_SOURCE),
73+
constants.isSplunkLogHelperEnabled())
74+
));
75+
}
3576

3677
}

api/src/main/java/ca/bc/gov/educ/api/studentgraduation/config/RequestInterceptor.java

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
1414
import org.springframework.stereotype.Component;
1515
import org.springframework.web.servlet.AsyncHandlerInterceptor;
16-
/*GRAD2-1899, commenting the below line as this import is not in use and showing it as error*/
17-
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
1816

1917
import java.time.Instant;
18+
import java.util.UUID;
2019

2120
@Component
2221
public class RequestInterceptor implements AsyncHandlerInterceptor {
2322

24-
@Autowired
2523
GradValidation validation;
24+
EducGradStudentGraduationApiConstants constants;
25+
LogHelper logHelper;
2626

2727
@Autowired
28-
EducGradStudentGraduationApiConstants constants;
28+
public RequestInterceptor(GradValidation validation, EducGradStudentGraduationApiConstants constants, LogHelper logHelper) {
29+
this.validation = validation;
30+
this.constants = constants;
31+
this.logHelper = logHelper;
32+
}
2933

3034
@Override
3135
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
@@ -37,21 +41,30 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
3741
validation.clear();
3842
// correlationID
3943
val correlationID = request.getHeader(EducGradStudentGraduationApiConstants.CORRELATION_ID);
40-
if (correlationID != null) {
41-
ThreadLocalStateUtil.setCorrelationID(correlationID);
44+
ThreadLocalStateUtil.setCorrelationID(correlationID != null ? correlationID : UUID.randomUUID().toString());
45+
46+
//Request Source
47+
val requestSource = request.getHeader(EducGradStudentGraduationApiConstants.REQUEST_SOURCE);
48+
if(requestSource != null) {
49+
ThreadLocalStateUtil.setRequestSource(requestSource);
4250
}
4351

44-
// username
45-
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
46-
if (auth instanceof JwtAuthenticationToken) {
47-
JwtAuthenticationToken authenticationToken = (JwtAuthenticationToken) auth;
48-
Jwt jwt = (Jwt) authenticationToken.getCredentials();
49-
String username = JwtUtil.getName(jwt);
50-
if (username != null) {
51-
ThreadLocalStateUtil.setCurrentUser(username);
52+
// Header userName
53+
val userName = request.getHeader(EducGradStudentGraduationApiConstants.USER_NAME);
54+
if (userName != null) {
55+
ThreadLocalStateUtil.setCurrentUser(userName);
56+
}
57+
else {
58+
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
59+
if (auth instanceof JwtAuthenticationToken) {
60+
JwtAuthenticationToken authenticationToken = (JwtAuthenticationToken) auth;
61+
Jwt jwt = (Jwt) authenticationToken.getCredentials();
62+
String username = JwtUtil.getName(jwt);
63+
if (username != null) {
64+
ThreadLocalStateUtil.setCurrentUser(username);
65+
}
5266
}
5367
}
54-
5568
return true;
5669
}
5770

@@ -65,11 +78,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
6578
*/
6679
@Override
6780
public void afterCompletion(@NonNull final HttpServletRequest request, final HttpServletResponse response, @NonNull final Object handler, final Exception ex) {
68-
LogHelper.logServerHttpReqResponseDetails(request, response, constants.isSplunkLogHelperEnabled());
69-
val correlationID = request.getHeader(EducGradStudentGraduationApiConstants.CORRELATION_ID);
70-
if (correlationID != null) {
71-
response.setHeader(EducGradStudentGraduationApiConstants.CORRELATION_ID, request.getHeader(EducGradStudentGraduationApiConstants.CORRELATION_ID));
72-
}
81+
logHelper.logServerHttpReqResponseDetails(request, response, constants.isSplunkLogHelperEnabled());
7382
// clear
7483
ThreadLocalStateUtil.clear();
7584
}

api/src/main/java/ca/bc/gov/educ/api/studentgraduation/config/WebSecurityConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
2828
"/api/v1/api-docs/**",
2929
"/actuator/health",
3030
"/actuator/prometheus",
31-
"/health")
31+
"/health",
32+
"/api/v1/metadata")
3233
.permitAll()
3334
.anyRequest().authenticated()
3435
)

0 commit comments

Comments
 (0)