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

The following examples show how to use org.springframework.security.saml.metadata.MetadataGenerator. These examples are extracted from open source projects. 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 Project: blackduck-alert   Source File: SamlManagerTest.java    License: 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 Project: blackduck-alert   Source File: SamlManagerTest.java    License: 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 Project: blackduck-alert   Source File: SAMLStartupComponentTest.java    License: 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 Project: blackduck-alert   Source File: SAMLStartupComponentTest.java    License: 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 Project: blackduck-alert   Source File: SAMLManager.java    License: 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
@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 Project: spring-security-saml-dsl   Source File: SAMLConfigurer.java    License: 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
public AlertSAMLMetadataGeneratorFilter(final MetadataGenerator metadataGenerator, final SAMLContext samlContext) {
    super(metadataGenerator);
    this.samlContext = samlContext;
}
 
Example 9
public MetadataGeneratorConfigurer(MetadataGenerator metadataGenerator) {
    this.metadataGenerator = metadataGenerator;
}
 
Example 10
@Override
public void init(ServiceProviderBuilder builder) throws Exception {
    config = builder.getSharedObject(SAMLSSOProperties.class).getMetadataGenerator();
    endpoints = builder.getSharedObject(ServiceProviderEndpoints.class);
    metadataGeneratorBean = builder.getSharedObject(MetadataGenerator.class);
}