Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make JWT auth providers isolated #240

Merged
merged 3 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ puppycrawlCheckstyleVersion=8.18
ballerinaGradlePluginVersion=0.8.2

ballerinaLangVersion=2.0.0-beta.1-20210520-181100-6c7be323
stdlibCacheVersion=2.1.0-beta.1-20210520-211100-df32f2f
stdlibCacheVersion=2.1.0-beta.1-20210521-162000-537d4fd
stdlibCryptoVersion=1.1.0-beta.1-20210521-002900-bc269d5
stdlibLogVersion=1.1.0-beta.1-20210520-193800-22c12d0
stdlibRegexVersion=0.7.0-beta.1-20210520-193000-257850b
Expand Down
6 changes: 3 additions & 3 deletions jwt-ballerina/client_self_signed_jwt_auth_provider.bal
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
# }
# });
# ```
public class ClientSelfSignedJwtAuthProvider {
public isolated class ClientSelfSignedJwtAuthProvider {

IssuerConfig issuerConfig;
private final IssuerConfig & readonly issuerConfig;

# Provides authentication based on the provided JWT configurations.
#
# + issuerConfig - JWT issuer configurations
public isolated function init(IssuerConfig issuerConfig) {
self.issuerConfig = issuerConfig;
self.issuerConfig = issuerConfig.cloneReadOnly();
}

# Issues a self-signed JWT for authentication.
Expand Down
23 changes: 13 additions & 10 deletions jwt-ballerina/listener_jwt_auth_provider.bal
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,37 @@ import ballerina/time;
# }
# });
# ```
public class ListenerJwtAuthProvider {
public isolated class ListenerJwtAuthProvider {

ValidatorConfig validatorConfig;
cache:Cache? jwtCache = ();
cache:Cache? jwksCache = ();
private final ValidatorConfig & readonly validatorConfig;
private final cache:Cache? jwtCache;
private final cache:Cache? jwksCache;

# Provides authentication based on the provided JWT.
#
# + validatorConfig - JWT validator configurations
public isolated function init(ValidatorConfig validatorConfig) {
self.validatorConfig = validatorConfig;
cache:CacheConfig? jwtCacheConfig = validatorConfig?.cacheConfig;
self.validatorConfig = validatorConfig.cloneReadOnly();
cache:CacheConfig? jwtCacheConfig = self.validatorConfig?.cacheConfig;
if (jwtCacheConfig is cache:CacheConfig) {
self.jwtCache = new(jwtCacheConfig);
} else {
self.jwtCache = ();
}
var jwksConfig = validatorConfig?.signatureConfig?.jwksConfig;
var jwksConfig = self.validatorConfig?.signatureConfig?.jwksConfig;
if !(jwksConfig is ()) {
string url = <string> jwksConfig?.url;
ClientConfiguration clientConfig = <ClientConfiguration> jwksConfig?.clientConfig;
ClientConfiguration clientConfig = jwksConfig.clientConfig;
cache:CacheConfig? jwksCacheConfig = jwksConfig?.cacheConfig;
if (jwksCacheConfig is cache:CacheConfig) {
self.jwksCache = new(jwksCacheConfig);
Error? result = preloadJwksToCache(<cache:Cache> (self.jwksCache), url, clientConfig);
Error? result = preloadJwksToCache(<cache:Cache> (self.jwksCache), jwksConfig.url, clientConfig);
if (result is Error) {
panic result;
}
return;
}
}
self.jwksCache = ();
}

# Authenticates the provided JWT.
Expand Down