Search in sources :

Example 1 with STSRESTOutInterceptor

use of org.talend.esb.security.saml.STSRESTOutInterceptor in project tesb-rt-se by Talend.

the class STSRESTOutInterceptorTest method handleMessageNotRequestor.

@Test
public void handleMessageNotRequestor() throws Exception {
    STSRESTOutInterceptor i = new STSRESTOutInterceptor();
    Message message = createMock(Message.class);
    message.get(Message.REQUESTOR_ROLE);
    expectLastCall().andReturn(false).anyTimes();
    STSClient stsClient = createMock(STSClient.class);
    i.setStsClient(stsClient);
    assertSame(stsClient, i.getStsClient());
    replay(message);
    i.handleMessage(message);
    verify(message);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) Message(org.apache.cxf.message.Message) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) Test(org.junit.Test)

Example 2 with STSRESTOutInterceptor

use of org.talend.esb.security.saml.STSRESTOutInterceptor in project tesb-rt-se by Talend.

the class STSRESTOutInterceptorTest method handleMessageNoStsClient.

@Test
public void handleMessageNoStsClient() throws Exception {
    STSRESTOutInterceptor i = new STSRESTOutInterceptor();
    Message message = createMock(Message.class);
    message.get(Message.REQUESTOR_ROLE);
    expectLastCall().andReturn(true).anyTimes();
    i.setStsClient(null);
    assertSame(null, i.getStsClient());
    replay(message);
    i.handleMessage(message);
    verify(message);
}
Also used : Message(org.apache.cxf.message.Message) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) Test(org.junit.Test)

Example 3 with STSRESTOutInterceptor

use of org.talend.esb.security.saml.STSRESTOutInterceptor in project tesb-rt-se by Talend.

the class SAMLRESTUtilsTest method configureClientTest.

@Test
public void configureClientTest() throws Exception {
    AbstractJAXRSFactoryBean clientFactory = createMock(AbstractJAXRSFactoryBean.class);
    STSClient stsClient = createMock(STSClient.class);
    List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
    expect(clientFactory.getOutInterceptors()).andReturn(interceptors).anyTimes();
    replay(clientFactory);
    SAMLRESTUtils.configureClient(clientFactory, stsClient);
    assertFalse(interceptors.isEmpty());
    for (Interceptor<? extends Message> i : interceptors) {
        if (i instanceof STSRESTOutInterceptor) {
            assertSame(((STSRESTOutInterceptor) i).getStsClient(), stsClient);
        }
    }
    EasyMock.verify(clientFactory);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) AbstractJAXRSFactoryBean(org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean) Interceptor(org.apache.cxf.interceptor.Interceptor) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) Test(org.junit.Test)

Example 4 with STSRESTOutInterceptor

use of org.talend.esb.security.saml.STSRESTOutInterceptor in project tesb-rt-se by Talend.

the class STSRESTOutInterceptorTest method handleMessage.

@Test
public void handleMessage() throws Exception {
    STSRESTOutInterceptor i = new STSRESTOutInterceptor();
    Message message = createMock(Message.class);
    STSClient stsClient = createMock(STSClient.class);
    stsClient.requestSecurityToken(EasyMock.<String>anyObject());
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    stsClient.setActAs(EasyMock.<String>anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    stsClient.setOnBehalfOf(EasyMock.<Object>anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    stsClient.setMessage(EasyMock.<Message>anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    replay(stsClient);
    i.setStsClient(stsClient);
    assertSame(stsClient, i.getStsClient());
    message.get(Message.REQUESTOR_ROLE);
    expectLastCall().andReturn(true).anyTimes();
    message.getContextualProperty(SecurityConstants.STS_TOKEN_ACT_AS);
    expectLastCall().andReturn(new Object()).anyTimes();
    message.getContextualProperty(SecurityConstants.STS_APPLIES_TO);
    expectLastCall().andReturn(new Object()).anyTimes();
    message.getContextualProperty(SecurityConstants.STS_TOKEN_ON_BEHALF_OF);
    expectLastCall().andReturn(new Object()).anyTimes();
    replay(message);
    i.handleMessage(message);
    verify(message);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) Message(org.apache.cxf.message.Message) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) Test(org.junit.Test)

Example 5 with STSRESTOutInterceptor

use of org.talend.esb.security.saml.STSRESTOutInterceptor in project tesb-rt-se by Talend.

the class AuxiliaryStorageRestClientSecurityProvider method getClientFactory.

protected JAXRSClientFactoryBean getClientFactory() {
    if (null == cachedClientFactory) {
        JAXRSClientFactoryBean factoryBean = new JAXRSClientFactoryBean();
        factoryBean.setThreadSafe(true);
        factoryBean.setAddress(getServerURL());
        if (Authentication.BASIC == auxiliaryStorageAuthentication) {
            factoryBean.setUsername(authenticationUser);
            factoryBean.setPassword(authenticationPassword);
        }
        if (Authentication.SAML == auxiliaryStorageAuthentication) {
            STSClient stsClient = STSClientCreator.create(factoryBean.getBus(), stsProps);
            STSRESTOutInterceptor outInterceptor = new STSRESTOutInterceptor();
            outInterceptor.setStsClient(stsClient);
            factoryBean.getOutInterceptors().add(outInterceptor);
            factoryBean.getOutInterceptors().add(new SamlHeaderOutInterceptor());
        }
        cachedClientFactory = factoryBean;
    }
    return cachedClientFactory;
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) SamlHeaderOutInterceptor(org.apache.cxf.rs.security.saml.SamlHeaderOutInterceptor)

Aggregations

STSRESTOutInterceptor (org.talend.esb.security.saml.STSRESTOutInterceptor)5 Message (org.apache.cxf.message.Message)4 STSClient (org.apache.cxf.ws.security.trust.STSClient)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 AbstractJAXRSFactoryBean (org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 SamlHeaderOutInterceptor (org.apache.cxf.rs.security.saml.SamlHeaderOutInterceptor)1