validation and expiration splitted

This commit is contained in:
lucio 2024-10-28 13:46:42 +01:00
parent 1d02c93aae
commit 16bae0aa70
7 changed files with 24 additions and 7 deletions

View File

@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=11

View File

@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [v1.0.0] - 2022-06-06
## [v1.0.0-SNAPSHOT] - 2022-06-06
- First Release

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.common.security</groupId>
<artifactId>gcube-secrets</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<name>gcube secrets</name>
<scm>

View File

@ -77,9 +77,14 @@ public class AccessTokenSecret extends Secret {
@Override
public boolean isValid() {
if (this.umaTokenSecret.isExpired())
if (isExpired())
refreshAccessToken();
return this.umaTokenSecret.isValid();
}
@Override
public boolean isExpired() {
return this.umaTokenSecret.isExpired();
}
}

View File

@ -57,6 +57,11 @@ public class CredentialSecret extends Secret {
return this.accessTokenSecret.getHTTPAuthorizationHeaders();
}
@Override
public boolean isExpired() {
return this.accessTokenSecret.isExpired();
}
@Override
public boolean isValid() {
return this.accessTokenSecret.isValid();

View File

@ -72,4 +72,9 @@ public class GCubeSecret extends Secret {
return gcubeToken != null && !gcubeToken.isEmpty() && Pattern.matches(GCUBE_TOKEN_REGEX, gcubeToken);
}
@Override
public boolean isExpired() {
return false;
}
}

View File

@ -97,11 +97,13 @@ public class UmaTokenSecret extends Secret {
try {
KeycloakClient client = KeycloakClientFactory.newInstance();
PublishedRealmRepresentation realmInfo = client.getRealmInfo(client.getRealmBaseURL(context));
return ModelUtils.isValid(encodedUmaToken, realmInfo.getPublicKey());
return ModelUtils.isValid(encodedUmaToken, realmInfo.getPublicKey(), false);
} catch (Exception e) {
log.error("Error contacting keycloak, is not possible to check token validity", e);
return false;
}
}
}