Search in sources :

Example 6 with Metadata

use of org.cloudfoundry.client.v2.Metadata in project midpoint by Evolveum.

the class MidpointAssertingPartyMetadataConverter method convert.

public RelyingPartyRegistration.Builder convert(InputStream inputStream, Saml2ProviderAuthenticationModuleType providerConfig) {
    EntityDescriptor descriptor = entityDescriptor(inputStream);
    IDPSSODescriptor idpssoDescriptor = descriptor.getIDPSSODescriptor(SAMLConstants.SAML20P_NS);
    if (idpssoDescriptor == null) {
        throw new Saml2Exception("Metadata response is missing the necessary IDPSSODescriptor element");
    }
    List<Saml2X509Credential> verification = new ArrayList<>();
    List<Saml2X509Credential> encryption = new ArrayList<>();
    for (KeyDescriptor keyDescriptor : idpssoDescriptor.getKeyDescriptors()) {
        defineKeys(keyDescriptor, verification, encryption);
    }
    if (verification.isEmpty()) {
        throw new Saml2Exception("Metadata response is missing verification certificates, necessary for verifying SAML assertions");
    }
    RelyingPartyRegistration.Builder builder = RelyingPartyRegistration.withRegistrationId(descriptor.getEntityID()).assertingPartyDetails((party) -> party.entityId(descriptor.getEntityID()).wantAuthnRequestsSigned(Boolean.TRUE.equals(idpssoDescriptor.getWantAuthnRequestsSigned())).verificationX509Credentials((c) -> c.addAll(verification)).encryptionX509Credentials((c) -> c.addAll(encryption)));
    List<SigningMethod> signingMethods = signingMethods(idpssoDescriptor);
    for (SigningMethod method : signingMethods) {
        builder.assertingPartyDetails((party) -> party.signingAlgorithms((algorithms) -> algorithms.add(method.getAlgorithm())));
    }
    defineSingleSingOnService(idpssoDescriptor, providerConfig.getAuthenticationRequestBinding(), builder);
    defineSingleLogoutService(idpssoDescriptor, builder);
    return builder;
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) X509Certificate(java.security.cert.X509Certificate) UsageType(org.opensaml.security.credential.UsageType) OpenSamlInitializationService(org.springframework.security.saml2.core.OpenSamlInitializationService) Unmarshaller(org.opensaml.core.xml.io.Unmarshaller) Saml2Exception(org.springframework.security.saml2.Saml2Exception) ConfigurationService(org.opensaml.core.config.ConfigurationService) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) CertificateException(java.security.cert.CertificateException) StringUtils(org.apache.commons.lang3.StringUtils) XMLObjectProviderRegistry(org.opensaml.core.xml.config.XMLObjectProviderRegistry) KeyInfoSupport(org.opensaml.xmlsec.keyinfo.KeyInfoSupport) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) ArrayList(java.util.ArrayList) Saml2MessageBinding(org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding) ParserPool(net.shibboleth.utilities.java.support.xml.ParserPool) List(java.util.List) org.opensaml.saml.saml2.metadata(org.opensaml.saml.saml2.metadata) SigningMethod(org.opensaml.saml.ext.saml2alg.SigningMethod) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XMLObject(org.opensaml.core.xml.XMLObject) SAMLConstants(org.opensaml.saml.common.xml.SAMLConstants) Saml2ProviderAuthenticationModuleType(com.evolveum.midpoint.xml.ns._public.common.common_3.Saml2ProviderAuthenticationModuleType) InputStream(java.io.InputStream) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) ArrayList(java.util.ArrayList) Saml2Exception(org.springframework.security.saml2.Saml2Exception) SigningMethod(org.opensaml.saml.ext.saml2alg.SigningMethod)

Example 7 with Metadata

use of org.cloudfoundry.client.v2.Metadata in project cxf by apache.

the class MEXTest method testGet.

@Test
public void testGet() {
    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress("local://Echo-mex");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    MetadataExchange exc = proxyFac.create(MetadataExchange.class);
    Metadata metadata = exc.get2004();
    assertNotNull(metadata);
    proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    exc = proxyFac.create(MetadataExchange.class);
    metadata = exc.get2004();
    assertNotNull(metadata);
}
Also used : JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) Test(org.junit.Test)

Example 8 with Metadata

use of org.cloudfoundry.client.v2.Metadata in project cxf by apache.

the class IssueUnitTest method testRetrieveWSMEX.

@org.junit.Test
public void testRetrieveWSMEX() throws Exception {
    createBus(getClass().getResource("cxf-client.xml").toString());
    // Get Metadata
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setBindingId(SoapBindingConstants.SOAP11_BINDING_ID);
    proxyFac.setAddress("https://localhost:" + STSPORT + "/SecurityTokenService/Transport/mex");
    MetadataExchange exc = proxyFac.create(MetadataExchange.class);
    Metadata metadata = exc.get2004();
    // Parse response (as per the STSClient)
    Definition definition = null;
    // Parse the MetadataSections into WSDL definition + associated schemas
    for (MetadataSection s : metadata.getMetadataSection()) {
        if ("http://schemas.xmlsoap.org/wsdl/".equals(s.getDialect())) {
            definition = bus.getExtension(WSDLManager.class).getDefinition((Element) s.getAny());
        }
    }
    assertNotNull(definition);
}
Also used : MetadataSection(org.apache.cxf.ws.mex.model._2004_09.MetadataSection) Element(org.w3c.dom.Element) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) Definition(javax.wsdl.Definition) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange)

Example 9 with Metadata

use of org.cloudfoundry.client.v2.Metadata in project cxf by apache.

the class AbstractSTSClient method configureViaEPR.

public void configureViaEPR(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
    if (client != null) {
        return;
    }
    location = EndpointReferenceUtils.getAddress(ref);
    if (location != null) {
        location = location.trim();
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("EPR address: " + location);
    }
    final QName sName = EndpointReferenceUtils.getServiceName(ref, bus);
    if (sName != null) {
        serviceName = sName;
        final QName epName = EndpointReferenceUtils.getPortQName(ref, bus);
        if (epName != null) {
            endpointName = epName;
        }
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("EPR endpoint: " + serviceName + " " + endpointName);
        }
    }
    final String wsdlLoc = EndpointReferenceUtils.getWSDLLocation(ref);
    if (wsdlLoc != null) {
        wsdlLocation = wsdlLoc;
    }
    String mexLoc = findMEXLocation(ref, useEPRWSAAddrAsMEXLocation);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("WS-MEX location: " + mexLoc);
    }
    if (mexLoc != null) {
        try {
            JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
            proxyFac.setBindingId(soapVersion);
            proxyFac.setAddress(mexLoc);
            MetadataExchange exc = proxyFac.create(MetadataExchange.class);
            Metadata metadata = exc.get2004();
            Definition definition = null;
            List<Schema> schemas = new ArrayList<>();
            // Parse the MetadataSections into WSDL definition + associated schemas
            for (MetadataSection s : metadata.getMetadataSection()) {
                if ("http://schemas.xmlsoap.org/wsdl/".equals(s.getDialect())) {
                    definition = bus.getExtension(WSDLManager.class).getDefinition((Element) s.getAny());
                } else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
                    Element schemaElement = (Element) s.getAny();
                    if (schemaElement == null) {
                        String schemaLocation = s.getLocation();
                        LOG.info("XSD schema location: " + schemaLocation);
                        schemaElement = downloadSchema(schemaLocation);
                    }
                    QName schemaName = new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
                    WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
                    ExtensibilityElement exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
                    ((Schema) exElement).setElement(schemaElement);
                    schemas.add((Schema) exElement);
                }
            }
            if (definition != null) {
                // Add any extra schemas to the WSDL definition
                for (Schema schema : schemas) {
                    definition.getTypes().addExtensibilityElement(schema);
                }
                WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
                SourceDataBinding dataBinding = new SourceDataBinding();
                factory.setDataBinding(dataBinding);
                Service service = factory.create();
                service.setDataBinding(dataBinding);
                // Get the endpoint + service names by matching the 'location' to the
                // address in the WSDL. If the 'location' is 'anonymous' then just fall
                // back to the first service + endpoint name in the WSDL, if the endpoint
                // name is not defined in the Metadata
                List<ServiceInfo> services = service.getServiceInfos();
                String anonymousAddress = "http://www.w3.org/2005/08/addressing/anonymous";
                if (!anonymousAddress.equals(location)) {
                    for (ServiceInfo serv : services) {
                        for (EndpointInfo ei : serv.getEndpoints()) {
                            if (ei.getAddress().equals(location)) {
                                endpointName = ei.getName();
                                serviceName = serv.getName();
                                LOG.fine("Matched endpoint to location");
                            }
                        }
                    }
                }
                EndpointInfo ei = service.getEndpointInfo(endpointName);
                if (ei == null && anonymousAddress.equals(location) && !services.isEmpty() && !services.get(0).getEndpoints().isEmpty()) {
                    LOG.fine("Anonymous location so taking first endpoint");
                    serviceName = services.get(0).getName();
                    endpointName = services.get(0).getEndpoints().iterator().next().getName();
                    ei = service.getEndpointInfo(endpointName);
                }
                if (ei == null) {
                    throw new TrustException(LOG, "ADDRESS_NOT_MATCHED", location);
                }
                if (location != null && !anonymousAddress.equals(location)) {
                    ei.setAddress(location);
                }
                Endpoint endpoint = new EndpointImpl(bus, service, ei);
                client = new ClientImpl(bus, endpoint);
            }
        } catch (Exception ex) {
            throw new TrustException("WS_MEX_ERROR", ex, LOG);
        }
    }
}
Also used : Types(javax.wsdl.Types) MetadataSection(org.apache.cxf.ws.mex.model._2004_09.MetadataSection) Schema(javax.wsdl.extensions.schema.Schema) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) ArrayList(java.util.ArrayList) ModCountCopyOnWriteArrayList(org.apache.cxf.common.util.ModCountCopyOnWriteArrayList) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Definition(javax.wsdl.Definition) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) Base64DecodingException(org.apache.xml.security.exceptions.Base64DecodingException) EndpointException(org.apache.cxf.endpoint.EndpointException) BusException(org.apache.cxf.BusException) WSDLManager(org.apache.cxf.wsdl.WSDLManager)

Example 10 with Metadata

use of org.cloudfoundry.client.v2.Metadata in project cxf by apache.

the class MEXTest method testGet.

@Test
public void testGet() {
    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setBus(getStaticBus());
    proxyFac.setAddress("http://localhost:" + PORT + "/jaxws/addmex");
    proxyFac.getFeatures().add(new LoggingFeature());
    MetadataExchange exc = proxyFac.create(MetadataExchange.class);
    Metadata metadata = exc.get2004();
    assertNotNull(metadata);
    assertEquals(2, metadata.getMetadataSection().size());
    assertEquals("http://schemas.xmlsoap.org/wsdl/", metadata.getMetadataSection().get(0).getDialect());
    assertEquals("http://apache.org/cxf/systest/ws/addr_feature/", metadata.getMetadataSection().get(0).getIdentifier());
    assertEquals("http://www.w3.org/2001/XMLSchema", metadata.getMetadataSection().get(1).getDialect());
    GetMetadata body = new GetMetadata();
    body.setDialect("http://www.w3.org/2001/XMLSchema");
    metadata = exc.getMetadata(body);
    assertEquals(1, metadata.getMetadataSection().size());
    assertEquals("http://www.w3.org/2001/XMLSchema", metadata.getMetadataSection().get(0).getDialect());
}
Also used : GetMetadata(org.apache.cxf.ws.mex.model._2004_09.GetMetadata) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) GetMetadata(org.apache.cxf.ws.mex.model._2004_09.GetMetadata) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange) Test(org.junit.Test)

Aggregations

JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)5 Metadata (org.apache.cxf.ws.mex.model._2004_09.Metadata)5 MetadataExchange (org.apache.cxf.ws.mex.MetadataExchange)4 Test (org.junit.Test)4 LinkedList (java.util.LinkedList)3 MetadataSection (org.apache.cxf.ws.mex.model._2004_09.MetadataSection)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Definition (javax.wsdl.Definition)2 Element (org.w3c.dom.Element)2 JmxAttributeGauge (com.codahale.metrics.JmxAttributeGauge)1 MetricRegistry.name (com.codahale.metrics.MetricRegistry.name)1 HealthCheck (com.codahale.metrics.health.HealthCheck)1 Saml2ProviderAuthenticationModuleType (com.evolveum.midpoint.xml.ns._public.common.common_3.Saml2ProviderAuthenticationModuleType)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ActiveMQBundle (com.kjetland.dropwizard.activemq.ActiveMQBundle)1 Application (io.dropwizard.Application)1 AssetsBundle (io.dropwizard.assets.AssetsBundle)1 HttpClientBuilder (io.dropwizard.client.HttpClientBuilder)1