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.
This commit is contained in:
		
							parent
							
								
									404c05ad32
								
							
						
					
					
						commit
						dddf541bb8
					
				| @ -5,17 +5,19 @@ import java.util.ArrayList; | |||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  | import java.util.Timer; | ||||||
| 
 | 
 | ||||||
| import org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider; | import org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider; | ||||||
| import org.opensaml.saml2.metadata.provider.MetadataProvider; | import org.opensaml.saml2.metadata.provider.MetadataProvider; | ||||||
| import org.opensaml.saml2.metadata.provider.MetadataProviderException; | 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.util.resource.ResourceException; | ||||||
| import org.opensaml.xml.parse.StaticBasicParserPool; | import org.opensaml.xml.parse.StaticBasicParserPool; | ||||||
| import org.springframework.beans.factory.annotation.Qualifier; | import org.springframework.beans.factory.annotation.Qualifier; | ||||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||||
| import org.springframework.context.annotation.Bean; | import org.springframework.context.annotation.Bean; | ||||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||||
| import org.springframework.core.io.ClassPathResource; |  | ||||||
| import org.springframework.core.io.DefaultResourceLoader; | import org.springframework.core.io.DefaultResourceLoader; | ||||||
| import org.springframework.core.io.Resource; | import org.springframework.core.io.Resource; | ||||||
| import org.springframework.security.saml.*; | import org.springframework.security.saml.*; | ||||||
| @ -142,13 +144,19 @@ public class SamlSecurityConfig { | |||||||
|     @Bean |     @Bean | ||||||
|     @Qualifier("okta") |     @Qualifier("okta") | ||||||
|     public ExtendedMetadataDelegate oktaExtendedMetadataProvider() throws MetadataProviderException { |     public ExtendedMetadataDelegate oktaExtendedMetadataProvider() throws MetadataProviderException { | ||||||
|         File metadata = null; | 		// Use the Spring Security SAML resource mechanism to load | ||||||
|         try { |     	// metadata from the Java classpath.  This works from Spring Boot  | ||||||
|             metadata = new ClassPathResource("saml/metadata/sso.xml").getFile(); |     	// self contained JAR file. | ||||||
|         } catch (Exception e) { | 		org.opensaml.util.resource.Resource resource = null; | ||||||
|             e.printStackTrace(); | 
 | ||||||
|         } | 		try { | ||||||
|         FilesystemMetadataProvider provider = new FilesystemMetadataProvider(metadata); | 			resource = new ClasspathResource("/saml/metadata/sso.xml"); | ||||||
|  | 		} catch (ResourceException e) { | ||||||
|  | 			 e.printStackTrace(); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  |         Timer timer = new Timer("saml-metadata"); | ||||||
|  |         ResourceBackedMetadataProvider provider = new ResourceBackedMetadataProvider(timer,resource); | ||||||
|         provider.setParserPool(parserPool()); |         provider.setParserPool(parserPool()); | ||||||
|         return new ExtendedMetadataDelegate(provider, extendedMetadata()); |         return new ExtendedMetadataDelegate(provider, extendedMetadata()); | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user