Search in sources :

Example 61 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class KeyManagementUtils method loadPublicKey.

public static PublicKey loadPublicKey(Message m, String keyStoreLocPropPreferred, String keyStoreLocPropDefault) {
    String keyStoreLoc = getMessageProperty(m, keyStoreLocPropPreferred, keyStoreLocPropDefault);
    Bus bus = m.getExchange().getBus();
    try {
        Properties props = JoseUtils.loadProperties(keyStoreLoc, bus);
        return KeyManagementUtils.loadPublicKey(m, props);
    } catch (Exception ex) {
        LOG.warning("Public key can not be loaded");
        throw new JoseException(ex);
    }
}
Also used : Bus(org.apache.cxf.Bus) Properties(java.util.Properties) KeyStoreException(java.security.KeyStoreException) JwkException(org.apache.cxf.rs.security.jose.jwk.JwkException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Base64Exception(org.apache.cxf.common.util.Base64Exception) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 62 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class KeyManagementUtils method loadPersistKeyStore.

public static KeyStore loadPersistKeyStore(Message m, Properties props) {
    KeyStore keyStore = null;
    if (props.containsKey(JoseConstants.RSSEC_KEY_STORE)) {
        keyStore = (KeyStore) props.get(JoseConstants.RSSEC_KEY_STORE);
    }
    if (keyStore == null) {
        if (!props.containsKey(JoseConstants.RSSEC_KEY_STORE_FILE)) {
            LOG.warning("No keystore file has been configured");
            throw new JoseException("No keystore file has been configured");
        }
        if (m != null) {
            Object keyStoreProp = m.getExchange().get(props.get(JoseConstants.RSSEC_KEY_STORE_FILE));
            if (keyStoreProp != null && !(keyStoreProp instanceof KeyStore)) {
                throw new JwkException("Unexpected key store class: " + keyStoreProp.getClass().getName());
            } else {
                keyStore = (KeyStore) keyStoreProp;
            }
        }
    }
    if (keyStore == null) {
        Bus bus = m != null ? m.getExchange().getBus() : null;
        keyStore = loadKeyStore(props, bus);
        if (m != null) {
            m.getExchange().put((String) props.get(JoseConstants.RSSEC_KEY_STORE_FILE), keyStore);
        }
    }
    return keyStore;
}
Also used : Bus(org.apache.cxf.Bus) JwkException(org.apache.cxf.rs.security.jose.jwk.JwkException) KeyStore(java.security.KeyStore)

Example 63 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class EhCacheIdentityCacheTest method testTwoDistinctAndTwoRelatedMapping.

@org.junit.Test
public void testTwoDistinctAndTwoRelatedMapping() {
    IdentityMapper mapper = new CacheIdentityMapper();
    Bus bus = BusFactory.getDefaultBus();
    EHCacheIdentityCache cache = new EHCacheIdentityCache(mapper, bus);
    cache.mapPrincipal("REALM_A", new CustomTokenPrincipal("user_aaa"), "REALM_B");
    cache.mapPrincipal("REALM_D", new CustomTokenPrincipal("user_ddd"), "REALM_E");
    assertEquals(4, cache.size());
    // No Mapping occured between A,B and D,E (C not involved at all)
    assertEquals(2, cache.get("user_aaa", "REALM_A").size());
    assertEquals(2, cache.get("user_bbb", "REALM_B").size());
    assertEquals(2, cache.get("user_ddd", "REALM_D").size());
    assertEquals(2, cache.get("user_eee", "REALM_E").size());
    cache.mapPrincipal("REALM_B", new CustomTokenPrincipal("user_bbb"), "REALM_C");
    assertEquals(5, cache.size());
    assertNotNull(cache.get("user_aaa", "REALM_A"));
    assertNotNull(cache.get("user_bbb", "REALM_B"));
    assertNotNull(cache.get("user_ccc", "REALM_C"));
    assertNotNull(cache.get("user_ddd", "REALM_D"));
    assertNotNull(cache.get("user_eee", "REALM_E"));
    assertEquals(3, cache.get("user_aaa", "REALM_A").size());
    assertEquals(3, cache.get("user_bbb", "REALM_B").size());
    assertEquals(3, cache.get("user_ccc", "REALM_C").size());
    // No mapping occurred between A,B,C and D,E -> distinct
    assertEquals(2, cache.get("user_ddd", "REALM_D").size());
    assertEquals(2, cache.get("user_eee", "REALM_E").size());
    cache.mapPrincipal("REALM_C", new CustomTokenPrincipal("user_ccc"), "REALM_E");
    // All mappings are known now
    assertEquals(5, cache.size());
    assertNotNull(cache.get("user_aaa", "REALM_A"));
    assertNotNull(cache.get("user_bbb", "REALM_B"));
    assertNotNull(cache.get("user_ccc", "REALM_C"));
    assertNotNull(cache.get("user_ddd", "REALM_D"));
    assertNotNull(cache.get("user_eee", "REALM_E"));
    assertEquals(5, cache.get("user_aaa", "REALM_A").size());
    assertEquals(5, cache.get("user_bbb", "REALM_B").size());
    assertEquals(5, cache.get("user_ccc", "REALM_C").size());
    assertEquals(5, cache.get("user_ddd", "REALM_D").size());
    assertEquals(5, cache.get("user_eee", "REALM_E").size());
    cache.close();
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) Bus(org.apache.cxf.Bus) IdentityMapper(org.apache.cxf.sts.IdentityMapper)

Example 64 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class EhCacheIdentityCacheTest method testOneMapping.

// tests TokenStore apis for storing in the cache.
@org.junit.Test
public void testOneMapping() throws Exception {
    IdentityMapper mapper = new CacheIdentityMapper();
    Bus bus = BusFactory.getDefaultBus();
    EHCacheIdentityCache cache = new EHCacheIdentityCache(mapper, bus);
    cache.mapPrincipal("REALM_A", new CustomTokenPrincipal("user_aaa"), "REALM_B");
    assertEquals(2, cache.size());
    assertNotNull(cache.get("user_aaa", "REALM_A"));
    assertNotNull(cache.get("user_bbb", "REALM_B"));
    cache.close();
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) Bus(org.apache.cxf.Bus) IdentityMapper(org.apache.cxf.sts.IdentityMapper)

Example 65 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class ReflectionServiceFactorBeanTest method testEmptyWsdlAndNoServiceClass.

@Test
public void testEmptyWsdlAndNoServiceClass() throws Exception {
    final String dummyWsdl = "target/dummy.wsdl";
    ReflectionServiceFactoryBean bean = new ReflectionServiceFactoryBean();
    Bus bus = control.createMock(Bus.class);
    WSDLManager wsdlmanager = control.createMock(WSDLManager.class);
    EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(wsdlmanager);
    EasyMock.expect(wsdlmanager.getDefinition(dummyWsdl)).andThrow(new WSDLException("PARSER_ERROR", "Problem parsing '" + dummyWsdl + "'."));
    EasyMock.expect(bus.getExtension(FactoryBeanListenerManager.class)).andReturn(null);
    control.replay();
    bean.setWsdlURL(dummyWsdl);
    bean.setServiceName(new QName("http://cxf.apache.org/hello_world_soap_http", "GreeterService"));
    bean.setBus(bus);
    try {
        bean.create();
        fail("no valid wsdl nor service class specified");
    } catch (ServiceConstructionException e) {
    // ignore
    }
}
Also used : Bus(org.apache.cxf.Bus) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) WSDLManager(org.apache.cxf.wsdl.WSDLManager) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Test(org.junit.Test)

Aggregations

Bus (org.apache.cxf.Bus)1144 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)800 URL (java.net.URL)748 QName (javax.xml.namespace.QName)436 Service (javax.xml.ws.Service)400 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)354 Test (org.junit.Test)219 HashMap (java.util.HashMap)63 Message (org.apache.cxf.message.Message)60 WebClient (org.apache.cxf.jaxrs.client.WebClient)50 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)48 Client (org.apache.cxf.endpoint.Client)43 Greeter (org.apache.hello_world.Greeter)42 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)41 SOAPService (org.apache.hello_world.services.SOAPService)41 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)40 Endpoint (org.apache.cxf.endpoint.Endpoint)38 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)36 STSClient (org.apache.cxf.ws.security.trust.STSClient)36 Document (org.w3c.dom.Document)36