diff --git a/pom.xml b/pom.xml
index 2f0ae4e9..ac329f11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.7.17
+ 2.7.18
@@ -32,14 +32,13 @@
17
- 2.7.17
+ 2.7.18
italiangrid_storm-webdav
italiangrid
https://sonarcloud.io
- 0.4.6.v20220506
2.7.1.7
2.3
@@ -55,9 +54,9 @@
1.0.5.1
2.3.3.RELEASE
- 6.0.2
5.5.1
1.76
+ 3.3.2
org.italiangrid.storm.webdav.WebdavService
@@ -348,34 +347,6 @@
metrics-servlets
-
- org.italiangrid
- jetty-utils
- ${jetty-utils.version}
-
-
- javax.activation
- activation
-
-
- javax.mail
- mail
-
-
- org.eclipse.jetty.aggregate
- jetty-all
-
-
- ch.qos.logback
- logback-core
-
-
- ch.qos.logback
- logback-classic
-
-
-
-
org.bouncycastle
bcpkix-jdk18on
@@ -388,7 +359,6 @@
${bouncycastle.version}
-
ch.qos.logback
logback-access
@@ -404,6 +374,11 @@
logback-classic
+
+ org.slf4j
+ log4j-over-slf4j
+
+
org.apache.httpcomponents
httpclient
@@ -419,6 +394,34 @@
org.eclipse.jetty
jetty-rewrite
+
+ org.eclipse.jetty
+ jetty-server
+
+
+ org.eclipse.jetty
+ jetty-http
+
+
+ org.eclipse.jetty
+ jetty-util
+
+
+ org.eclipse.jetty
+ jetty-alpn-server
+
+
+ org.eclipse.jetty.http2
+ http2-server
+
+
+ org.eclipse.jetty.http2
+ http2-common
+
+
+ org.eclipse.jetty
+ jetty-alpn-conscrypt-server
+
commons-lang
@@ -463,6 +466,12 @@
${milton.version}
+
+ org.italiangrid
+ voms-api-java
+ ${voms-api-java.version}
+
+
commons-cli
commons-cli
diff --git a/src/main/java/org/italiangrid/storm/webdav/config/OAuthProperties.java b/src/main/java/org/italiangrid/storm/webdav/config/OAuthProperties.java
index bd833381..aab8d1f6 100644
--- a/src/main/java/org/italiangrid/storm/webdav/config/OAuthProperties.java
+++ b/src/main/java/org/italiangrid/storm/webdav/config/OAuthProperties.java
@@ -96,6 +96,9 @@ public boolean isEnforceAudienceChecks() {
@Min(value = 1, message = "The refresh period must be a positive integer")
int refreshPeriodMinutes = 60;
+ @Min(value = 1, message = "The refresh timeout must be a positive integer")
+ int refreshTimeoutSeconds = 30;
+
public List getIssuers() {
return issuers;
}
@@ -112,6 +115,14 @@ public void setRefreshPeriodMinutes(int refreshPeriodMinutes) {
this.refreshPeriodMinutes = refreshPeriodMinutes;
}
+ public int getRefreshTimeoutSeconds() {
+ return refreshTimeoutSeconds;
+ }
+
+ public void setRefreshTimeoutSeconds(int refreshTimeoutSeconds) {
+ this.refreshTimeoutSeconds = refreshTimeoutSeconds;
+ }
+
public void setEnableOidc(boolean enableOidc) {
this.enableOidc = enableOidc;
}
diff --git a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java
index 090ee2db..73fa6277 100644
--- a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java
+++ b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java
@@ -18,34 +18,45 @@
import static java.lang.String.format;
import java.net.URI;
+import java.time.Duration;
+import java.util.Arrays;
import java.util.Map;
+import org.italiangrid.storm.webdav.config.OAuthProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
+import com.nimbusds.jose.RemoteKeySourceException;
+
@Service
public class DefaultOidcConfigurationFetcher implements OidcConfigurationFetcher {
public static final String WELL_KNOWN_FRAGMENT = "/.well-known/openid-configuration";
public static final String ISSUER_MISMATCH_ERROR_TEMPLATE =
"Issuer in metadata '%s' does not match with requested issuer '%s'";
- public static final String NO_JWKS_URI_ERROR_TEMPLATE =
+ public static final String NO_JWKS_URI_ERROR_TEMPLATE =
"No jwks_uri found in metadata for issuer '%s'";
+ private static final MediaType APPLICATION_JWK_SET_JSON =
+ new MediaType("application", "jwk-set+json");
+
public static final Logger LOG = LoggerFactory.getLogger(DefaultOidcConfigurationFetcher.class);
- final RestTemplateBuilder restBuilder;
+ final RestTemplate restTemplate;
- @Autowired
- public DefaultOidcConfigurationFetcher(RestTemplateBuilder restBuilder) {
- this.restBuilder = restBuilder;
+ public DefaultOidcConfigurationFetcher(RestTemplateBuilder restBuilder,
+ OAuthProperties oAuthProperties) {
+ final Duration TIMEOUT = Duration.ofSeconds(oAuthProperties.getRefreshTimeoutSeconds());
+ this.restTemplate = restBuilder.setConnectTimeout(TIMEOUT).setReadTimeout(TIMEOUT).build();
}
private void metadataChecks(String issuer, Map oidcConfiguration) {
@@ -59,29 +70,27 @@ private void metadataChecks(String issuer, Map oidcConfiguration
throw new OidcConfigurationResolutionError(
format(ISSUER_MISMATCH_ERROR_TEMPLATE, metadataIssuer, issuer));
}
-
+
if (!oidcConfiguration.containsKey("jwks_uri")) {
- throw new OidcConfigurationResolutionError(format(NO_JWKS_URI_ERROR_TEMPLATE,issuer));
+ throw new OidcConfigurationResolutionError(format(NO_JWKS_URI_ERROR_TEMPLATE, issuer));
}
}
@Override
public Map loadConfigurationForIssuer(String issuer) {
LOG.debug("Fetching OpenID configuration for {}", issuer);
-
+
ParameterizedTypeReference