Changeset 639 for raptor-client


Ignore:
Timestamp:
04/05/11 18:56:03 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/Endpoint.java

    r595 r639  
    3535    private AttributeFilterPolicy attributeFilterPolicy; 
    3636 
     37    /** They public key used to encrypt messages sent to this endpoint*/ 
     38    private String publicKey; 
     39 
     40    /** The password used to access the public key */ 
     41    private String publicKeyPassword; 
     42 
    3743    public void setServiceEndpoint(String serviceEndpoint) { 
    3844        this.serviceEndpoint = serviceEndpoint; 
     
    5965    } 
    6066 
     67    /** 
     68     * @param publicKey the publicKey to set 
     69     */ 
     70    public void setPublicKey(String publicKey) { 
     71        this.publicKey = publicKey; 
     72    } 
     73 
     74    /** 
     75     * @return the publicKey 
     76     */ 
     77    public String getPublicKey() { 
     78        return publicKey; 
     79    } 
     80 
     81    /** 
     82     * @param publicKeyPassword the publicKeyPassword to set 
     83     */ 
     84    public void setPublicKeyPassword(String publicKeyPassword) { 
     85        this.publicKeyPassword = publicKeyPassword; 
     86    } 
     87 
     88    /** 
     89     * @return the publicKeyPassword 
     90     */ 
     91    public String getPublicKeyPassword() { 
     92        return publicKeyPassword; 
     93    } 
     94 
    6195 
    6296 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EventReleaseEngine.java

    r622 r639  
    3636/** 
    3737 * @author philsmart 
    38  *  
     38 * 
    3939 */ 
    4040public class EventReleaseEngine { 
     
    5151         * meet the push policy defined on them. Event attributes are also filtered 
    5252         * according to the attribute filter policy defined per endpoint. 
    53          *  
     53         * 
    5454         * @param authenticationModules 
    5555         */ 
     
    6464                        if (shouldRelease) { 
    6565                                log.debug("Pushing {} entries to the Endpoint [{}]", filteredEntries.size(),endpoint.getServiceEndpoint()); 
    66                                 boolean releaseSuccess = getServiceEndpointInterface().sendEvents(pushMessage,endpoint.getServiceEndpoint()); 
     66                                boolean releaseSuccess = getServiceEndpointInterface().sendEvents(pushMessage,endpoint); 
    6767                                log.debug("Release to [{}] succeeded {}", endpoint.getServiceEndpoint(), releaseSuccess); 
    6868                                if (releaseSuccess == false) 
     
    8686         * endpoint. If no filter policy has been defined, no work is done, and the 
    8787         * input allEvents is returned without modification 
    88          *  
     88         * 
    8989         * @param endpoint 
    9090         * @param allEvents 
     
    9999        /** 
    100100         * Constructs an event push message, which encapsulates the events to send 
    101          *  
     101         * 
    102102         * @param clientMetadata 
    103103         * @param events 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/ServiceEndpointClient.java

    r627 r639  
    1717 
    1818import uk.ac.cardiff.model.wsmodel.EventPushMessage; 
     19import uk.ac.cardiff.raptor.registry.Endpoint; 
    1920 
    2021public interface ServiceEndpointClient { 
    21          
    22         public boolean sendEvents(EventPushMessage pushed, String endpoint); 
     22 
     23        public boolean sendEvents(EventPushMessage pushed, Endpoint endpoint); 
    2324 
    2425} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/CxfServiceEndpointClient.java

    r627 r639  
    1616package uk.ac.cardiff.raptor.remoting.client.sei.impl; 
    1717 
     18import java.io.File; 
     19import java.io.FileInputStream; 
     20import java.security.KeyStore; 
    1821import java.util.HashSet; 
    1922import java.util.LinkedHashSet; 
    2023import java.util.Set; 
     24 
     25import javax.net.ssl.TrustManager; 
     26import javax.net.ssl.TrustManagerFactory; 
    2127 
    2228import org.apache.cxf.aegis.DatabindingException; 
     
    2531import org.apache.cxf.binding.soap.SoapFault; 
    2632import org.apache.cxf.common.classloader.ClassLoaderUtils; 
     33import org.apache.cxf.configuration.jsse.TLSClientParameters; 
     34import org.apache.cxf.frontend.ClientProxy; 
    2735import org.apache.cxf.frontend.ClientProxyFactoryBean; 
     36import org.apache.cxf.transport.http.HTTPConduit; 
     37import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; 
    2838import org.slf4j.Logger; 
    2939import org.slf4j.LoggerFactory; 
     
    3242import uk.ac.cardiff.model.event.ShibbolethIdpAuthenticationEvent; 
    3343import uk.ac.cardiff.model.wsmodel.EventPushMessage; 
     44import uk.ac.cardiff.raptor.registry.Endpoint; 
    3445import uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointClient; 
    3546import uk.ac.cardiff.raptor.remoting.server.sei.MultiUnitAggregator; 
    3647 
    37  
    3848public class CxfServiceEndpointClient implements ServiceEndpointClient { 
    3949 
    40         /** Class logger */ 
    41         private final Logger log = LoggerFactory.getLogger(CxfServiceEndpointClient.class); 
     50    /** Class logger */ 
     51    private final Logger log = LoggerFactory.getLogger(CxfServiceEndpointClient.class); 
    4252 
    43         @Override 
    44         public boolean sendEvents(EventPushMessage pushed, String endpointURL) { 
     53    @Override 
     54    public boolean sendEvents(EventPushMessage pushed, Endpoint endpoint) { 
     55        try { 
     56            ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); 
     57            factory.setServiceClass(MultiUnitAggregator.class); 
     58            AegisDatabinding databinding = new AegisDatabinding(); 
     59 
     60            org.apache.cxf.aegis.AegisContext context = new org.apache.cxf.aegis.AegisContext(); 
     61            context.setWriteXsiTypes(true); 
     62 
     63            Set<Class<?>> rootClasses = new HashSet<Class<?>>(); 
     64 
     65            Set<String> overrides = new HashSet<String>(); 
     66            overrides.add(ShibbolethIdpAuthenticationEvent.class.getName()); 
     67            overrides.add(AuthenticationEvent.class.getName()); 
     68            databinding.setOverrideTypes(overrides); 
     69 
     70            for (String typeName : overrides) { 
     71                Class c = null; 
    4572                try { 
    46                         ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); 
    47                         factory.setServiceClass(MultiUnitAggregator.class); 
    48                         AegisDatabinding databinding = new AegisDatabinding(); 
     73                    c = ClassLoaderUtils.loadClass(typeName, TypeUtil.class); 
     74                } catch (ClassNotFoundException e) { 
     75                    throw new DatabindingException("Could not find override type class: " + typeName, e); 
     76                } 
     77                rootClasses.add(c); 
     78            } 
    4979 
    50                         org.apache.cxf.aegis.AegisContext context = new org.apache.cxf.aegis.AegisContext(); 
    51                         context.setWriteXsiTypes(true); 
     80            context.setRootClasses(rootClasses); 
     81            databinding.setAegisContext(context); 
    5282 
    53                         Set<Class<?>> rootClasses = new HashSet<Class<?>>(); 
     83            factory.setAddress(endpoint.getServiceEndpoint()); 
     84            factory.getServiceFactory().setDataBinding(databinding); 
    5485 
    55                         Set<String> overrides = new HashSet<String>(); 
    56                         overrides.add(ShibbolethIdpAuthenticationEvent.class.getName()); 
    57                         overrides.add(AuthenticationEvent.class.getName()); 
    58                         databinding.setOverrideTypes(overrides); 
     86            MultiUnitAggregator client = (MultiUnitAggregator) factory.create(); 
     87            org.apache.cxf.endpoint.Client cl = ClientProxy.getClient(client); 
     88            HTTPConduit httpConduit = (HTTPConduit) cl.getConduit(); 
     89            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
     90            httpConduit.setClient(httpClientPolicy); 
     91            TLSClientParameters tls = new TLSClientParameters(); 
     92            tls.setDisableCNCheck(true);//disable URL and CN on cert match 
     93            KeyStore keyStore = KeyStore.getInstance("JKS"); 
     94            File truststore = new File(endpoint.getPublicKey()); 
     95            keyStore.load(new FileInputStream(truststore),  endpoint.getPublicKeyPassword().toCharArray()); 
     96            TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
     97            trustFactory.init(keyStore); 
     98            TrustManager[] tm = trustFactory.getTrustManagers(); 
     99            tls.setTrustManagers(tm); 
     100            httpConduit.setTlsClientParameters(tls); 
    59101 
    60                         for (String typeName : overrides) { 
    61                                 Class c = null; 
    62                                 try { 
    63                                         c = ClassLoaderUtils.loadClass(typeName, TypeUtil.class); 
    64                                 } catch (ClassNotFoundException e) { 
    65                                         throw new DatabindingException("Could not find override type class: " + typeName, e); 
    66                                 } 
     102            log.debug("Accessing the endpoint version " + client.getVersion()); 
     103            client.addAuthentications(pushed); 
     104            log.debug("Sent {} events", pushed.getEvents().size()); 
    67105 
    68                                 rootClasses.add(c); 
    69                         } 
     106            return true; 
     107        } catch (SoapFault e) { 
     108            log.error("Could not send events to endpoint [{}] -> {}", new Object[] { endpoint.getServiceEndpoint(), e.getMessage() }); 
     109            e.printStackTrace(); 
     110            return false; 
     111        } catch (Exception e) { 
     112            log.error("Could not send events to endpoint [{}] -> {}", new Object[] { endpoint.getServiceEndpoint(), e.getMessage() }); 
     113            e.printStackTrace(); 
     114            return false; 
     115        } 
    70116 
    71                         context.setRootClasses(rootClasses); 
    72                         databinding.setAegisContext(context); 
    73  
    74                         factory.setAddress(endpointURL); 
    75                         factory.getServiceFactory().setDataBinding(databinding); 
    76  
    77                         MultiUnitAggregator client = (MultiUnitAggregator) factory.create(); 
    78                         log.debug("Accessing the endpoint version " + client.getVersion()); 
    79                         Set<ShibbolethIdpAuthenticationEvent> newEntries = new LinkedHashSet<ShibbolethIdpAuthenticationEvent>(); 
    80                         client.addAuthentications(pushed); 
    81                         log.debug("Sent {} events", pushed.getEvents().size()); 
    82                         return true; 
    83                 } catch (SoapFault e) { 
    84                     log.error("Could not send events to endpoint [{}] -> {}", new Object[]{endpointURL, e.getMessage()}); 
    85                     return false; 
    86                 }catch (Exception e) { 
    87                     log.error("Could not send events to endpoint [{}] -> {}", new Object[]{endpointURL, e.getMessage()}); 
    88                     return false; 
    89                 } 
    90  
    91         } 
     117    } 
    92118} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/DefaultServiceEndpointClient.java

    r627 r639  
    1717 
    1818import uk.ac.cardiff.model.wsmodel.EventPushMessage; 
     19import uk.ac.cardiff.raptor.registry.Endpoint; 
    1920import uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointClient; 
    2021 
    2122public class DefaultServiceEndpointClient implements ServiceEndpointClient { 
    2223 
     24        /* (non-Javadoc) 
     25         * @see uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointClient#sendEvents(uk.ac.cardiff.model.wsmodel.EventPushMessage, uk.ac.cardiff.raptor.registry.Endpoint) 
     26         */ 
    2327        @Override 
    24         public boolean sendEvents(EventPushMessage pushed, String endpoint) { 
    25                 // TODO Auto-generated method stub 
    26                 return false; 
     28        public boolean sendEvents(EventPushMessage pushed, Endpoint endpoint) { 
     29            // TODO Auto-generated method stub 
     30            return false; 
    2731        } 
    2832 
Note: See TracChangeset for help on using the changeset viewer.