mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-15 18:33:40 +00:00
parent
1f8e232487
commit
7d4f1270ab
@ -68,7 +68,7 @@ public class ChangeEventHandler implements EventHandler {
|
|||||||
}
|
}
|
||||||
// Always set the Change Event Username as context Principal, the one creating the CE
|
// Always set the Change Event Username as context Principal, the one creating the CE
|
||||||
changeEvent.setUserName(loggedInUserName);
|
changeEvent.setUserName(loggedInUserName);
|
||||||
LOG.info(
|
LOG.debug(
|
||||||
"Recording change event {}:{}:{}:{}",
|
"Recording change event {}:{}:{}:{}",
|
||||||
changeEvent.getTimestamp(),
|
changeEvent.getTimestamp(),
|
||||||
changeEvent.getEntityId(),
|
changeEvent.getEntityId(),
|
||||||
|
|||||||
@ -18,30 +18,50 @@ import com.auth0.jwk.JwkException;
|
|||||||
import com.auth0.jwk.JwkProvider;
|
import com.auth0.jwk.JwkProvider;
|
||||||
import com.auth0.jwk.SigningKeyNotFoundException;
|
import com.auth0.jwk.SigningKeyNotFoundException;
|
||||||
import com.auth0.jwk.UrlJwkProvider;
|
import com.auth0.jwk.UrlJwkProvider;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.openmetadata.service.exception.UnhandledServerException;
|
||||||
|
|
||||||
final class MultiUrlJwkProvider implements JwkProvider {
|
final class MultiUrlJwkProvider implements JwkProvider {
|
||||||
private final List<UrlJwkProvider> urlJwkProviders;
|
private final List<UrlJwkProvider> urlJwkProviders;
|
||||||
|
private LoadingCache<String, Jwk> CACHE =
|
||||||
|
CacheBuilder.newBuilder()
|
||||||
|
.maximumSize(10)
|
||||||
|
.expireAfterWrite(24, TimeUnit.HOURS)
|
||||||
|
.build(
|
||||||
|
new CacheLoader<>() {
|
||||||
|
@Override
|
||||||
|
public Jwk load(String key) throws Exception {
|
||||||
|
JwkException lastException =
|
||||||
|
new SigningKeyNotFoundException(
|
||||||
|
"JWT Token keyID doesn't match the configured keyID. This usually happens if you didn't configure "
|
||||||
|
+ "proper publicKeyUrls under authentication configuration.",
|
||||||
|
null);
|
||||||
|
for (UrlJwkProvider jwkProvider : urlJwkProviders) {
|
||||||
|
try {
|
||||||
|
return jwkProvider.get(key);
|
||||||
|
} catch (JwkException e) {
|
||||||
|
lastException.addSuppressed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw lastException;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
public MultiUrlJwkProvider(List<URL> publicKeyUris) {
|
public MultiUrlJwkProvider(List<URL> publicKeyUris) {
|
||||||
this.urlJwkProviders = publicKeyUris.stream().map(UrlJwkProvider::new).toList();
|
this.urlJwkProviders = publicKeyUris.stream().map(UrlJwkProvider::new).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Jwk get(String keyId) throws JwkException {
|
public Jwk get(String keyId) {
|
||||||
JwkException lastException =
|
try {
|
||||||
new SigningKeyNotFoundException(
|
return CACHE.get(keyId);
|
||||||
"JWT Token keyID doesn't match the configured keyID. This usually happens if you didn't configure "
|
} catch (Exception e) {
|
||||||
+ "proper publicKeyUrls under authentication configuration.",
|
throw new UnhandledServerException(e.getMessage());
|
||||||
null);
|
|
||||||
for (UrlJwkProvider jwkProvider : urlJwkProviders) {
|
|
||||||
try {
|
|
||||||
return jwkProvider.get(keyId);
|
|
||||||
} catch (JwkException e) {
|
|
||||||
lastException.addSuppressed(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw lastException;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user