Java Code Examples for org.opensaml.xml.parse.ParserPool

The following examples show how to use org.opensaml.xml.parse.ParserPool. 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
@Before
public void setup() {
    properties = mock(SAMLSSOProperties.class);
    metadataManagerProperties = spy(new MetadataManagerProperties());
    extendedMetadataDelegateProperties = spy(new ExtendedMetadataDelegateProperties());
    idpConfiguration = spy(new IdentityProvidersProperties());
    extendedMetadata = spy(new ExtendedMetadata());
    when(properties.getMetadataManager()).thenReturn(metadataManagerProperties);
    when(properties.getExtendedDelegate()).thenReturn(extendedMetadataDelegateProperties);
    when(properties.getIdp()).thenReturn(idpConfiguration);
    builder = mock(ServiceProviderBuilder.class);
    when(builder.getSharedObject(SAMLSSOProperties.class)).thenReturn(properties);
    when(builder.getSharedObject(ExtendedMetadata.class)).thenReturn(extendedMetadata);
    resourceLoader = new DefaultResourceLoader();
    when(builder.getSharedObject(ResourceLoader.class)).thenReturn(resourceLoader);
    parserPool = mock(ParserPool.class);
    when(builder.getSharedObject(ParserPool.class)).thenReturn(parserPool);
}
 
Example 6
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 7
Source Project: lams   Source File: BaseMessageDecoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param pool parser pool used to deserialize messages
 */
public BaseMessageDecoder(ParserPool pool) {
    if (pool == null) {
        throw new IllegalArgumentException("Parser pool may not be null");
    }

    parserPool = pool;
}
 
Example 8
Source Project: lams   Source File: BaseMessageDecoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the parser pool used to deserialize incomming messages.
 * 
 * @param pool parser pool used to deserialize incomming messages
 */
protected void setParserPool(ParserPool pool) {
    if (pool == null) {
        throw new IllegalArgumentException("Parser pool may not be null");
    }
    parserPool = pool;
}
 
Example 9
Source Project: lams   Source File: HttpSOAPClient.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param client Client used to make outbound HTTP requests. This client SHOULD employ a
 *            {@link org.apache.commons.httpclient.MultiThreadedHttpConnectionManager} and may be shared with other
 *            objects.
 * @param parser pool of XML parsers used to parse incoming responses
 */
public HttpSOAPClient(HttpClient client, ParserPool parser) {
    if (client == null) {
        throw new IllegalArgumentException("HtppClient may not be null");
    }
    httpClient = client;

    if (parser == null) {
        throw new IllegalArgumentException("ParserPool may not be null");
    }
    parserPool = parser;
}
 
Example 10
Source Project: lams   Source File: XMLObjectHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unmarshall a Document from an InputSteam.
 * 
 * @param parserPool the ParserPool instance to use
 * @param inputStream the InputStream to unmarshall
 * @return the unmarshalled XMLObject
 * @throws XMLParserException if there is a problem parsing the input data
 * @throws UnmarshallingException if there is a problem unmarshalling the parsed DOM
 */
public static XMLObject unmarshallFromInputStream(ParserPool parserPool, InputStream inputStream)
        throws XMLParserException, UnmarshallingException {
    Logger log = getLogger();
    log.debug("Parsing InputStream into DOM document");

    Document messageDoc = parserPool.parse(inputStream);
    Element messageElem = messageDoc.getDocumentElement();

    if (log.isTraceEnabled()) {
        log.trace("Resultant DOM message was:");
        log.trace(XMLHelper.nodeToString(messageElem));
    }

    log.debug("Unmarshalling DOM parsed from InputStream");
    Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(messageElem);
    if (unmarshaller == null) {
        log.error("Unable to unmarshall InputStream, no unmarshaller registered for element "
                + XMLHelper.getNodeQName(messageElem));
        throw new UnmarshallingException(
                "Unable to unmarshall InputStream, no unmarshaller registered for element "
                        + XMLHelper.getNodeQName(messageElem));
    }

    XMLObject message = unmarshaller.unmarshall(messageElem);

    log.debug("InputStream succesfully unmarshalled");
    return message;
}
 
Example 11
Source Project: lams   Source File: XMLObjectHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unmarshall a Document from a Reader.
 * 
 * @param parserPool the ParserPool instance to use
 * @param reader the Reader to unmarshall
 * @return the unmarshalled XMLObject
 * @throws XMLParserException if there is a problem parsing the input data
 * @throws UnmarshallingException if there is a problem unmarshalling the parsed DOM
 */
public static XMLObject unmarshallFromReader(ParserPool parserPool, Reader reader)
        throws XMLParserException, UnmarshallingException {
    Logger log = getLogger();
    log.debug("Parsing Reader into DOM document");
    

    Document messageDoc = parserPool.parse(reader);
    Element messageElem = messageDoc.getDocumentElement();

    if (log.isTraceEnabled()) {
        log.trace("Resultant DOM message was:");
        log.trace(XMLHelper.nodeToString(messageElem));
    }

    log.debug("Unmarshalling DOM parsed from Reader");
    Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(messageElem);
    if (unmarshaller == null) {
        log.error("Unable to unmarshall Reader, no unmarshaller registered for element "
                + XMLHelper.getNodeQName(messageElem));
        throw new UnmarshallingException(
                "Unable to unmarshall Reader, no unmarshaller registered for element "
                        + XMLHelper.getNodeQName(messageElem));
    }

    XMLObject message = unmarshaller.unmarshall(messageElem);

    log.debug("Reader succesfully unmarshalled");
    return message;
}
 
Example 12
@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 13
@Before
public void setup() {
    properties = mock(SAMLSSOProperties.class);
    samlProcessorConfig = spy(new SAMLProcessorProperties());
    when(properties.getSamlProcessor()).thenReturn(samlProcessorConfig);
    builder = mock(ServiceProviderBuilder.class);
    parserPool = mock(ParserPool.class);
    when(builder.getSharedObject(ParserPool.class)).thenReturn(parserPool);
    when(builder.getSharedObject(SAMLSSOProperties.class)).thenReturn(properties);
}
 
Example 14
Source Project: spring-tsers-auth   Source File: WebSecurityConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("idp-ssocircle")
public ExtendedMetadataDelegate ssoCircleExtendedMetadataProvider()
        throws MetadataProviderException {


    AbstractMetadataProvider provider = new AbstractMetadataProvider() {
        @Override
        protected XMLObject doGetMetadata() throws MetadataProviderException {
            DefaultResourceLoader loader = new DefaultResourceLoader();
            Resource storeFile = loader.getResource("classPath:/saml/idp-metadata.xml");

            ParserPool parser = parserPool();
            try {
                Document mdDocument = parser.parse(storeFile.getInputStream());
                Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(mdDocument.getDocumentElement());
                return unmarshaller.unmarshall(mdDocument.getDocumentElement());
            } catch (Exception e) {
                e.printStackTrace();
                throw new MetadataProviderException();
            }


        }
    };
    ExtendedMetadataDelegate extendedMetadataDelegate =
            new ExtendedMetadataDelegate(provider, extendedMetadata());
    extendedMetadataDelegate.setMetadataTrustCheck(false);
    extendedMetadataDelegate.setMetadataRequireSignature(false);
    return extendedMetadataDelegate;
}
 
Example 15
private MetadataProvider setParserPool(MetadataProvider provider) {
    if (provider instanceof AbstractMetadataProvider) {
        ((AbstractMetadataProvider) provider).setParserPool(getBuilder().getSharedObject(ParserPool.class));
    }
    return provider;
}
 
Example 16
@Override
public void init(ServiceProviderBuilder builder) throws Exception {
    sAMLProcessorBean = builder.getSharedObject(SAMLProcessor.class);
    processorConfig = builder.getSharedObject(SAMLSSOProperties.class).getSamlProcessor();
    parserPool = builder.getSharedObject(ParserPool.class);
}
 
Example 17
@Bean(initMethod = "initialize")
@ConditionalOnMissingBean
public ParserPool parserPool() {
    return new StaticBasicParserPool();
}
 
Example 18
Source Project: spring-tsers-auth   Source File: WebSecurityConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public HTTPArtifactBinding artifactBinding(ParserPool parserPool, VelocityEngine velocityEngine) {
    return new HTTPArtifactBinding(parserPool, velocityEngine, artifactResolutionProfile());
}
 
Example 19
Source Project: MaxKey   Source File: OpenHTTPPostDecoder.java    License: Apache License 2.0 4 votes vote down vote up
public OpenHTTPPostDecoder(ParserPool pool) {
    super(pool);
}
 
Example 20
Source Project: MaxKey   Source File: OpenHTTPPostSimpleSignDecoder.java    License: Apache License 2.0 4 votes vote down vote up
public OpenHTTPPostSimpleSignDecoder(ParserPool pool) {
	super(pool);
}
 
Example 21
Source Project: MaxKey   Source File: OpenHTTPRedirectDecoder.java    License: Apache License 2.0 4 votes vote down vote up
public OpenHTTPRedirectDecoder(ParserPool pool) {
	super(pool);
}
 
Example 22
Source Project: spring-security-saml-dsl   Source File: SAMLConfigurer.java    License: MIT License 4 votes vote down vote up
private HTTPPostBinding httpPostBinding(ParserPool parserPool) {
	return new HTTPPostBinding(parserPool, VelocityFactory.getEngine());
}
 
Example 23
Source Project: spring-security-saml-dsl   Source File: SAMLConfigurer.java    License: MIT License 4 votes vote down vote up
private HTTPRedirectDeflateBinding httpRedirectDeflateBinding(ParserPool parserPool) {
	return new HTTPRedirectDeflateBinding(parserPool);
}
 
Example 24
@Bean
public HTTPArtifactBinding artifactBinding(ParserPool parserPool, VelocityEngine velocityEngine) {
    return new HTTPArtifactBinding(parserPool, velocityEngine, artifactResolutionProfile());
}
 
Example 25
/**
 * Constructor.
 * 
 * @param engine the trust engine to use
 * @param parserPool the parser pool used to parse the KeyInfo request parameter
 * @param keyInfoCredResolver the KeyInfo credential resovler to use to extract credentials from the KeyInfo request
 *            parameter
 */
public SAML2HTTPPostSimpleSignRule(SignatureTrustEngine engine, ParserPool parserPool,
        KeyInfoCredentialResolver keyInfoCredResolver) {
    super(engine);
    parser = parserPool;
    keyInfoResolver = keyInfoCredResolver;
}
 
Example 26
/**
 * Constructor.
 *
 * @param pool parser pool used to deserialize messages
 */
public BaseHandlerChainAwareMessageDecoder(ParserPool pool) {
    super(pool);
}
 
Example 27
Source Project: lams   Source File: BaseMessageDecoder.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the parser pool used to deserialize incomming messages.
 * 
 * @return parser pool used to deserialize incomming messages
 */
protected ParserPool getParserPool() {
    return parserPool;
}
 
Example 28
Source Project: lams   Source File: HTTPSOAP11Decoder.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor.
 * 
 * @param pool parser pool used to deserialize messages
 */
public HTTPSOAP11Decoder(ParserPool pool) {
    super(pool);
}
 
Example 29
Source Project: lams   Source File: SOAP11Decoder.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor.
 * 
 * @param pool parser pool used to deserialize messages
 */
public SOAP11Decoder(ParserPool pool) {
    super(pool);
}
 
Example 30
Source Project: lams   Source File: Configuration.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the currently configured ParserPool instance.
 * 
 * @return the currently ParserPool
 */
public static ParserPool getParserPool() {
    return parserPool;
}