-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JWT retryable exception type (#107)
- Loading branch information
Showing
7 changed files
with
147 additions
and
68 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
tests/src/test/java/io/scalecube/security/environment/IntegrationEnvironmentFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.scalecube.security.environment; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ExtensionContext.Namespace; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import org.junit.jupiter.api.extension.ParameterResolver; | ||
|
||
public class IntegrationEnvironmentFixture | ||
implements BeforeAllCallback, ExtensionContext.Store.CloseableResource, ParameterResolver { | ||
|
||
private static final Map<Class<?>, Supplier<?>> PARAMETERS_TO_RESOLVE = new HashMap<>(); | ||
|
||
private static VaultEnvironment vaultEnvironment; | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext context) { | ||
context | ||
.getRoot() | ||
.getStore(Namespace.GLOBAL) | ||
.getOrComputeIfAbsent( | ||
this.getClass(), | ||
key -> { | ||
vaultEnvironment = VaultEnvironment.start(); | ||
return this; | ||
}); | ||
|
||
PARAMETERS_TO_RESOLVE.put(VaultEnvironment.class, () -> vaultEnvironment); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (vaultEnvironment != null) { | ||
vaultEnvironment.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean supportsParameter( | ||
ParameterContext parameterContext, ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
Class<?> type = parameterContext.getParameter().getType(); | ||
return PARAMETERS_TO_RESOLVE.keySet().stream().anyMatch(type::isAssignableFrom); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter( | ||
ParameterContext parameterContext, ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
Class<?> type = parameterContext.getParameter().getType(); | ||
return PARAMETERS_TO_RESOLVE.get(type).get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tokens/src/main/java/io/scalecube/security/tokens/jwt/JwtUnavailableException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.scalecube.security.tokens.jwt; | ||
|
||
/** | ||
* Special JWT exception type indicating transient error during token resolution. For example such | ||
* transient errors are: | ||
* | ||
* <ul> | ||
* <li>Key Rotation: JWKS endpoints often implement key rotation policies where keys are | ||
* periodically changed for security reasons. If the JWT was issued with a "kid" that | ||
* corresponds to a key that has since been rotated out, that key won't be available in the | ||
* JWKS anymore. | ||
* <li>Network or Server Issues: if the JWKS URI is temporarily down, inaccessible, or | ||
* experiencing issues, cleint might not be able to retrieve the keys, or the list of keys | ||
* might be incomplete or outdated. | ||
* </ul> | ||
*/ | ||
public class JwtUnavailableException extends JwtTokenException { | ||
|
||
public JwtUnavailableException(String message) { | ||
super(message); | ||
} | ||
|
||
public JwtUnavailableException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |