Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4930575

Browse files
aq-ikhwa-techludomikula
authored andcommitted
Add handling for audit logs feature
1 parent 4ae0e0a commit 4930575

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/event/AbstractEvent.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.lowcoder.infra.event;
22

3+
import java.lang.reflect.Field;
34
import java.util.HashMap;
45
import java.util.Map;
56

@@ -14,9 +15,11 @@ public abstract class AbstractEvent implements LowcoderEvent
1415
{
1516
protected final String orgId;
1617
protected final String userId;
17-
protected Map<String, String> details;
18+
protected final String sessionHash;
19+
protected final Boolean isAnonymous;
20+
protected Map<String, Object> details;
1821

19-
public Map<String, String> details()
22+
public Map<String, Object> details()
2023
{
2124
return this.details;
2225
}
@@ -33,4 +36,20 @@ public B detail(String name, String value)
3336
return self();
3437
}
3538
}
39+
40+
public void populateDetails() {
41+
if (details == null) {
42+
details = new HashMap<>();
43+
}
44+
for(Field f : getClass().getDeclaredFields()){
45+
Object value = null;
46+
try {
47+
f.setAccessible(Boolean.TRUE);
48+
value = f.get(this);
49+
details.put(f.getName(), value);
50+
} catch (Exception e) {
51+
}
52+
53+
}
54+
}
3655
}

server/api-service/lowcoder-server/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
<artifactId>jjwt-impl</artifactId>
215215
<version>0.11.5</version>
216216
<scope>runtime</scope>
217+
</dependency>
218+
<groupId>org.springframework</groupId>
219+
<artifactId>spring-aspects</artifactId>
217220
</dependency>
218221
<dependency>
219222
<groupId>org.springframework</groupId>

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/plugin/data/PluginServerRequest.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package org.lowcoder.api.framework.plugin.data;
22

3+
import org.lowcoder.plugin.api.PluginEndpoint;
4+
import org.lowcoder.plugin.api.PluginEndpoint.Method;
5+
import org.lowcoder.plugin.api.data.EndpointRequest;
6+
import org.springframework.http.HttpCookie;
7+
import org.springframework.http.HttpHeaders;
8+
import org.springframework.http.HttpMethod;
9+
import org.springframework.web.reactive.function.server.ServerRequest;
10+
311
import java.net.URI;
412
import java.security.Principal;
513
import java.util.AbstractMap.SimpleEntry;
@@ -10,14 +18,6 @@
1018
import java.util.Map.Entry;
1119
import java.util.concurrent.CompletableFuture;
1220

13-
import org.lowcoder.plugin.api.PluginEndpoint;
14-
import org.lowcoder.plugin.api.PluginEndpoint.Method;
15-
import org.lowcoder.plugin.api.data.EndpointRequest;
16-
import org.springframework.http.HttpCookie;
17-
import org.springframework.http.HttpHeaders;
18-
import org.springframework.http.HttpMethod;
19-
import org.springframework.web.reactive.function.server.ServerRequest;
20-
2121
public class PluginServerRequest implements EndpointRequest
2222
{
2323
private URI uri;
@@ -27,6 +27,8 @@ public class PluginServerRequest implements EndpointRequest
2727
private Map<String, List<Map.Entry<String, String>>> cookies;
2828
private Map<String, Object> attributes;
2929
private Map<String, String> pathVariables;
30+
31+
private Map<String, List<String>> queryParams;
3032
private CompletableFuture<? extends Principal> principal;
3133

3234

@@ -36,6 +38,7 @@ public PluginServerRequest()
3638
cookies = new HashMap<>();
3739
attributes = new HashMap<>();
3840
pathVariables = new HashMap<>();
41+
queryParams = new HashMap<>();
3942
}
4043

4144
public static PluginServerRequest fromServerRequest(ServerRequest request)
@@ -74,6 +77,14 @@ public static PluginServerRequest fromServerRequest(ServerRequest request)
7477
psr.pathVariables.put(entry.getKey(), entry.getValue());
7578
});
7679
}
80+
81+
if (request.queryParams() != null)
82+
{
83+
request.queryParams().entrySet()
84+
.forEach(entry -> {
85+
psr.queryParams.put(entry.getKey(), entry.getValue());
86+
});
87+
}
7788

7889
psr.principal = request.principal().toFuture();
7990

@@ -125,6 +136,11 @@ public Map<String, Object> attributes() {
125136
public Map<String, String> pathVariables() {
126137
return pathVariables;
127138
}
139+
140+
@Override
141+
public Map<String, List<String>> queryParams() {
142+
return queryParams;
143+
}
128144
@Override
129145
public CompletableFuture<? extends Principal> principal() {
130146
return principal;

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/util/BusinessEventPublisher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.lowcoder.infra.event.user.UserLoginEvent;
4040
import org.lowcoder.infra.event.user.UserLogoutEvent;
4141
import org.lowcoder.plugin.api.event.LowcoderEvent.EventType;
42+
import org.lowcoder.sdk.constants.Authentication;
4243
import org.lowcoder.sdk.util.LocaleUtils;
4344
import org.springframework.beans.factory.annotation.Autowired;
4445
import org.springframework.context.ApplicationEventPublisher;

0 commit comments

Comments
 (0)