-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJWTTokenRequestTracker-filter.java
34 lines (29 loc) · 1.33 KB
/
JWTTokenRequestTracker-filter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// servlet filter, apply filter only for endpoint with annotation
import com.ubs.jetty.api.rest.security.KeyCloakJWTBody;
import com.ubs.jetty.api.rest.usage.JWTTokenTracking;
import com.ubs.jetty.authentication.AuthenticationUtil;
import com.ubs.metrics.postgres.usertracking.UserTracking;
import com.ubs.metrics.postgres.usertracking.UserTrackingDAO;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import javax.annotation.Priority;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Priorities;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import lombok.Setter;
@Provider
@JWTTokenTracking // filter will work only for methods with this annotation
@Priority(Priorities.USER)
public class JWTTokenRequestTracker implements ContainerRequestFilter {
@Context @Setter private HttpServletRequest request;
static Cache<String, UserTracking> jwtUserCache = CacheBuilder.newBuilder().maximumSize(2000).expireAfterWrite(360, TimeUnit.SECONDS).build();
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
KeyCloakJWTBody keyCloakJWTBody = AuthenticationUtil.getKeyCloakJWTBodyFromRequest(request);
...
}
}