Skip to content

Commit 0bd370f

Browse files
authored
Merge pull request #79 from codingapi/dev
Dev
2 parents f62f973 + b87e6a7 commit 0bd370f

File tree

24 files changed

+144
-38
lines changed

24 files changed

+144
-38
lines changed

example/example-application/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.6</version>
8+
<version>3.3.10</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.codingapi.example.handler;
22

3+
import com.codingapi.example.event.AEvent;
34
import com.codingapi.example.event.CEvent;
5+
import com.codingapi.springboot.framework.event.EventPusher;
46
import com.codingapi.springboot.framework.event.EventTraceContext;
57
import com.codingapi.springboot.framework.event.IHandler;
68
import lombok.extern.slf4j.Slf4j;
@@ -14,7 +16,7 @@ public class CHandler implements IHandler<CEvent> {
1416
public void handler(CEvent event) {
1517
log.info("c event:{},eventKey:{}", event, EventTraceContext.getInstance().getEventKey());
1618

17-
// EventPusher.push(new AEvent());
19+
// EventPusher.push(new AEvent(),true);
1820
// throw new RuntimeException("c handler error");
1921
}
2022

example/example-domain/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.6</version>
8+
<version>3.3.10</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.6</version>
8+
<version>3.3.10</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-jpa/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.6</version>
8+
<version>3.3.10</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.6</version>
8+
<version>3.3.10</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.6</version>
20+
<version>3.3.10</version>
2121

2222
<name>springboot-example</name>
2323
<description>springboot-example project for Spring Boot</description>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>3.3.6</version>
15+
<version>3.3.10</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>

springboot-starter-data-fast/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.6</version>
8+
<version>3.3.10</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-flow/pom.xml

+26-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.6</version>
9+
<version>3.3.10</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>
@@ -46,5 +46,30 @@
4646
</dependencies>
4747

4848

49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.jacoco</groupId>
53+
<artifactId>jacoco-maven-plugin</artifactId>
54+
<version>0.8.12</version>
55+
<executions>
56+
<execution>
57+
<goals>
58+
<goal>prepare-agent</goal>
59+
</goals>
60+
</execution>
61+
<execution>
62+
<id>report</id>
63+
<phase>test</phase>
64+
<goals>
65+
<goal>report</goal>
66+
</goals>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
71+
72+
</plugins>
73+
</build>
4974

5075
</project>

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void urge(long recordId, IFlowOperator currentOperator) {
9797
// 推送催办消息
9898
for (FlowRecord record : todoRecords) {
9999
IFlowOperator pushOperator = record.getCurrentOperator();
100-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_URGE, record, pushOperator, flowWork, null));
100+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_URGE, record, pushOperator, flowWork, null),true);
101101
}
102102

103103
}
@@ -220,10 +220,10 @@ public void transfer(long recordId, IFlowOperator currentOperator, IFlowOperator
220220
flowRecordRepository.save(List.of(transferRecord));
221221

222222
// 推送转办消息
223-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TRANSFER, flowRecord, currentOperator, flowWork, snapshot.toBindData()));
223+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TRANSFER, flowRecord, currentOperator, flowWork, snapshot.toBindData()),true);
224224

225225
// 推送待办消息
226-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, transferRecord, targetOperator, flowWork, snapshot.toBindData()));
226+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, transferRecord, targetOperator, flowWork, snapshot.toBindData()),true);
227227
}
228228

229229

@@ -327,8 +327,8 @@ public FlowResult startFlow(String workCode, IFlowOperator operator, IBindData b
327327

328328
// 推送事件消息
329329
for (FlowRecord record : records) {
330-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_CREATE, record, operator, flowWork, snapshot.toBindData()));
331-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, operator, flowWork, snapshot.toBindData()));
330+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_CREATE, record, operator, flowWork, snapshot.toBindData()),true);
331+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, operator, flowWork, snapshot.toBindData()),true);
332332
}
333333
// 当前的审批记录
334334
return new FlowResult(flowWork, records);
@@ -426,7 +426,7 @@ public FlowResult submitFlow(long recordId, IFlowOperator currentOperator, IBind
426426
flowRecordRepository.update(flowRecord);
427427
flowRecordRepository.finishFlowRecordByProcessId(flowRecord.getProcessId());
428428

429-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_FINISH, flowRecord, currentOperator, flowWork, snapshot.toBindData()));
429+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_FINISH, flowRecord, currentOperator, flowWork, snapshot.toBindData()),true);
430430
return new FlowResult(flowWork, flowRecord);
431431
}
432432

@@ -465,12 +465,12 @@ public FlowResult submitFlow(long recordId, IFlowOperator currentOperator, IBind
465465

466466
// 推送审批事件消息
467467
int eventState = flowSourceDirection == FlowSourceDirection.PASS ? FlowApprovalEvent.STATE_PASS : FlowApprovalEvent.STATE_REJECT;
468-
EventPusher.push(new FlowApprovalEvent(eventState, flowRecord, currentOperator, flowWork, snapshot.toBindData()));
468+
EventPusher.push(new FlowApprovalEvent(eventState, flowRecord, currentOperator, flowWork, snapshot.toBindData()),true);
469469

470470
// 推送待办事件消息
471471
for (FlowRecord record : records) {
472472
IFlowOperator pushOperator = record.getCurrentOperator();
473-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, pushOperator, flowWork, snapshot.toBindData()));
473+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, pushOperator, flowWork, snapshot.toBindData()),true);
474474
}
475475

476476
return new FlowResult(flowWork, records);
@@ -514,7 +514,7 @@ public void recall(long recordId, IFlowOperator currentOperator) {
514514
flowRecordRepository.update(flowRecord);
515515

516516
flowRecordRepository.delete(childrenRecords);
517-
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_RECALL, flowRecord, currentOperator, flowWork, null));
517+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_RECALL, flowRecord, currentOperator, flowWork, null),true);
518518
}
519519

520520
}

springboot-starter-security/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.6</version>
9+
<version>3.3.10</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter-security/src/main/java/com/codingapi/springboot/security/AutoConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void preHandle(HttpServletRequest request, HttpServletResponse response,
7171
}
7272

7373
@Override
74-
public LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, Token token) {
74+
public LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest,UserDetails user, Token token) {
7575
LoginResponse loginResponse = new LoginResponse();
7676
loginResponse.setToken(token.getToken());
7777
loginResponse.setUsername(token.getUsername());

springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAccessDeniedHandler.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class MyAccessDeniedHandler implements AccessDeniedHandler {
2020
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
2121
log.debug("access denied");
2222
String content = JSONObject.toJSONString(Response.buildFailure("not.access", "please check user authentication."));
23+
// 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8
24+
response.setContentType("application/json;charset=UTF-8");
25+
response.setCharacterEncoding("UTF-8");
26+
2327
IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8);
2428
}
2529
}

springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAuthenticationFilter.java

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
8080

8181
private void writeResponse(HttpServletResponse servletResponse, Response returnResponse) throws IOException {
8282
String content = JSONObject.toJSONString(returnResponse);
83+
// 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8
84+
servletResponse.setContentType("application/json;charset=UTF-8");
85+
servletResponse.setCharacterEncoding("UTF-8");
86+
8387
IOUtils.write(content, servletResponse.getOutputStream(), StandardCharsets.UTF_8);
8488
}
8589

springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLoginFilter.java

+21-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
import com.codingapi.springboot.security.dto.request.LoginRequest;
77
import com.codingapi.springboot.security.dto.request.LoginRequestContext;
88
import com.codingapi.springboot.security.dto.response.LoginResponse;
9-
import com.codingapi.springboot.security.gateway.TokenGateway;
109
import com.codingapi.springboot.security.gateway.Token;
1110
import com.codingapi.springboot.security.gateway.TokenContext;
11+
import com.codingapi.springboot.security.gateway.TokenGateway;
1212
import com.codingapi.springboot.security.properties.CodingApiSecurityProperties;
13+
import io.jsonwebtoken.Header;
14+
import jakarta.servlet.FilterChain;
15+
import jakarta.servlet.ServletException;
16+
import jakarta.servlet.http.HttpServletRequest;
17+
import jakarta.servlet.http.HttpServletResponse;
1318
import lombok.extern.slf4j.Slf4j;
1419
import org.apache.commons.io.IOUtils;
1520
import org.springframework.security.authentication.AuthenticationManager;
@@ -18,14 +23,10 @@
1823
import org.springframework.security.core.Authentication;
1924
import org.springframework.security.core.AuthenticationException;
2025
import org.springframework.security.core.GrantedAuthority;
21-
import org.springframework.security.core.userdetails.User;
26+
import org.springframework.security.core.userdetails.UserDetails;
2227
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
2328
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
2429

25-
import jakarta.servlet.FilterChain;
26-
import jakarta.servlet.ServletException;
27-
import jakarta.servlet.http.HttpServletRequest;
28-
import jakarta.servlet.http.HttpServletResponse;
2930
import java.io.IOException;
3031
import java.nio.charset.StandardCharsets;
3132
import java.util.stream.Collectors;
@@ -58,7 +59,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
5859
throw new AuthenticationServiceException("request stream read was null.");
5960
}
6061
try {
61-
loginHandler.preHandle(request,response,login);
62+
loginHandler.preHandle(request, response, login);
6263
} catch (Exception e) {
6364
throw new AuthenticationServiceException(e.getLocalizedMessage());
6465
}
@@ -69,15 +70,20 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
6970
@Override
7071
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
7172
log.debug("login success authentication ~");
72-
User user = (User) authResult.getPrincipal();
73+
UserDetails user = (UserDetails) authResult.getPrincipal();
7374
LoginRequest loginRequest = LoginRequestContext.getInstance().get();
7475

7576
Token token = tokenGateway.create(user.getUsername(), loginRequest.getPassword(),
7677
user.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()),
7778
TokenContext.getExtra());
7879

79-
LoginResponse loginResponse = loginHandler.postHandle(request,response,loginRequest,token);
80+
LoginResponse loginResponse = loginHandler.postHandle(request, response, loginRequest, user, token);
8081
String content = JSONObject.toJSONString(SingleResponse.of(loginResponse));
82+
83+
// 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8
84+
response.setContentType("application/json;charset=UTF-8");
85+
response.setCharacterEncoding("UTF-8");
86+
8187
IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8);
8288

8389
LoginRequestContext.getInstance().clean();
@@ -89,7 +95,13 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
8995
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException {
9096
log.debug("login fail authentication ~");
9197
String content = JSONObject.toJSONString(Response.buildFailure("login.error", failed.getMessage()));
98+
99+
// 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8
100+
response.setContentType("application/json;charset=UTF-8");
101+
response.setCharacterEncoding("UTF-8");
102+
92103
IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8);
104+
93105
LoginRequestContext.getInstance().clean();
94106
}
95107
}

springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLogoutSuccessHandler.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
2020
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
2121
log.debug("logout success ~");
2222
String content = JSONObject.toJSONString(Response.buildSuccess());
23+
// 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8
24+
response.setContentType("application/json;charset=UTF-8");
25+
response.setCharacterEncoding("UTF-8");
26+
2327
IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8);
2428
}
2529
}

springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyUnAuthenticationEntryPoint.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class MyUnAuthenticationEntryPoint implements AuthenticationEntryPoint {
2020
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
2121
log.debug("no authentication ~");
2222
String content = JSONObject.toJSONString(Response.buildFailure("not.login", "please to login."));
23+
// 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8
24+
response.setContentType("application/json;charset=UTF-8");
25+
response.setCharacterEncoding("UTF-8");
26+
2327
IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8);
2428
}
2529
}

springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/SecurityLoginHandler.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import com.codingapi.springboot.security.gateway.Token;
66
import jakarta.servlet.http.HttpServletRequest;
77
import jakarta.servlet.http.HttpServletResponse;
8+
import org.springframework.security.core.userdetails.User;
9+
import org.springframework.security.core.userdetails.UserDetails;
810

911
public interface SecurityLoginHandler {
1012

1113
void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest) throws Exception;
1214

13-
LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, Token token);
15+
LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, UserDetails user, Token token);
1416

1517
}

springboot-starter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>3.3.6</version>
8+
<version>3.3.10</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

springboot-starter/src/main/java/com/codingapi/springboot/framework/event/DomainEventContext.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ public static DomainEventContext getInstance() {
2323
return instance;
2424
}
2525

26-
private void push(IEvent event, boolean sync) {
26+
private void push(IEvent event, boolean sync,boolean hasLoopEvent) {
2727
if (context != null) {
2828
String traceId = EventTraceContext.getInstance().getOrCreateTrace();
29+
if(hasLoopEvent){
30+
EventTraceContext.getInstance().clearTrace();
31+
traceId = EventTraceContext.getInstance().getOrCreateTrace();
32+
}
2933
EventTraceContext.getInstance().addEvent(traceId,event);
3034
context.publishEvent(new DomainEvent(event, sync,traceId));
3135
}
@@ -36,13 +40,13 @@ private void push(IEvent event, boolean sync) {
3640
* @see EventPusher
3741
* 默认 同步事件
3842
*/
39-
public void push(IEvent event) {
43+
public void push(IEvent event,boolean hasLoopEvent) {
4044
if (event instanceof IAsyncEvent) {
41-
this.push(event, false);
45+
this.push(event, false,hasLoopEvent);
4246
} else if (event instanceof ISyncEvent) {
43-
this.push(event, true);
47+
this.push(event, true,hasLoopEvent);
4448
} else {
45-
this.push(event, true);
49+
this.push(event, true,hasLoopEvent);
4650
}
4751
}
4852

0 commit comments

Comments
 (0)