Skip to content

Commit 5776544

Browse files
committed
Update the SetUserFilter
1 parent 73fe4d1 commit 5776544

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sample-apps/SpringBoot2.7Postgres/src/main/java/com/example/demo/SetUserFilter.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.example.demo;
22

3+
import dev.aikido.agent_api.SetUser;
34
import org.springframework.core.annotation.Order;
45
import org.springframework.stereotype.Component;
56

67
import javax.servlet.*;
8+
import javax.servlet.http.HttpServletRequest;
79
import java.io.IOException;
810

11+
import static dev.aikido.agent_api.SetUser.setUser;
12+
913

1014
@Component
1115
@Order(0)
@@ -16,7 +20,12 @@ public void doFilter(
1620
ServletRequest request,
1721
ServletResponse response,
1822
FilterChain chain) throws IOException, ServletException {
19-
//setUser(new SetUser.UserObject("123", "John Doe"));
23+
HttpServletRequest httpRequest = (HttpServletRequest) request;
24+
if (httpRequest.getHeader("user") != null) {
25+
// Useful for end2end tests:
26+
String id = httpRequest.getHeader("user");
27+
setUser(new SetUser.UserObject(id, "John Doe"));
28+
}
2029
chain.doFilter(request, response);
2130
}
2231
}

0 commit comments

Comments
 (0)