Revised to use built in Sprint Security SAML resource resolution.  Otherwise when used from Spring Boot self-contained JAR the File could not be located.
@@ -5,17 +5,19 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Timer;
import org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider;
import org.opensaml.saml2.metadata.provider.MetadataProvider;
import org.opensaml.saml2.metadata.provider.MetadataProviderException;
+import org.opensaml.saml2.metadata.provider.ResourceBackedMetadataProvider;
+import org.opensaml.util.resource.ClasspathResource;
import org.opensaml.util.resource.ResourceException;
import org.opensaml.xml.parse.StaticBasicParserPool;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.security.saml.*;
@@ -142,13 +144,19 @@ public class SamlSecurityConfig {
@Bean
@Qualifier("okta")
public ExtendedMetadataDelegate oktaExtendedMetadataProvider() throws MetadataProviderException {
- File metadata = null;
+ // Use the Spring Security SAML resource mechanism to load
+ // metadata from the Java classpath. This works from Spring Boot
+ // self contained JAR file.
+ org.opensaml.util.resource.Resource resource = null;
+
try {
- metadata = new ClassPathResource("saml/metadata/sso.xml").getFile();
- } catch (Exception e) {
+ resource = new ClasspathResource("/saml/metadata/sso.xml");
+ } catch (ResourceException e) {
e.printStackTrace();
}
- FilesystemMetadataProvider provider = new FilesystemMetadataProvider(metadata);
+
+ Timer timer = new Timer("saml-metadata");
+ ResourceBackedMetadataProvider provider = new ResourceBackedMetadataProvider(timer,resource);
provider.setParserPool(parserPool());
return new ExtendedMetadataDelegate(provider, extendedMetadata());
}
