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

The following examples show how to use org.springframework.security.saml.metadata.MetadataGenerator. 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: SamlManagerTest.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSamlDisabled() throws Exception {
    SAMLContext context = Mockito.mock(SAMLContext.class);
    ParserPool parserPool = Mockito.mock(ParserPool.class);
    ExtendedMetadata extendedMetadata = Mockito.mock(ExtendedMetadata.class);
    MetadataManager metadataManager = Mockito.mock(MetadataManager.class);
    MetadataGenerator metadataGenerator = Mockito.mock(MetadataGenerator.class);
    ConfigurationModel currentConfiguration = Mockito.mock(ConfigurationModel.class);
    FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
    Mockito.when(context.getCurrentConfiguration()).thenReturn(currentConfiguration);
    Mockito.when(context.isSAMLEnabled(Mockito.any(ConfigurationModel.class))).thenReturn(Boolean.FALSE.booleanValue());

    SAMLManager samlManager = new SAMLManager(parserPool, extendedMetadata, metadataManager, metadataGenerator, filePersistenceUtil, context);
    samlManager.updateSAMLConfiguration(Boolean.FALSE.booleanValue(), "metadataURL", "entityId", "baseURL");
    Mockito.verify(metadataGenerator).setEntityId(null);
    Mockito.verify(metadataGenerator).setEntityBaseURL(null);
    Mockito.verify(metadataManager).setProviders(Mockito.anyList());
    Mockito.verify(metadataManager).setDefaultIDP(null);
    Mockito.verify(metadataManager).setHostedSPName(null);
    Mockito.verify(metadataManager).afterPropertiesSet();
}
 
Example #2
Source File: SamlManagerTest.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSamlEnabled() throws Exception {
    SAMLContext context = Mockito.mock(SAMLContext.class);
    ParserPool parserPool = Mockito.mock(ParserPool.class);
    ExtendedMetadata extendedMetadata = Mockito.mock(ExtendedMetadata.class);
    MetadataManager metadataManager = Mockito.mock(MetadataManager.class);
    MetadataGenerator metadataGenerator = Mockito.mock(MetadataGenerator.class);
    ConfigurationModel currentConfiguration = Mockito.mock(ConfigurationModel.class);
    FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
    Mockito.when(context.getCurrentConfiguration()).thenReturn(currentConfiguration);
    Mockito.when(context.isSAMLEnabled(Mockito.any(ConfigurationModel.class))).thenReturn(Boolean.TRUE.booleanValue());
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.anyString())).thenReturn("metadataURL");
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.anyString())).thenReturn("entityId");
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.anyString())).thenReturn("baseURL");

    SAMLManager samlManager = new SAMLManager(parserPool, extendedMetadata, metadataManager, metadataGenerator, filePersistenceUtil, context);
    samlManager.updateSAMLConfiguration(Boolean.TRUE.booleanValue(), "metadataURL", "entityId", "baseURL");

    Mockito.verify(metadataGenerator).setEntityId(Mockito.anyString());
    Mockito.verify(metadataGenerator).setEntityBaseURL(Mockito.anyString());
    // these methods are called to clear the existing metadata and then set it if true.
    Mockito.verify(metadataManager, Mockito.times(2)).setProviders(Mockito.anyList());
    Mockito.verify(metadataManager, Mockito.times(2)).afterPropertiesSet();
}
 
Example #3
Source File: SAMLStartupComponentTest.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialize() throws Exception {
    SAMLContext context = Mockito.mock(SAMLContext.class);
    ParserPool parserPool = Mockito.mock(ParserPool.class);
    ExtendedMetadata extendedMetadata = Mockito.mock(ExtendedMetadata.class);
    MetadataManager metadataManager = Mockito.mock(MetadataManager.class);
    MetadataGenerator metadataGenerator = Mockito.mock(MetadataGenerator.class);
    ConfigurationModel currentConfiguration = Mockito.mock(ConfigurationModel.class);
    FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
    Mockito.when(context.getCurrentConfiguration()).thenReturn(currentConfiguration);
    Mockito.when(context.isSAMLEnabled(Mockito.any(ConfigurationModel.class))).thenReturn(Boolean.TRUE.booleanValue());
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.anyString())).thenReturn("metadataURL");
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.anyString())).thenReturn("entityId");
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.anyString())).thenReturn("baseURL");

    SAMLManager samlManager = new SAMLManager(parserPool, extendedMetadata, metadataManager, metadataGenerator, filePersistenceUtil, context);
    SAMLStartupComponent startupComponent = new SAMLStartupComponent(context, samlManager);
    startupComponent.initializeComponent();

    Mockito.verify(metadataGenerator).setEntityId(Mockito.anyString());
    Mockito.verify(metadataGenerator).setEntityBaseURL(Mockito.anyString());
    Mockito.verify(metadataManager, Mockito.times(2)).setProviders(Mockito.anyList());
    Mockito.verify(metadataManager, Mockito.times(2)).afterPropertiesSet();
}
 
Example #4
Source File: SAMLStartupComponentTest.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitializeException() throws Exception {
    SAMLContext context = Mockito.mock(SAMLContext.class);
    ParserPool parserPool = Mockito.mock(ParserPool.class);
    ExtendedMetadata extendedMetadata = Mockito.mock(ExtendedMetadata.class);
    MetadataManager metadataManager = Mockito.mock(MetadataManager.class);
    MetadataGenerator metadataGenerator = Mockito.mock(MetadataGenerator.class);
    FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
    Mockito.when(context.getCurrentConfiguration()).thenThrow(new AlertDatabaseConstraintException("Test exception"));

    SAMLManager samlManager = new SAMLManager(parserPool, extendedMetadata, metadataManager, metadataGenerator, filePersistenceUtil, context);
    SAMLStartupComponent startupComponent = new SAMLStartupComponent(context, samlManager);
    startupComponent.initializeComponent();

    Mockito.verify(metadataGenerator, Mockito.times(0)).setEntityId(Mockito.anyString());
    Mockito.verify(metadataGenerator, Mockito.times(0)).setEntityBaseURL(Mockito.anyString());
    Mockito.verify(metadataManager, Mockito.times(0)).setProviders(Mockito.anyList());
    Mockito.verify(metadataManager, Mockito.times(0)).afterPropertiesSet();
}
 
Example #5
Source File: SAMLManager.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
public SAMLManager(ParserPool parserPool, ExtendedMetadata extendedMetadata, MetadataManager metadataManager, MetadataGenerator metadataGenerator,
    FilePersistenceUtil filePersistenceUtil, SAMLContext samlContext) {
    this.parserPool = parserPool;
    this.extendedMetadata = extendedMetadata;
    this.metadataManager = metadataManager;
    this.metadataGenerator = metadataGenerator;
    this.filePersistenceUtil = filePersistenceUtil;
    this.samlContext = samlContext;
}
 
Example #6
Source File: SAMLServiceProviderSecurityConfiguration.java    From spring-boot-security-saml with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
    //All existing beans are thrown as shared objects to the ServiceProviderSecurityBuilder, which will wire all
    //beans/objects related to spring security SAML.
    serviceProviderBuilder.setSharedObject(ParserPool.class, ParserPoolHolder.getPool());
    serviceProviderBuilder.setSharedObject(WebSSOProfileConsumerImpl.class, (WebSSOProfileConsumerImpl) webSSOProfileConsumer);
    serviceProviderBuilder.setSharedObject(WebSSOProfileConsumerHoKImpl.class, hokWebSSOProfileConsumer);
    serviceProviderBuilder.setSharedObject(ServiceProviderEndpoints.class, new ServiceProviderEndpoints());
    serviceProviderBuilder.setSharedObject(ResourceLoader.class, resourceLoader);
    serviceProviderBuilder.setSharedObject(SAMLSSOProperties.class, sAMLSsoProperties);
    serviceProviderBuilder.setSharedObject(ExtendedMetadata.class, extendedMetadata);
    serviceProviderBuilder.setSharedObject(LocalExtendedMetadata.class, localExtendedMetadata);
    serviceProviderBuilder.setSharedObject(SAMLAuthenticationProvider.class, samlAuthenticationProvider);
    serviceProviderBuilder.setSharedObject(SAMLContextProvider.class, samlContextProvider);
    serviceProviderBuilder.setSharedObject(KeyManager.class, keyManager);
    serviceProviderBuilder.setSharedObject(MetadataManager.class, metadataManager);
    serviceProviderBuilder.setSharedObject(MetadataGenerator.class, metadataGenerator);
    serviceProviderBuilder.setSharedObject(SAMLProcessor.class, samlProcessor);
    serviceProviderBuilder.setSharedObject(WebSSOProfile.class, webSSOProfile);
    serviceProviderBuilder.setSharedObject(WebSSOProfileECPImpl.class, ecpProfile);
    serviceProviderBuilder.setSharedObject(WebSSOProfileHoKImpl.class, hokWebSSOProfile);
    serviceProviderBuilder.setSharedObject(SingleLogoutProfile.class, sloProfile);
    serviceProviderBuilder.setSharedObject(WebSSOProfileConsumer.class, webSSOProfileConsumer);
    serviceProviderBuilder.setSharedObject(WebSSOProfileConsumerHoKImpl.class, hokWebSSOProfileConsumer);
    serviceProviderBuilder.setSharedObject(SAMLLogger.class, samlLogger);
    serviceProviderBuilder.setSharedObject(ApplicationEventPublisher.class, eventPublisher);
}
 
Example #7
Source File: SAMLConfigurer.java    From spring-security-saml-dsl with MIT License 5 votes vote down vote up
private MetadataGenerator getMetadataGenerator(SAMLEntryPoint samlEntryPoint, ExtendedMetadata extendedMetadata) {
	MetadataGenerator metadataGenerator = new MetadataGenerator();

	metadataGenerator.setSamlEntryPoint(samlEntryPoint);
	metadataGenerator.setEntityBaseURL(entityBaseURL());
	metadataGenerator.setKeyManager(serviceProvider.keyManager);
	metadataGenerator.setEntityId(serviceProvider.entityId);
	metadataGenerator.setIncludeDiscoveryExtension(false);
	metadataGenerator.setExtendedMetadata(extendedMetadata);

	return metadataGenerator;
}
 
Example #8
Source File: AlertSAMLMetadataGeneratorFilter.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
public AlertSAMLMetadataGeneratorFilter(final MetadataGenerator metadataGenerator, final SAMLContext samlContext) {
    super(metadataGenerator);
    this.samlContext = samlContext;
}
 
Example #9
Source File: MetadataGeneratorConfigurer.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
public MetadataGeneratorConfigurer(MetadataGenerator metadataGenerator) {
    this.metadataGenerator = metadataGenerator;
}
 
Example #10
Source File: MetadataGeneratorConfigurer.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@Override
public void init(ServiceProviderBuilder builder) throws Exception {
    config = builder.getSharedObject(SAMLSSOProperties.class).getMetadataGenerator();
    endpoints = builder.getSharedObject(ServiceProviderEndpoints.class);
    metadataGeneratorBean = builder.getSharedObject(MetadataGenerator.class);
}