org.springframework.security.saml.metadata.CachingMetadataManager Java Examples

The following examples show how to use org.springframework.security.saml.metadata.CachingMetadataManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InsightsSecurityConfigurationAdapterSAML.java    From Insights with Apache License 2.0 5 votes vote down vote up
/**
 * used to provide Metadata Manager
 * 
 * @return
 * @throws MetadataProviderException
 */
@Bean
@Qualifier("metadata")
@Conditional(InsightsSAMLBeanInitializationCondition.class)
public CachingMetadataManager metadata() throws MetadataProviderException {
	List<MetadataProvider> providers = new ArrayList<>();
	providers.add(idpMetadata());
	return new CachingMetadataManager(providers);
}
 
Example #2
Source File: MetadataManagerConfigurerTest.java    From spring-boot-security-saml with MIT License 5 votes vote down vote up
@Test
public void configure_defaults() throws Exception {
    MetadataManagerConfigurer configurer = spy(new MetadataManagerConfigurer());
    CachingMetadataManager metadataManager = mock(CachingMetadataManager.class);
    when(configurer.createDefaultMetadataManager()).thenReturn(metadataManager);
    ExtendedMetadataDelegate delegate = mock(ExtendedMetadataDelegate.class);
    doReturn(delegate).when(configurer).createDefaultExtendedMetadataDelegate(any(), any());
    configurer.setBuilder(builder);
    configurer.init(builder);
    configurer.configure(builder);
    verify(builder).setSharedObject(eq(MetadataManager.class), eq(metadataManager));
    ArgumentCaptor<List> providersCaptor = ArgumentCaptor.forClass(List.class);
    verify(metadataManager).setProviders((List<MetadataProvider>) providersCaptor.capture());
    verify(configurer).createDefaultMetadataProvider(eq(idpConfiguration.getMetadataLocation()));
    verify(configurer).createDefaultExtendedMetadataDelegate(any(ResourceBackedMetadataProvider.class), any());
    verify(metadataManagerProperties).getDefaultIdp();
    verify(metadataManagerProperties).getHostedSpName();
    verify(metadataManagerProperties).getRefreshCheckInterval();
    verify(extendedMetadataDelegateProperties).isForceMetadataRevocationCheck();
    verify(extendedMetadataDelegateProperties).isMetadataRequireSignature();
    verify(extendedMetadataDelegateProperties).isMetadataTrustCheck();
    verify(extendedMetadataDelegateProperties).isRequireValidMetadata();
    verify(extendedMetadataDelegateProperties).getMetadataTrustedKeys();
    List<MetadataProvider> providers = providersCaptor.getValue();
    assertThat(providers).hasSize(1);
    assertThat(providers.get(0)).isEqualTo(delegate);
    verify(metadataManager).setDefaultIDP(eq(metadataManagerProperties.getDefaultIdp()));
    verify(metadataManager).setHostedSPName(eq(metadataManagerProperties.getHostedSpName()));
    verify(metadataManager).setRefreshCheckInterval(eq(metadataManagerProperties.getRefreshCheckInterval()));
    verify(delegate).setForceMetadataRevocationCheck(eq(extendedMetadataDelegateProperties.isForceMetadataRevocationCheck()));
    verify(delegate).setMetadataRequireSignature(eq(extendedMetadataDelegateProperties.isMetadataRequireSignature()));
    verify(delegate).setMetadataTrustCheck(eq(extendedMetadataDelegateProperties.isMetadataTrustCheck()));
    verify(delegate).setMetadataTrustedKeys(eq(extendedMetadataDelegateProperties.getMetadataTrustedKeys()));
    verify(delegate).setRequireValidMetadata(eq(extendedMetadataDelegateProperties.isRequireValidMetadata()));
    verify(delegate).setMetadataFilter((MetadataFilter) isNull());
}
 
Example #3
Source File: MetadataManagerConfigurerTest.java    From spring-boot-security-saml with MIT License 5 votes vote down vote up
@Test
public void configure_defaults_withProvider() throws Exception {
    MetadataManagerConfigurer configurer = spy(new MetadataManagerConfigurer());
    CachingMetadataManager metadataManager = mock(CachingMetadataManager.class);
    when(configurer.createDefaultMetadataManager()).thenReturn(metadataManager);
    configurer.setBuilder(builder);
    AbstractMetadataProvider provider = mock(AbstractMetadataProvider.class);
    configurer.metadataProvider(provider);
    configurer.init(builder);
    configurer.configure(builder);
    verify(builder).setSharedObject(eq(MetadataManager.class), eq(metadataManager));
    ArgumentCaptor<List> providersCaptor = ArgumentCaptor.forClass(List.class);
    verify(provider).setParserPool(eq(parserPool));
    verify(metadataManager).setProviders((List<MetadataProvider>) providersCaptor.capture());
    verify(configurer, never()).createDefaultMetadataProvider(eq(idpConfiguration.getMetadataLocation()));
    verify(configurer, never()).createDefaultExtendedMetadataDelegate(any(ResourceBackedMetadataProvider.class), any());
    verify(metadataManagerProperties).getDefaultIdp();
    verify(metadataManagerProperties).getHostedSpName();
    verify(metadataManagerProperties).getRefreshCheckInterval();
    verify(extendedMetadataDelegateProperties).isForceMetadataRevocationCheck();
    verify(extendedMetadataDelegateProperties).isMetadataRequireSignature();
    verify(extendedMetadataDelegateProperties).isMetadataTrustCheck();
    verify(extendedMetadataDelegateProperties).isRequireValidMetadata();
    verify(extendedMetadataDelegateProperties).getMetadataTrustedKeys();
    List<MetadataProvider> providers = providersCaptor.getValue();
    assertThat(providers).hasSize(1);
    assertThat(providers.get(0)).isExactlyInstanceOf(ExtendedMetadataDelegate.class);
    assertThat(((ExtendedMetadataDelegate) providers.get(0)).getDelegate()).isEqualTo(provider);
}
 
Example #4
Source File: MetadataManagerConfigurerTest.java    From spring-boot-security-saml with MIT License 5 votes vote down vote up
@Test
public void configure_defaults_withProviderDelegate() throws Exception {
    MetadataManagerConfigurer configurer = spy(new MetadataManagerConfigurer());
    CachingMetadataManager metadataManager = mock(CachingMetadataManager.class);
    when(configurer.createDefaultMetadataManager()).thenReturn(metadataManager);
    configurer.setBuilder(builder);
    MetadataProvider provider = mock(ExtendedMetadataDelegate.class);
    configurer.metadataProvider(provider);
    configurer.init(builder);
    configurer.configure(builder);
    verify(builder).setSharedObject(eq(MetadataManager.class), eq(metadataManager));
    ArgumentCaptor<List> providersCaptor = ArgumentCaptor.forClass(List.class);
    verify(metadataManager).setProviders((List<MetadataProvider>) providersCaptor.capture());
    verify(configurer, never()).createDefaultMetadataProvider(eq(idpConfiguration.getMetadataLocation()));
    verify(configurer, never()).createDefaultExtendedMetadataDelegate(any(ResourceBackedMetadataProvider.class), any());
    verify(metadataManagerProperties).getDefaultIdp();
    verify(metadataManagerProperties).getHostedSpName();
    verify(metadataManagerProperties).getRefreshCheckInterval();
    verify(extendedMetadataDelegateProperties, never()).isForceMetadataRevocationCheck();
    verify(extendedMetadataDelegateProperties, never()).isMetadataRequireSignature();
    verify(extendedMetadataDelegateProperties, never()).isMetadataTrustCheck();
    verify(extendedMetadataDelegateProperties, never()).isRequireValidMetadata();
    verify(extendedMetadataDelegateProperties, never()).getMetadataTrustedKeys();
    List<MetadataProvider> providers = providersCaptor.getValue();
    assertThat(providers).hasSize(1);
    assertThat(providers.get(0)).isEqualTo(provider);
    assertThat(((ExtendedMetadataDelegate) providers.get(0)).getDelegate()).isNull();
}
 
Example #5
Source File: MetadataManagerConfigurerTest.java    From spring-boot-security-saml with MIT License 5 votes vote down vote up
@Test
public void configure_defaults_withProviderLocation() throws Exception {
    MetadataManagerConfigurer configurer = spy(new MetadataManagerConfigurer());
    CachingMetadataManager metadataManager = mock(CachingMetadataManager.class);
    when(configurer.createDefaultMetadataManager()).thenReturn(metadataManager);
    configurer.setBuilder(builder);
    configurer.metadataLocations("classpath:idp-provided.xml");
    configurer.init(builder);
    configurer.configure(builder);
    verify(builder).setSharedObject(eq(MetadataManager.class), eq(metadataManager));
    ArgumentCaptor<List> providersCaptor = ArgumentCaptor.forClass(List.class);
    verify(metadataManager).setProviders((List<MetadataProvider>) providersCaptor.capture());
    verify(configurer).createDefaultMetadataProvider(eq("classpath:idp-provided.xml"));
    verify(configurer).createDefaultExtendedMetadataDelegate(any(ResourceBackedMetadataProvider.class), any());
    verify(metadataManagerProperties).getDefaultIdp();
    verify(metadataManagerProperties).getHostedSpName();
    verify(metadataManagerProperties).getRefreshCheckInterval();
    verify(extendedMetadataDelegateProperties).isForceMetadataRevocationCheck();
    verify(extendedMetadataDelegateProperties).isMetadataRequireSignature();
    verify(extendedMetadataDelegateProperties).isMetadataTrustCheck();
    verify(extendedMetadataDelegateProperties).isRequireValidMetadata();
    verify(extendedMetadataDelegateProperties).getMetadataTrustedKeys();
    List<MetadataProvider> providers = providersCaptor.getValue();
    assertThat(providers).hasSize(1);
    assertThat(providers.get(0)).isExactlyInstanceOf(ExtendedMetadataDelegate.class);
    assertThat(((ExtendedMetadataDelegate) providers.get(0)).getDelegate()).isExactlyInstanceOf(ResourceBackedMetadataProvider.class);
}
 
Example #6
Source File: WebSecurityConfig.java    From spring-boot-security-saml-sample with Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("metadata")
public CachingMetadataManager metadata() throws MetadataProviderException {
    List<MetadataProvider> providers = new ArrayList<MetadataProvider>();
    providers.add(ssoCircleExtendedMetadataProvider());
    return new CachingMetadataManager(providers);
}
 
Example #7
Source File: AuthenticationHandler.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@Bean
@Qualifier("metadata")
public CachingMetadataManager metadata() throws MetadataProviderException {
    return new CachingMetadataManager(Collections.emptyList());
}
 
Example #8
Source File: MetadataManagerConfigurer.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@VisibleForTesting
protected CachingMetadataManager createDefaultMetadataManager() throws MetadataProviderException {
    return new CachingMetadataManager(null);
}
 
Example #9
Source File: MetadataManagerConfigurerTest.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@Test
public void configure_arguments() throws Exception {
    MetadataManagerConfigurer configurer = spy(new MetadataManagerConfigurer());
    CachingMetadataManager metadataManager = mock(CachingMetadataManager.class);
    when(configurer.createDefaultMetadataManager()).thenReturn(metadataManager);
    ResourceBackedMetadataProvider provider = mock(ResourceBackedMetadataProvider.class);
    doReturn(provider).when(configurer).createDefaultMetadataProvider("classpath:idp-provided.xml");
    ExtendedMetadataDelegate delegate = mock(ExtendedMetadataDelegate.class);
    doReturn(delegate).when(configurer).createDefaultExtendedMetadataDelegate(eq(provider), any(ExtendedMetadata.class));
    MetadataFilter metadataFilter = mock(MetadataFilter.class);
    configurer.setBuilder(builder);
    configurer
            .metadataLocations("classpath:idp-provided.xml")
            .defaultIDP("default")
            .hostedSPName("spname")
            .refreshCheckInterval(999L)
            .forceMetadataRevocationCheck(true)
            .metadataRequireSignature(true)
            .metadataTrustCheck(true)
            .requireValidMetadata(true)
            .metadataTrustedKeys("one", "two")
            .metadataFilter(metadataFilter);
    configurer.init(builder);
    configurer.configure(builder);
    verify(builder).setSharedObject(eq(MetadataManager.class), eq(metadataManager));
    ArgumentCaptor<List> providersCaptor = ArgumentCaptor.forClass(List.class);
    verify(metadataManager).setProviders((List<MetadataProvider>) providersCaptor.capture());
    verify(configurer).createDefaultMetadataProvider(eq("classpath:idp-provided.xml"));
    verify(configurer).createDefaultExtendedMetadataDelegate(eq(provider), any());
    verify(metadataManagerProperties, never()).getDefaultIdp();
    verify(metadataManagerProperties, never()).getHostedSpName();
    verify(metadataManagerProperties, never()).getRefreshCheckInterval();
    verify(extendedMetadataDelegateProperties, never()).isForceMetadataRevocationCheck();
    verify(extendedMetadataDelegateProperties, never()).isMetadataRequireSignature();
    verify(extendedMetadataDelegateProperties, never()).isMetadataTrustCheck();
    verify(extendedMetadataDelegateProperties, never()).isRequireValidMetadata();
    verify(extendedMetadataDelegateProperties, never()).getMetadataTrustedKeys();
    List<MetadataProvider> providers = providersCaptor.getValue();
    assertThat(providers).hasSize(1);
    assertThat(providers.get(0)).isEqualTo(delegate);
    verify(metadataManager).setDefaultIDP(eq("default"));
    verify(metadataManager).setHostedSPName(eq("spname"));
    verify(metadataManager).setRefreshCheckInterval(eq(999L));
    verify(delegate).setForceMetadataRevocationCheck(eq(true));
    verify(delegate).setMetadataRequireSignature(eq(true));
    verify(delegate).setMetadataTrustCheck(eq(true));
    verify(delegate).setMetadataTrustedKeys((Set<String>) MockitoHamcrest.argThat(contains("one", "two")));
    verify(delegate).setRequireValidMetadata(eq(true));
    verify(delegate).setMetadataFilter(eq(metadataFilter));
}
 
Example #10
Source File: SAMLConfigDefaults.java    From spring-boot-security-saml-samples with MIT License 4 votes vote down vote up
@Bean
public CachingMetadataManager metadataManager(List<MetadataProvider> metadataProviders) throws MetadataProviderException {
    return new CachingMetadataManager(metadataProviders);
}