RED-9147: Added function to authenticate needed for websockets

This commit is contained in:
Dominique Eifländer 2024-05-17 15:44:22 +02:00
parent 2a8196a69f
commit 526887f3e2

View File

@ -1,6 +1,5 @@
package com.knecon.fforesight.keycloakcommons.security;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
@ -8,7 +7,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationManagerResolver;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.jwt.JwtDecoders;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider;
import org.springframework.security.oauth2.server.resource.web.BearerTokenResolver;
@ -37,6 +35,18 @@ public class TenantAuthenticationManagerResolver implements AuthenticationManage
}
public AuthenticationManager resolve(String token) {
return this.authenticationManagers.computeIfAbsent(toTenant(token), this::fromTenant);
}
private String toTenant(String token) {
return TokenUtils.toTenant(token);
}
private String toTenant(HttpServletRequest request) {
return TokenUtils.toTenant(this.resolver.resolve(request));