summaryrefslogtreecommitdiff
path: root/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/SimpleMetadataProvider.java
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-01-31 20:41:54 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-01-31 20:41:54 +0100
commitd41afe91ee59daf6b5f5037cecac52900fe2ccb2 (patch)
tree3a19e1818d276d701574758ce6166b2f3a7e2030 /eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/SimpleMetadataProvider.java
parent0cf9926282ba4aa46bad3f4e8020cec72683492f (diff)
downloadEAAF-Components-d41afe91ee59daf6b5f5037cecac52900fe2ccb2.tar.gz
EAAF-Components-d41afe91ee59daf6b5f5037cecac52900fe2ccb2.tar.bz2
EAAF-Components-d41afe91ee59daf6b5f5037cecac52900fe2ccb2.zip
a lot of more OpenSAML3 refactoring staff
This version is also NOT stable!
Diffstat (limited to 'eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/SimpleMetadataProvider.java')
-rw-r--r--eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/SimpleMetadataProvider.java231
1 files changed, 0 insertions, 231 deletions
diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/SimpleMetadataProvider.java b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/SimpleMetadataProvider.java
deleted file mode 100644
index d63950cb..00000000
--- a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/SimpleMetadataProvider.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright 2017 Graz University of Technology EAAF-Core Components has been developed in a
- * cooperation between EGIZ, A-SIT Plus, A-SIT, and Graz University of Technology.
- *
- * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European
- * Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work except in
- * compliance with the Licence. You may obtain a copy of the Licence at:
- * https://joinup.ec.europa.eu/news/understanding-eupl-v12
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the Licence
- * is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the Licence for the specific language governing permissions and limitations under
- * the Licence.
- *
- * This product combines work with different licenses. See the "NOTICE" text file for details on the
- * various modules and licenses. The "NOTICE" text file is part of the distribution. Any derivative
- * works that you distribute must include a readable copy of the "NOTICE" text file.
-*/
-
-package at.gv.egiz.eaaf.modules.pvp2.impl.metadata;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.util.Timer;
-
-import javax.net.ssl.SSLHandshakeException;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider;
-import org.opensaml.saml2.metadata.provider.HTTPMetadataProvider;
-import org.opensaml.saml2.metadata.provider.MetadataFilter;
-import org.opensaml.saml2.metadata.provider.MetadataProvider;
-import org.opensaml.xml.parse.ParserPool;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
-import at.gv.egiz.eaaf.core.impl.utils.FileUtils;
-import at.gv.egiz.eaaf.modules.pvp2.exception.SchemaValidationException;
-import at.gv.egiz.eaaf.modules.pvp2.exception.SignatureValidationException;
-
-/**
- * Simple SAML2 metadata provider.
- *
- * @author tlenz
- *
- */
-public abstract class SimpleMetadataProvider implements MetadataProvider {
- private static final Logger log = LoggerFactory.getLogger(SimpleMetadataProvider.class);
-
- private static final String URI_PREFIX_HTTP = "http:";
- private static final String URI_PREFIX_HTTPS = "https:";
- private static final String URI_PREFIX_FILE = "file:";
-
- @Autowired
- protected IConfiguration authConfig;
-
- /**
- * Create a single SAML2 metadata provider.
- *
- * @param metadataLocation where the metadata should be loaded, but never null.
- * If the location starts with http(s):, than a http
- * based metadata provider is used. If the location
- * starts with file:, than a filesystem based metadata
- * provider is used
- * @param filter Filters, which should be used to validate the
- * metadata
- * @param idForLogging Id, which is used for Logging
- * @param timer {@link Timer} which is used to schedule metadata
- * refresh operations
- * @param httpClient Apache commons 3.x http client
- *
- * @return SAML2 Metadata Provider, or null if the metadata provider can not
- * initialized
- */
- protected MetadataProvider createNewSimpleMetadataProvider(final String metadataLocation,
- final MetadataFilter filter, final String idForLogging, final Timer timer,
- final ParserPool pool, final HttpClient httpClient) {
- if (metadataLocation.startsWith(URI_PREFIX_HTTP)
- || metadataLocation.startsWith(URI_PREFIX_HTTPS)) {
- if (httpClient != null) {
- return createNewHttpMetaDataProvider(metadataLocation, filter, idForLogging, timer, pool,
- httpClient);
- } else {
- log.warn("Can not load http(s) based SAML2 metadata without a HTTP client");
- return null;
- }
-
- } else {
- String absoluteMetadataLocation;
- try {
- absoluteMetadataLocation =
- FileUtils.makeAbsoluteUrl(metadataLocation, authConfig.getConfigurationRootDirectory());
-
- if (absoluteMetadataLocation.startsWith(URI_PREFIX_FILE)) {
- final File metadataFile = new File(absoluteMetadataLocation);
- if (metadataFile.exists()) {
- return createNewFileSystemMetaDataProvider(metadataFile, filter, idForLogging, timer,
- pool);
- } else {
- log.warn(
- "SAML2 metadata file: " + absoluteMetadataLocation + " not found or not exist");
- return null;
- }
-
- }
-
- } catch (final MalformedURLException e) {
- log.warn("SAML2 metadata URL is invalid: " + metadataLocation, e);
-
- }
-
- }
-
- log.warn("SAML2 metadata has an unsupported metadata location prefix: " + metadataLocation);
- return null;
-
- }
-
- /**
- * Create a single SAML2 filesystem based metadata provider.
- *
- * @param metadataFile File, where the metadata should be loaded
- * @param filter Filters, which should be used to validate the metadata
- * @param idForLogging Id, which is used for Logging
- * @param timer {@link Timer} which is used to schedule metadata refresh
- * operations
- * @param pool
- *
- * @return SAML2 Metadata Provider
- */
- private MetadataProvider createNewFileSystemMetaDataProvider(final File metadataFile,
- final MetadataFilter filter, final String idForLogging, final Timer timer,
- final ParserPool pool) {
- FilesystemMetadataProvider fileSystemProvider = null;
- try {
- fileSystemProvider = new FilesystemMetadataProvider(timer, metadataFile);
- fileSystemProvider.setParserPool(pool);
- fileSystemProvider.setRequireValidMetadata(true);
- fileSystemProvider.setMinRefreshDelay(1000 * 60 * 15); // 15 minutes
- fileSystemProvider.setMaxRefreshDelay(1000 * 60 * 60 * 24); // 24 hours
- // httpProvider.setRefreshDelayFactor(0.1F);
-
- fileSystemProvider.setMetadataFilter(filter);
- fileSystemProvider.initialize();
-
- fileSystemProvider.setRequireValidMetadata(true);
-
- return fileSystemProvider;
-
- } catch (final Exception e) {
- log.warn("Failed to load Metadata file for " + idForLogging + "[ " + "File: "
- + metadataFile.getAbsolutePath() + " Msg: " + e.getMessage() + " ]", e);
-
- log.warn("Can not initialize SAML2 metadata provider from filesystem: "
- + metadataFile.getAbsolutePath() + " Reason: " + e.getMessage(), e);
-
- if (fileSystemProvider != null) {
- fileSystemProvider.destroy();
- }
-
- }
-
- return null;
-
- }
-
- /**
- * Create a single SAML2 HTTP metadata provider.
- *
- * @param metadataUrl URL, where the metadata should be loaded
- * @param filter Filters, which should be used to validate the metadata
- * @param idForLogging Id, which is used for Logging
- * @param timer {@link Timer} which is used to schedule metadata refresh
- * operations
- * @param pool
- *
- * @return SAML2 Metadata Provider
- */
- private MetadataProvider createNewHttpMetaDataProvider(final String metadataUrl,
- final MetadataFilter filter, final String idForLogging, final Timer timer,
- final ParserPool pool, final HttpClient httpClient) {
- HTTPMetadataProvider httpProvider = null;
- try {
- httpProvider = new HTTPMetadataProvider(timer, httpClient, metadataUrl);
- httpProvider.setParserPool(pool);
- httpProvider.setRequireValidMetadata(true);
- httpProvider.setMinRefreshDelay(1000 * 60 * 15); // 15 minutes
- httpProvider.setMaxRefreshDelay(1000 * 60 * 60 * 24); // 24 hours
- // httpProvider.setRefreshDelayFactor(0.1F);
-
- httpProvider.setMetadataFilter(filter);
- httpProvider.initialize();
-
- httpProvider.setRequireValidMetadata(true);
-
- return httpProvider;
-
- } catch (final Throwable e) {
- if (e.getCause() != null && e.getCause().getCause() instanceof SSLHandshakeException) {
- log.warn("SSL-Server certificate for metadata " + metadataUrl + " not trusted.", e);
-
- }
- if (e.getCause() != null && e.getCause().getCause() instanceof SignatureValidationException) {
- log.warn("Signature verification for metadata" + metadataUrl + " FAILED.", e);
-
- }
- if (e.getCause() != null && e.getCause().getCause() instanceof SchemaValidationException) {
- log.warn("Schema validation for metadata " + metadataUrl + " FAILED.", e);
- }
-
- log.warn("Failed to load Metadata file for " + idForLogging + "[ " + e.getMessage() + " ]",
- e);
-
- if (httpProvider != null) {
- log.debug("Destroy failed Metadata provider");
- httpProvider.destroy();
- }
-
- // if (timer != null) {
- // log.debug("Destroy Timer.");
- // timer.cancel();
- // }
-
- }
-
- return null;
- }
-
-}