[Minor] Adding remoteIp to ThreadLocal and using in authentication
This commit is contained in:
parent
0f8f94dc10
commit
7c11292199
|
@ -144,7 +144,7 @@ public class WebSocketClient implements MessageHandler.Whole<String> {
|
|||
|
||||
try {
|
||||
StrolchSessionHandler sessionHandler = RestfulStrolchComponent.getInstance().getSessionHandler();
|
||||
this.certificate = sessionHandler.validate(authToken);
|
||||
this.certificate = sessionHandler.validate(authToken, WebSocketRemoteIp.get());
|
||||
if (!this.certificate.getUsername().equals(username)) {
|
||||
logger.error("Invalid authentication for " + username);
|
||||
close(CloseReason.CloseCodes.UNEXPECTED_CONDITION, "Invalid authentication");
|
||||
|
|
|
@ -20,8 +20,9 @@ public class WebSocketFilter implements Filter {
|
|||
throws IOException, ServletException {
|
||||
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
logger.info("Remote IP: " + getRemoteIp(httpRequest) + ": " + httpRequest.getMethod() + " " + httpRequest
|
||||
.getRequestURI());
|
||||
String remoteIp = getRemoteIp(httpRequest);
|
||||
logger.info("Remote IP: " + remoteIp + ": " + httpRequest.getMethod() + " " + httpRequest.getRequestURI());
|
||||
WebSocketRemoteIp.set(remoteIp);
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package li.strolch.websocket;
|
||||
|
||||
public class WebSocketRemoteIp {
|
||||
|
||||
private static final ThreadLocal<String> threadLocal = ThreadLocal.withInitial(() -> "notset");
|
||||
|
||||
public static String get() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
|
||||
public static void set(String remoteIp) {
|
||||
threadLocal.set(remoteIp);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue