Auth Utils filter

This commit is contained in:
Fabio Sinibaldi 2022-10-18 15:41:17 +02:00
parent 3a2a42f3b8
commit 60de4f504b
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package org.gcube.application.geoportal.service;
import lombok.extern.slf4j.Slf4j;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.GCubeSecret;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import javax.ws.rs.container.*;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
@Provider
@PreMatching
@Slf4j
public class RequestFilter implements ContainerRequestFilter, ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
log.trace("PreMatching RequestFilter");
SecretManagerProvider.instance.reset();
SecretManager secretManager = new SecretManager();
String token = AccessTokenProvider.instance.get();
if(token!=null) {
Secret secret = new JWTSecret(token);
secretManager.addSecret(secret);
}
token = SecurityTokenProvider.instance.get();
if(token!=null) {
Secret secret = new GCubeSecret(token);
secretManager.addSecret(secret);
}
SecretManagerProvider.instance.set(secretManager);
}
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
log.trace("ResponseFilter");
SecretManagerProvider.instance.reset();
}
}