Changeset 1025 for raptor-client


Ignore:
Timestamp:
06/23/11 23:29:28 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
9 edited
1 moved

Legend:

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

    r595 r1025  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptor.attribute; 
    2021 
     
    2223 
    2324/** 
    24  * This is a poor implementation of an attributeRule as taken from the ShibbolethIDP 
    25  * 
    26  * @author philsmart 
    27  * 
     25 * This is a poor implementation of an attributeRule as taken from the ShibbolethIDP. 
    2826 */ 
    2927public class AttributeRule { 
    3028 
    31     /* needs to be the exact field name of the attribute */ 
    32     //TODO change all these to proper regulated values with OIDs. 
     29    /** 
     30     * The name of the field in the {@link uk.ac.cardiff.model.event.Event} or a subclass thereof that this rule applies 
     31     * to e.g principalName. 
     32     */ 
    3333    private String attributeID; 
     34 
     35    /** A permit value rule. */ 
    3436    private MatchRule permitValueRule; 
     37 
     38    /** A deny value rule. */ 
    3539    private MatchRule denyValueRule; 
    3640 
    37  
    38     public void setAttributeID(String attributeID) { 
    39         this.attributeID = attributeID; 
    40     } 
    41     public String getAttributeID() { 
    42         return attributeID; 
    43     } 
    44     public void setPermitValueRule(MatchRule permitValueRule) { 
    45         this.permitValueRule = permitValueRule; 
    46     } 
    47     public MatchRule getPermitValueRule() { 
    48         return permitValueRule; 
    49     } 
    50     public void setDenyValueRule(MatchRule denyValueRule) { 
    51         this.denyValueRule = denyValueRule; 
    52     } 
    53     public MatchRule getDenyValueRule() { 
    54         return denyValueRule; 
     41    /** 
     42     * Sets the attribute id. 
     43     *  
     44     * @param attributeID the new attribute id 
     45     */ 
     46    public void setAttributeID(final String attributeID) { 
     47        this.attributeID = attributeID; 
    5548    } 
    5649 
     50    /** 
     51     * Gets the attribute id. 
     52     *  
     53     * @return the attribute id 
     54     */ 
     55    public String getAttributeID() { 
     56        return attributeID; 
     57    } 
     58 
     59    /** 
     60     * Sets the permit value rule. 
     61     *  
     62     * @param permitValueRule the new permit value rule 
     63     */ 
     64    public void setPermitValueRule(final MatchRule permitValueRule) { 
     65        this.permitValueRule = permitValueRule; 
     66    } 
     67 
     68    /** 
     69     * Gets the permit value rule. 
     70     *  
     71     * @return the permit value rule 
     72     */ 
     73    public MatchRule getPermitValueRule() { 
     74        return permitValueRule; 
     75    } 
     76 
     77    /** 
     78     * Sets the deny value rule. 
     79     *  
     80     * @param denyValueRule the new deny value rule 
     81     */ 
     82    public void setDenyValueRule(final MatchRule denyValueRule) { 
     83        this.denyValueRule = denyValueRule; 
     84    } 
     85 
     86    /** 
     87     * Gets the deny value rule. 
     88     *  
     89     * @return the deny value rule 
     90     */ 
     91    public MatchRule getDenyValueRule() { 
     92        return denyValueRule; 
     93    } 
    5794 
    5895} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttributeFilterException.java

    r817 r1025  
    1414 * limitations under the License. 
    1515 */ 
    16 /** 
    17  * 
    18  */ 
     16 
    1917package uk.ac.cardiff.raptor.attribute.filtering; 
    2018 
    2119/** 
    2220 * @author philsmart 
    23  * 
     21 *  
    2422 */ 
    2523public class AttributeFilterException extends Exception { 
    26  
    2724 
    2825    /** Generated SeruialUID */ 
     
    3633    /** 
    3734     * Constructor. 
    38      * 
     35     *  
    3936     * @param message exception message 
    4037     */ 
     
    4542    /** 
    4643     * Constructor. 
    47      * 
     44     *  
    4845     * @param wrappedException exception to be wrapped by this one 
    4946     */ 
     
    5451    /** 
    5552     * Constructor. 
    56      * 
     53     *  
    5754     * @param message exception message 
    5855     * @param wrappedException exception to be wrapped by this one 
     
    6259    } 
    6360 
    64  
    6561} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttributeFilterPolicy.java

    r1024 r1025  
    2020 
    2121/** 
    22  * @author philsmart 
    23  *  
     22 * The Class AttributeFilterPolicy. 
    2423 */ 
    2524public class AttributeFilterPolicy { 
    2625 
     26    /** The policy name. */ 
    2727    private String policyName; 
    2828 
    29     private List<AttributeRule> attributeRules; 
     29    /** A <code>List</code> of attribute rules. */ 
     30    private List<BaseAttributeRule> attributeRules; 
    3031 
    31     public void setAttributeRules(List<AttributeRule> attributeRules) { 
     32    /** 
     33     * Sets the attribute rules. 
     34     *  
     35     * @param attributeRules the new attribute rules 
     36     */ 
     37    public void setAttributeRules(final List<BaseAttributeRule> attributeRules) { 
    3238        this.attributeRules = attributeRules; 
    3339    } 
    3440 
    35     public List<AttributeRule> getAttributeRules() { 
     41    /** 
     42     * Gets the attribute rules. 
     43     *  
     44     * @return the attribute rules 
     45     */ 
     46    public List<BaseAttributeRule> getAttributeRules() { 
    3647        return attributeRules; 
    3748    } 
    3849 
    39     public void setPolicyName(String policyName) { 
     50    /** 
     51     * Sets the policy name. 
     52     *  
     53     * @param policyName the new policy name 
     54     */ 
     55    public void setPolicyName(final String policyName) { 
    4056        this.policyName = policyName; 
    4157    } 
    4258 
     59    /** 
     60     * Gets the policy name. 
     61     *  
     62     * @return the policy name 
     63     */ 
    4364    public String getPolicyName() { 
    4465        return policyName; 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttrributeFilterEngine.java

    r817 r1025  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptor.attribute.filtering; 
    2021 
     
    2526import org.slf4j.LoggerFactory; 
    2627 
    27  
    2828import uk.ac.cardiff.model.ServiceMetadata; 
    2929import uk.ac.cardiff.model.event.Event; 
    3030 
    3131/** 
    32  * @author philsmart 
    3332 * 
    3433 */ 
    3534public class AttrributeFilterEngine { 
    3635 
    37         /** class logger. */ 
    38         private final Logger log = LoggerFactory.getLogger(AttrributeFilterEngine.class); 
     36    /** class logger. */ 
     37    private final Logger log = LoggerFactory.getLogger(AttrributeFilterEngine.class); 
    3938 
    40         /** 
    41          * Only runs against the deny rules, and only denies basic:ANY attributes, 
    42          * does not deny individual values. 
    43          * 
    44          * @param attributeFilterPolicy 
    45          * @param entries 
    46          * @return 
    47          */ 
    48         public List<Event> filter(AttributeFilterPolicy attributeFilterPolicy, ServiceMetadata metadata, List<Event> events) { 
    49                 log.debug("Applying attribute filter policy {} to event set", attributeFilterPolicy.getPolicyName()); 
    50                 List<Event> filteredEntries = clone(events); 
    51                 for (Event event : filteredEntries) { 
    52                         for (AttributeRule attributeRule : attributeFilterPolicy.getAttributeRules()) { 
    53                                 filterAttributes(event, attributeRule, metadata); 
     39    /** 
     40     * Only runs against the deny rules, and only denies basic:ANY attributes, does not deny individual values. 
     41     *  
     42     * @param attributeFilterPolicy 
     43     * @param entries 
     44     * @return 
     45     */ 
     46    public List<Event> filter(final AttributeFilterPolicy attributeFilterPolicy, final ServiceMetadata metadata, 
     47            final List<Event> events) { 
     48        log.debug("Applying attribute filter policy {} to event set", attributeFilterPolicy.getPolicyName()); 
     49        final List<Event> filteredEntries = clone(events); 
     50        for (final Event event : filteredEntries) { 
     51            for (final BaseAttributeRule attributeRule : attributeFilterPolicy.getAttributeRules()) { 
     52                filterAttributes(event, attributeRule, metadata); 
    5453 
    55                         } 
    56                 } 
    57                 return filteredEntries; 
    58         } 
     54            } 
     55        } 
     56        return filteredEntries; 
     57    } 
    5958 
    60         /** 
    61          * Only process deny rules on the level of basic:ANY attributes. Hence will 
    62          * not deny individual values 
    63          * 
    64          * @param entry 
    65          * @param attributeRule 
    66          * @param metadata 
    67          */ 
    68         private void filterAttributes(Event event, AttributeRule attributeRule, ServiceMetadata metadata) { 
    69             try{ 
    70                 if (attributeRule.shouldApply(event.getClass())){ 
    71                     attributeRule.filterAttribute(event, metadata); 
    72                 } 
    73             } 
    74             catch(AttributeFilterException e){ 
    75                 log.error("Could not filter attribute",e); 
    76             } 
    77         } 
     59    /** 
     60     * Only process deny rules on the level of basic:ANY attributes. Hence will not deny individual values 
     61     *  
     62     * @param entry 
     63     * @param attributeRule 
     64     * @param metadata 
     65     */ 
     66    private void filterAttributes(final Event event, final BaseAttributeRule attributeRule, final ServiceMetadata metadata) { 
     67        try { 
     68            if (attributeRule.shouldApply(event.getClass())) { 
     69                attributeRule.filterAttribute(event, metadata); 
     70            } 
     71        } catch (final AttributeFilterException e) { 
     72            log.error("Could not filter attribute", e); 
     73        } 
     74    } 
    7875 
    79  
    80         private  List<Event> clone(List<Event> events) { 
    81                 List<Event> clonedSet = new ArrayList<Event>(); 
    82                 for (Event event : events) { 
    83                         clonedSet.add(event.copy()); 
    84                 } 
    85                 log.trace("The event set of {} events has been cloned into the event set of {} events",events.size(),clonedSet.size()); 
    86                 return clonedSet; 
    87         } 
    88  
     76    private List<Event> clone(final List<Event> events) { 
     77        final List<Event> clonedSet = new ArrayList<Event>(); 
     78        for (final Event event : events) { 
     79            clonedSet.add(event.copy()); 
     80        } 
     81        log.trace("The event set of {} events has been cloned into the event set of {} events", events.size(), 
     82                clonedSet.size()); 
     83        return clonedSet; 
     84    } 
    8985 
    9086} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/BaseAttributeRule.java

    r1024 r1025  
    1414 * limitations under the License. 
    1515 */ 
    16 /** 
    17  * 
    18  */ 
    1916 
    2017package uk.ac.cardiff.raptor.attribute.filtering; 
     
    3128 *  
    3229 */ 
    33 public abstract class AttributeRule { 
     30public abstract class BaseAttributeRule { 
    3431 
     32    /** The permit value rule. */ 
    3533    private MatchRule permitValueRule; 
    3634 
     35    /** The deny value rule. */ 
    3736    private MatchRule denyValueRule; 
    3837 
    39     /** The class type that this attribute rule is defined for */ 
     38    /** The class type that this attribute rule is defined for. */ 
    4039    private Class<?> eventType; 
    4140 
     41    /** 
     42     * Abstract method that Filters an attribute. This *must* be implemented by all concrete classes. 
     43     *  
     44     * @param event the event 
     45     * @param metadata the metadata 
     46     * @throws AttributeFilterException the attribute filter exception 
     47     */ 
    4248    public abstract void filterAttribute(Event event, ServiceMetadata metadata) throws AttributeFilterException; 
    4349 
    4450    /** 
     51     * Whether the attribute rule should be applied to the class <code>eventType</code>. 
     52     *  
     53     * @param eventType the event type 
    4554     * @return true if this attribute rule is enabled, and should be applied to the input class type. 
    4655     */ 
    47     public boolean shouldApply(Class<?> eventType) { 
    48         boolean enabled = getDenyValueRule().isEnabled(); 
    49         boolean classEquivelent = (this.eventType == eventType); 
     56    public final boolean shouldApply(final Class<?> eventType) { 
     57        final boolean enabled = getDenyValueRule().isEnabled(); 
     58        final boolean classEquivelent = (this.eventType == eventType); 
    5059        if (enabled && classEquivelent) { 
    5160            return true; 
     
    5564    } 
    5665 
    57     protected void nullAttribute(Event event, String attributeID) { 
    58         ReflectionHelper.nullAttribute(event, attributeID); 
    59     } 
    60  
    61     protected boolean classHasAttribute(Event event, String attributeID) { 
     66    /** 
     67     * Whether the <code>Event</code> has the attribute <code>attributeID</code> 
     68     *  
     69     * @param event the event 
     70     * @param attributeID the attribute id 
     71     * @return true, if successful 
     72     */ 
     73    protected final boolean classHasAttribute(final Event event, final String attributeID) { 
    6274        return ReflectionHelper.classHasAttribute(event, attributeID); 
    6375    } 
    6476 
    65     protected Object getValueForObject(Event event, String attributeID) { 
    66         Object result = ReflectionHelper.getValueFromObject(attributeID, event); 
     77    /** 
     78     * Gets the value of the attribute <code>attributeID</code> for the class <code>event</code>. 
     79     *  
     80     * @param event the event 
     81     * @param attributeID the attribute id 
     82     * @return the value for object 
     83     */ 
     84    protected final Object getValueForObject(final Event event, final String attributeID) { 
     85        final Object result = ReflectionHelper.getValueFromObject(attributeID, event); 
    6786        return result; 
    6887    } 
    6988 
    70     protected void setValueForObject(Event event, String value, String attributeID) { 
     89    /** 
     90     * Sets the value of the attribute <code>attributeID</code> for the class <code>event</code>. 
     91     *  
     92     * @param event the event to set the <code>value</code> on 
     93     * @param value the value to set on the <code>event</code> 
     94     * @param attributeID the field name of the field to set the <code>value</code> on 
     95     */ 
     96    protected final void setValueForObject(final Event event, final String value, final String attributeID) { 
    7197        ReflectionHelper.setValueOnObject(attributeID, value, event); 
    7298    } 
    7399 
    74     public void setPermitValueRule(MatchRule permitValueRule) { 
     100    /** 
     101     * Sets the permit value rule. 
     102     *  
     103     * @param permitValueRule the new permit value rule 
     104     */ 
     105    public void setPermitValueRule(final MatchRule permitValueRule) { 
    75106        this.permitValueRule = permitValueRule; 
    76107    } 
    77108 
     109    /** 
     110     * Gets the permit value rule. 
     111     *  
     112     * @return the permit value rule 
     113     */ 
    78114    public MatchRule getPermitValueRule() { 
    79115        return permitValueRule; 
    80116    } 
    81117 
    82     public void setDenyValueRule(MatchRule denyValueRule) { 
     118    /** 
     119     * Sets the deny value rule. 
     120     *  
     121     * @param denyValueRule the new deny value rule 
     122     */ 
     123    public void setDenyValueRule(final MatchRule denyValueRule) { 
    83124        this.denyValueRule = denyValueRule; 
    84125    } 
    85126 
     127    /** 
     128     * Gets the deny value rule. 
     129     *  
     130     * @return the deny value rule 
     131     */ 
    86132    public MatchRule getDenyValueRule() { 
    87133        return denyValueRule; 
     
    89135 
    90136    /** 
     137     * Sets the event type. 
     138     *  
    91139     * @param eventType the eventType to set 
    92140     */ 
    93     public void setEventType(Class<?> eventType) { 
     141    public void setEventType(final Class<?> eventType) { 
    94142        this.eventType = eventType; 
    95143    } 
    96144 
    97145    /** 
     146     * Gets the event type. 
     147     *  
    98148     * @return the eventType 
    99149     */ 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/HashAttributeRule.java

    r790 r1025  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptor.attribute.filtering; 
    2021 
     
    3233/** 
    3334 * @author philsmart 
    34  * 
     35 *  
    3536 */ 
    36 public class HashAttributeRule extends AttributeRule{ 
     37public final class HashAttributeRule extends BaseAttributeRule { 
    3738 
    3839    /** class logger. */ 
     
    4142    private String attributeId; 
    4243 
    43     /** The hashing algorithm used, this property is not user definable, its fixed to SHA-256*/ 
    44     private final String HASH_ALGORITHM="SHA-256"; 
     44    /** The hashing algorithm used, this property is not user definable, its fixed to SHA-256 */ 
     45    private final String HASH_ALGORITHM = "SHA-256"; 
    4546 
    4647    /** 
    47      * Hash the attribute defined by the <code>attributeId</code> tag, with the 
    48      * entityId name of this service. 
    49      * 
     48     * Hash the attribute defined by the <code>attributeId</code> tag, with the entityId name of this service. 
     49     *  
    5050     * @throws AttributeFilterException 
    5151     */ 
    52     public void filterAttribute(Event event, ServiceMetadata metadata) throws AttributeFilterException { 
    53         try{ 
     52    public void filterAttribute(final Event event, final ServiceMetadata metadata) throws AttributeFilterException { 
     53        try { 
    5454            if (classHasAttribute(event, getAttributeId())) { 
    55                 MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM); 
    56                 Object value = getValueForObject(event, getAttributeId()); 
    57                 if (value instanceof String){ 
    58                     String valueAsString = (String) value; 
    59                     String toHash = metadata.getEntityId()+valueAsString; 
     55                final MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM); 
     56                final Object value = getValueForObject(event, getAttributeId()); 
     57                if (value instanceof String) { 
     58                    final String valueAsString = (String) value; 
     59                    final String toHash = metadata.getEntityId() + valueAsString; 
    6060                    md.update(toHash.getBytes("UTF-8")); 
    61                     byte[] digest = md.digest(); 
    62                     BigInteger number = new BigInteger(1,digest); 
    63                     String hashedValue = number.toString(16); 
     61                    final byte[] digest = md.digest(); 
     62                    final BigInteger number = new BigInteger(1, digest); 
     63                    final String hashedValue = number.toString(16); 
    6464                    this.setValueForObject(event, hashedValue, getAttributeId()); 
    65                 } 
    66                 else{ 
    67                         throw new AttributeFilterException("The hash filter requires attributes of type String"); 
     65                } else { 
     66                    throw new AttributeFilterException("The hash filter requires attributes of type String"); 
    6867                } 
    6968 
    7069            } 
    71         } 
    72         catch (NoSuchAlgorithmException e){ 
     70        } catch (final NoSuchAlgorithmException e) { 
    7371            throw new AttributeFilterException(e); 
    74         } catch (UnsupportedEncodingException e) { 
     72        } catch (final UnsupportedEncodingException e) { 
    7573            throw new AttributeFilterException(e); 
    7674        } 
     
    8179     * @param attributeId the attributeId to set 
    8280     */ 
    83     public void setAttributeId(String attributeId) { 
     81    public void setAttributeId(final String attributeId) { 
    8482        this.attributeId = attributeId; 
    8583    } 
     
    9290    } 
    9391 
    94  
    95  
    9692} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/NullAttributeRule.java

    r817 r1025  
    1414 * limitations under the License. 
    1515 */ 
    16 /** 
    17  * 
    18  */ 
     16 
    1917package uk.ac.cardiff.raptor.attribute.filtering; 
    2018 
    2119import uk.ac.cardiff.model.ServiceMetadata; 
    2220import uk.ac.cardiff.model.event.Event; 
     21import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    2322 
    2423/** 
    2524 * @author philsmart 
    26  * 
     25 *  
    2726 */ 
    28 public class NullAttributeRule extends AttributeRule{ 
     27public final class NullAttributeRule extends BaseAttributeRule { 
    2928 
    30     /* needs to be the exact field name of the attribute */ 
    3129    private String attributeId; 
    3230 
    33  
    34     public void filterAttribute(Event event, ServiceMetadata metadata) { 
    35         String attributeID = getAttributeId(); 
     31    public void filterAttribute(final Event event, final ServiceMetadata metadata) { 
     32        final String attributeID = getAttributeId(); 
    3633        if (classHasAttribute(event, attributeID)) { 
    37                nullAttribute(event, attributeID); 
     34            nullAttribute(event, attributeID); 
    3835        } 
    3936    } 
    4037 
     38    /** 
     39     * Null the attribute specified by the parameter <code>attributeID</code>. 
     40     *  
     41     * @param event the event 
     42     * @param attributeID the attribute id 
     43     */ 
     44    protected void nullAttribute(final Event event, final String attributeID) { 
     45        ReflectionHelper.nullAttribute(event, attributeID); 
     46    } 
    4147 
    42     public void setAttributeId(String attributeId) { 
     48    public void setAttributeId(final String attributeId) { 
    4349        this.attributeId = attributeId; 
    4450    } 
     51 
    4552    public String getAttributeId() { 
    4653        return attributeId; 
    4754    } 
    4855 
    49  
    5056} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseEngine.java

    r817 r1025  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptor.remoting.client; 
    2021 
     
    3940/** 
    4041 * @author philsmart 
    41  * 
     42 *  
    4243 */ 
    4344public class EventReleaseEngine { 
    4445 
    45         /** Engine that provides attribute filtering before events are released */ 
    46         private AttrributeFilterEngine attributeFilterEngine; 
    47  
    48         /** Class that handles the transport of events to the endpoint */ 
    49         private ServiceEndpointClient serviceEndpointInterface; 
    50  
    51  
    52         /** Class logger */ 
    53         private final Logger log = LoggerFactory.getLogger(EventReleaseEngine.class); 
    54  
    55         /** 
    56          * Performs the release of all events to all applicable endpoints defined in 
    57          * the endpoint registry. Endpoints are applicable to be sent to if they 
    58          * meet the push policy defined on them. Event attributes are also filtered 
    59          * according to the attribute filter policy defined per endpoint. 
    60          * 
    61          * @param authenticationModules 
    62          */ 
    63         public boolean release(EndpointRegistry endpointRegistry, List<Event> events, ServiceMetadata serviceMetadata) { 
    64                 boolean releasedtoAll = true; 
    65                 int releaseCount = 0; 
    66                 for (Endpoint endpoint : endpointRegistry.getEndpoints()) { 
    67                         List<Event> applicableEvents = chronologicalFilter(endpoint, events); 
    68                         applicableEvents = eventTypeFilter(endpoint,applicableEvents); 
    69                         boolean shouldRelease = shouldRelease(endpoint,applicableEvents); 
    70                         log.debug("Endpoint {}, should release {}", endpoint.getServiceEndpoint(), shouldRelease); 
    71                         if (shouldRelease) { 
    72                                 List<Event> filteredEntries = filterAttributes(serviceMetadata, endpoint, applicableEvents); 
    73                                 appendMetadata(filteredEntries,serviceMetadata); 
    74                                 EventPushMessage pushMessage = constructEventPush(serviceMetadata, filteredEntries); 
    75                                 log.debug("Pushing {} entries to the Endpoint [{}]", filteredEntries.size(),endpoint.getServiceEndpoint()); 
    76                                 boolean releaseSuccess = getServiceEndpointInterface().sendEvents(pushMessage,endpoint); 
    77                                 log.debug("Release to [{}] succeeded {}", endpoint.getServiceEndpoint(), releaseSuccess); 
    78                                 if (releaseSuccess == false) 
    79                                         releasedtoAll = false; 
    80                                 else if (releaseSuccess ==true){ 
    81                                         releaseCount++; 
    82                                         /* Saves the state of the event before modification e.g. <code>applicableEvents</code> 
    83                                          * not <code>filteredEntries</code> */ 
    84                                         endpoint.releasePerformed(applicableEvents); 
    85                                         log.debug("Endpoint [{}] has been sent events up to and including {}",endpoint.getServiceEndpoint(), 
    86                                                         endpoint.getReleaseInformation().getLastReleasedEventTime()); 
    87                                 } 
    88                         } else { 
    89                                 releasedtoAll = false; 
    90                         } 
    91  
    92                 } 
    93                 log.info("Released to {} listening Endpoints, out of a total of {}", releaseCount, endpointRegistry 
    94                                 .getEndpoints().size()); 
    95  
    96                 return releasedtoAll; 
    97  
    98         } 
    99  
    100  
    101         /** 
     46    /** Engine that provides attribute filtering before events are released */ 
     47    private AttrributeFilterEngine attributeFilterEngine; 
     48 
     49    /** Class that handles the transport of events to the endpoint */ 
     50    private ServiceEndpointClient serviceEndpointInterface; 
     51 
     52    /** Class logger */ 
     53    private final Logger log = LoggerFactory.getLogger(EventReleaseEngine.class); 
     54 
     55    /** 
     56     * Performs the release of all events to all applicable endpoints defined in the endpoint registry. Endpoints are 
     57     * applicable to be sent to if they meet the push policy defined on them. Event attributes are also filtered 
     58     * according to the attribute filter policy defined per endpoint. 
     59     *  
     60     * @param authenticationModules 
     61     */ 
     62    public boolean release(EndpointRegistry endpointRegistry, List<Event> events, ServiceMetadata serviceMetadata) { 
     63        boolean releasedtoAll = true; 
     64        int releaseCount = 0; 
     65        for (Endpoint endpoint : endpointRegistry.getEndpoints()) { 
     66            List<Event> applicableEvents = chronologicalFilter(endpoint, events); 
     67            applicableEvents = eventTypeFilter(endpoint, applicableEvents); 
     68            boolean shouldRelease = shouldRelease(endpoint, applicableEvents); 
     69            log.debug("Endpoint {}, should release {}", endpoint.getServiceEndpoint(), shouldRelease); 
     70            if (shouldRelease) { 
     71                List<Event> filteredEntries = filterAttributes(serviceMetadata, endpoint, applicableEvents); 
     72                appendMetadata(filteredEntries, serviceMetadata); 
     73                EventPushMessage pushMessage = constructEventPush(serviceMetadata, filteredEntries); 
     74                log.debug("Pushing {} entries to the Endpoint [{}]", filteredEntries.size(), 
     75                        endpoint.getServiceEndpoint()); 
     76                boolean releaseSuccess = getServiceEndpointInterface().sendEvents(pushMessage, endpoint); 
     77                log.debug("Release to [{}] succeeded {}", endpoint.getServiceEndpoint(), releaseSuccess); 
     78                if (releaseSuccess == false) 
     79                    releasedtoAll = false; 
     80                else if (releaseSuccess == true) { 
     81                    releaseCount++; 
     82                    /* 
     83                     * Saves the state of the event before modification e.g. <code>applicableEvents</code> not 
     84                     * <code>filteredEntries</code> 
     85                     */ 
     86                    endpoint.releasePerformed(applicableEvents); 
     87                    log.debug("Endpoint [{}] has been sent events up to and including {}", 
     88                            endpoint.getServiceEndpoint(), endpoint.getReleaseInformation().getLastReleasedEventTime()); 
     89                } 
     90            } else { 
     91                releasedtoAll = false; 
     92            } 
     93 
     94        } 
     95        log.info("Released to {} listening Endpoints, out of a total of {}", releaseCount, endpointRegistry 
     96                .getEndpoints().size()); 
     97 
     98        return releasedtoAll; 
     99 
     100    } 
     101 
     102    /** 
    102103     * Method that returns those events that are supported by the <code>endpoint</code parameter. 
    103      * 
     104     *  
    104105     * @param endpoint 
    105106     * @param applicableEvents 
     
    107108     */ 
    108109    private List<Event> eventTypeFilter(Endpoint endpoint, List<Event> events) { 
    109         if (endpoint.getSupportedEvents()==null){ 
    110             log.info("There are 0 events to send to the endpoint [{}] after event type filtering. Has the endpoint been set" + 
    111                         " with the correct supported event types?",endpoint.getServiceEndpoint()); 
     110        if (endpoint.getSupportedEvents() == null) { 
     111            log.info( 
     112                    "There are 0 events to send to the endpoint [{}] after event type filtering. Has the endpoint been set" 
     113                            + " with the correct supported event types?", endpoint.getServiceEndpoint()); 
    112114            return new ArrayList<Event>(); 
    113115        } 
    114116 
    115117        ArrayList<Event> applicableEvents = new ArrayList<Event>(); 
    116         for (Event event : events){ 
     118        for (Event event : events) { 
    117119            boolean supported = false; 
    118             for (Class<?> supportedClass : endpoint.getSupportedEvents()){ 
    119                 if (event.getClass()==supportedClass){ 
     120            for (Class<?> supportedClass : endpoint.getSupportedEvents()) { 
     121                if (event.getClass() == supportedClass) { 
    120122                    supported = true; 
    121123                } 
    122124            } 
    123             if (supported){ 
     125            if (supported) { 
    124126                applicableEvents.add(event); 
    125127            } 
    126128 
    127129        } 
    128         log.info("There are {} events to send to the endpoint [{}] after event type filtering",applicableEvents.size(),endpoint.getServiceEndpoint()); 
     130        log.info("There are {} events to send to the endpoint [{}] after event type filtering", 
     131                applicableEvents.size(), endpoint.getServiceEndpoint()); 
    129132        return applicableEvents; 
    130133    } 
    131134 
    132  
    133     private void appendMetadata(List<Event> events, ServiceMetadata metadata){ 
    134         for (Event event : events){ 
     135    private void appendMetadata(List<Event> events, ServiceMetadata metadata) { 
     136        for (Event event : events) { 
    135137            EventMetadata eventMetadata = new EventMetadata(); 
    136138            eventMetadata.setEntityId(metadata.getEntityId()); 
     
    142144 
    143145    /** 
    144          * Filters the input list of events (<code>events</code>) such that only those that are after (chronological) 
    145          * the <code>latestPublishedEventTime</code> of the input <code>Endpoint</code> remain 
    146          * 
    147          * @param endpoint the endpoint that is to be filtered on 
    148          * @param events the list of events that are filtered chronologically 
    149          * @return the list of filtered events 
    150          */ 
    151         private List<Event> chronologicalFilter(Endpoint endpoint, List<Event> events){ 
    152                 ArrayList<Event> applicableEvents = new ArrayList<Event>(); 
    153  
    154                 for (Event event : events){ 
    155                     if (endpoint.getReleaseInformation().hasNotBeenReleased(event)){ 
    156                                 applicableEvents.add(event); 
    157                         } 
    158                 } 
    159                 log.info("There are {} events to send to the endpoint [{}] after {}",new Object[]{applicableEvents.size(),endpoint.getServiceEndpoint(),endpoint.getReleaseInformation().getLastReleasedEventTime()}); 
    160                 return applicableEvents; 
    161         } 
    162  
    163         /** 
    164          * Iterates through all push policies attached to the <code>endpoint</code> parameter 
    165          * to determine if events should be released to this endpoint 
    166          * 
    167          * @param endpoint the endpoint to evaluate the policy on 
    168          * @param events the events ready to be released. 
    169          * @return true iff at least one push policy evaluates to true, false otherwise 
    170          */ 
    171         private boolean shouldRelease(Endpoint endpoint, List<Event> events){ 
    172                 boolean shouldRelease = false; 
    173                 for (PushPolicy policy : endpoint.getPushPolicies()){ 
    174                         if (policy.evaluatePolicy(events)) 
    175                                 shouldRelease = true; 
    176                 } 
    177                 return shouldRelease; 
    178         } 
    179  
    180         /** 
    181          * Filters the attributes from each event being pushed to the input 
    182          * endpoint. If no filter policy has been defined, no work is done, and the 
    183          * input allEvents is returned without modification 
    184          * 
    185          * @param endpoint 
    186          * @param allEvents 
    187          * @return 
    188          */ 
    189         private List<Event> filterAttributes(ServiceMetadata metadata, Endpoint endpoint, List<Event> allEvents) { 
    190                 if (endpoint.getAttributeFilterPolicy() == null) 
    191                         return allEvents; 
    192                 return attributeFilterEngine.filter(endpoint.getAttributeFilterPolicy(), metadata, allEvents); 
    193         } 
    194  
    195         /** 
    196          * Constructs an event push message, which encapsulates the events to send and some 
    197          * metadata about the list of events. 
    198          * 
    199          * @param clientMetadata 
    200          * @param events 
    201          * @return 
    202          */ 
    203         private EventPushMessage constructEventPush(ServiceMetadata clientMetadata, List<Event> events) { 
    204                 EventPushMessage pushMessage = new EventPushMessage(); 
    205                 pushMessage.setClientMetadata(clientMetadata); 
    206                 pushMessage.setEvents(events); 
    207                 pushMessage.setTimeOfPush(new Date(System.currentTimeMillis())); 
    208                 return pushMessage; 
    209         } 
    210  
    211  
    212         public void setAttributeFilterEngine(AttrributeFilterEngine attributeFilterEngine) { 
    213                 this.attributeFilterEngine = attributeFilterEngine; 
    214         } 
    215  
    216         public AttrributeFilterEngine getAttributeFilterEngine() { 
    217                 return attributeFilterEngine; 
    218         } 
    219  
    220         public void setServiceEndpointInterface(ServiceEndpointClient serviceEndpointInterface) { 
    221                 this.serviceEndpointInterface = serviceEndpointInterface; 
    222         } 
    223  
    224         public ServiceEndpointClient getServiceEndpointInterface() { 
    225                 return serviceEndpointInterface; 
    226         } 
    227  
     146     * Filters the input list of events (<code>events</code>) such that only those that are after (chronological) the 
     147     * <code>latestPublishedEventTime</code> of the input <code>Endpoint</code> remain 
     148     *  
     149     * @param endpoint the endpoint that is to be filtered on 
     150     * @param events the list of events that are filtered chronologically 
     151     * @return the list of filtered events 
     152     */ 
     153    private List<Event> chronologicalFilter(Endpoint endpoint, List<Event> events) { 
     154        ArrayList<Event> applicableEvents = new ArrayList<Event>(); 
     155 
     156        for (Event event : events) { 
     157            if (endpoint.getReleaseInformation().hasNotBeenReleased(event)) { 
     158                applicableEvents.add(event); 
     159            } 
     160        } 
     161        log.info("There are {} events to send to the endpoint [{}] after {}", new Object[] {applicableEvents.size(), 
     162                endpoint.getServiceEndpoint(), endpoint.getReleaseInformation().getLastReleasedEventTime()}); 
     163        return applicableEvents; 
     164    } 
     165 
     166    /** 
     167     * Iterates through all push policies attached to the <code>endpoint</code> parameter to determine if events should 
     168     * be released to this endpoint 
     169     *  
     170     * @param endpoint the endpoint to evaluate the policy on 
     171     * @param events the events ready to be released. 
     172     * @return true iff at least one push policy evaluates to true, false otherwise 
     173     */ 
     174    private boolean shouldRelease(Endpoint endpoint, List<Event> events) { 
     175        boolean shouldRelease = false; 
     176        for (PushPolicy policy : endpoint.getPushPolicies()) { 
     177            if (policy.evaluatePolicy(events)) 
     178                shouldRelease = true; 
     179        } 
     180        return shouldRelease; 
     181    } 
     182 
     183    /** 
     184     * Filters the attributes from each event being pushed to the input endpoint. If no filter policy has been defined, 
     185     * no work is done, and the input allEvents is returned without modification 
     186     *  
     187     * @param endpoint 
     188     * @param allEvents 
     189     * @return 
     190     */ 
     191    private List<Event> filterAttributes(ServiceMetadata metadata, Endpoint endpoint, List<Event> allEvents) { 
     192        if (endpoint.getAttributeFilterPolicy() == null) 
     193            return allEvents; 
     194        return attributeFilterEngine.filter(endpoint.getAttributeFilterPolicy(), metadata, allEvents); 
     195    } 
     196 
     197    /** 
     198     * Constructs an event push message, which encapsulates the events to send and some metadata about the list of 
     199     * events. 
     200     *  
     201     * @param clientMetadata 
     202     * @param events 
     203     * @return 
     204     */ 
     205    private EventPushMessage constructEventPush(ServiceMetadata clientMetadata, List<Event> events) { 
     206        EventPushMessage pushMessage = new EventPushMessage(); 
     207        pushMessage.setClientMetadata(clientMetadata); 
     208        pushMessage.setEvents(events); 
     209        pushMessage.setTimeOfPush(new Date(System.currentTimeMillis())); 
     210        return pushMessage; 
     211    } 
     212 
     213    public void setAttributeFilterEngine(AttrributeFilterEngine attributeFilterEngine) { 
     214        this.attributeFilterEngine = attributeFilterEngine; 
     215    } 
     216 
     217    public AttrributeFilterEngine getAttributeFilterEngine() { 
     218        return attributeFilterEngine; 
     219    } 
     220 
     221    public void setServiceEndpointInterface(ServiceEndpointClient serviceEndpointInterface) { 
     222        this.serviceEndpointInterface = serviceEndpointInterface; 
     223    } 
     224 
     225    public ServiceEndpointClient getServiceEndpointInterface() { 
     226        return serviceEndpointInterface; 
     227    } 
    228228 
    229229} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/ClientTLSParameters.java

    r817 r1025  
    5959 
    6060        public TLSClientParameters getTlsClientParameters() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException{ 
    61             TLSClientParameters tls = new TLSClientParameters(); 
     61            final TLSClientParameters tls = new TLSClientParameters(); 
    6262 
    6363            tls.setDisableCNCheck(true);//disable URL and CN on cert match 
    6464 
    6565            //clients private key / public key 
    66             KeyStore keyStoreKeyManager = KeyStore.getInstance("JKS"); 
    67             File keyStoreFile = new File(keyStoreLocation); 
     66            final KeyStore keyStoreKeyManager = KeyStore.getInstance("JKS"); 
     67            final File keyStoreFile = new File(keyStoreLocation); 
    6868            keyStoreKeyManager.load(new FileInputStream(keyStoreFile),  keyStorePassword.toCharArray()); 
    69             KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 
     69            final KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 
    7070            keyFactory.init(keyStoreKeyManager, keyStorePassword.toCharArray()); 
    7171 
    72             KeyManager[] km = keyFactory.getKeyManagers(); 
     72            final KeyManager[] km = keyFactory.getKeyManagers(); 
    7373            tls.setKeyManagers(km); 
    7474 
    7575            //servers public key 
    76             KeyStore keyStore = KeyStore.getInstance("JKS"); 
    77             File truststore = new File(trustStoreLocation); 
     76            final KeyStore keyStore = KeyStore.getInstance("JKS"); 
     77            final File truststore = new File(trustStoreLocation); 
    7878            keyStore.load(new FileInputStream(truststore),  trustStorePassword.toCharArray()); 
    79             TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
     79            final TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
    8080            trustFactory.init(keyStore); 
    8181 
    82             TrustManager[] tm = trustFactory.getTrustManagers(); 
     82            final TrustManager[] tm = trustFactory.getTrustManagers(); 
    8383            tls.setTrustManagers(tm); 
    8484 
     
    8787        } 
    8888 
    89         public void setTrustStoreLocation(String trustStoreLocation) { 
     89        public void setTrustStoreLocation(final String trustStoreLocation) { 
    9090                this.trustStoreLocation = trustStoreLocation; 
    9191        } 
     
    9595        } 
    9696 
    97         public void setKeyStoreLocation(String keyStoreLocation) { 
     97        public void setKeyStoreLocation(final String keyStoreLocation) { 
    9898                this.keyStoreLocation = keyStoreLocation; 
    9999        } 
     
    103103        } 
    104104 
    105         public void setTrustStorePassword(String trustStorePassword) { 
     105        public void setTrustStorePassword(final String trustStorePassword) { 
    106106                this.trustStorePassword = trustStorePassword; 
    107107        } 
     
    111111        } 
    112112 
    113         public void setKeyStorePassword(String keyStorePassword) { 
     113        public void setKeyStorePassword(final String keyStorePassword) { 
    114114                this.keyStorePassword = keyStorePassword; 
    115115        } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/sei/impl/CxfServiceEndpointClient.java

    r817 r1025  
    1414 * limitations under the License. 
    1515 */ 
     16 
    1617package uk.ac.cardiff.raptor.remoting.client.sei.impl; 
    17  
    1818 
    1919import java.util.HashSet; 
    2020import java.util.Set; 
    21  
    22  
    2321 
    2422import org.apache.cxf.aegis.DatabindingException; 
     
    4846    private final Logger log = LoggerFactory.getLogger(CxfServiceEndpointClient.class); 
    4947 
    50     /** Raptor specific TLS parameters class, that can return cxf TLSParameters*/ 
     48    /** Raptor specific TLS parameters class, that can return cxf TLSParameters */ 
    5149    private ClientTLSParameters tlsParameters; 
    5250 
    5351    @Override 
    5452    public boolean sendEvents(EventPushMessage pushed, Endpoint endpoint) { 
    55         try { 
    56             ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); 
    57             factory.setServiceClass(MultiUnitAggregator.class); 
    58             AegisDatabinding databinding = new AegisDatabinding(); 
     53        try { 
     54            ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); 
     55            factory.setServiceClass(MultiUnitAggregator.class); 
     56            AegisDatabinding databinding = new AegisDatabinding(); 
    5957 
    60             org.apache.cxf.aegis.AegisContext context = new org.apache.cxf.aegis.AegisContext(); 
    61             context.setWriteXsiTypes(true); 
     58            org.apache.cxf.aegis.AegisContext context = new org.apache.cxf.aegis.AegisContext(); 
     59            context.setWriteXsiTypes(true); 
    6260 
    63             Set<Class<?>> rootClasses = new HashSet<Class<?>>(); 
     61            Set<Class<?>> rootClasses = new HashSet<Class<?>>(); 
    6462 
    65             Set<String> overrides = new HashSet<String>(); 
    66             overrides.add(ShibbolethIdpAuthenticationEvent.class.getName()); 
    67             overrides.add(AuthenticationEvent.class.getName()); 
    68             overrides.add(EzproxyAuthenticationEvent.class.getName()); 
    69             overrides.add(OpenathenslaAuthenticationEvent.class.getName()); 
    70             databinding.setOverrideTypes(overrides); 
     63            Set<String> overrides = new HashSet<String>(); 
     64            overrides.add(ShibbolethIdpAuthenticationEvent.class.getName()); 
     65            overrides.add(AuthenticationEvent.class.getName()); 
     66            overrides.add(EzproxyAuthenticationEvent.class.getName()); 
     67            overrides.add(OpenathenslaAuthenticationEvent.class.getName()); 
     68            databinding.setOverrideTypes(overrides); 
    7169 
    72             for (String typeName : overrides) { 
    73                 Class<?> c = null; 
    74                 try { 
    75                     c = ClassLoaderUtils.loadClass(typeName, TypeUtil.class); 
    76                 } catch (ClassNotFoundException e) { 
    77                     throw new DatabindingException("Could not find override type class: " + typeName, e); 
    78                 } 
    79                 rootClasses.add(c); 
    80             } 
     70            for (String typeName : overrides) { 
     71                Class<?> c = null; 
     72                try { 
     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            } 
    8179 
    82             context.setRootClasses(rootClasses); 
    83             databinding.setAegisContext(context); 
     80            context.setRootClasses(rootClasses); 
     81            databinding.setAegisContext(context); 
    8482 
    85             factory.setAddress(endpoint.getServiceEndpoint()); 
    86             factory.getServiceFactory().setDataBinding(databinding); 
     83            factory.setAddress(endpoint.getServiceEndpoint()); 
     84            factory.getServiceFactory().setDataBinding(databinding); 
    8785 
    88             MultiUnitAggregator client = (MultiUnitAggregator) factory.create(); 
    89             org.apache.cxf.endpoint.Client cl = ClientProxy.getClient(client); 
    90             HTTPConduit httpConduit = (HTTPConduit) cl.getConduit(); 
    91             HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
    92             httpConduit.setClient(httpClientPolicy); 
     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); 
    9391 
     92            if (getTlsParameters() != null) 
     93                httpConduit.setTlsClientParameters(getTlsParameters().getTlsClientParameters()); 
    9494 
    95             if (getTlsParameters()!=null) 
    96                 httpConduit.setTlsClientParameters(getTlsParameters().getTlsClientParameters()); 
     95            log.debug("Accessing the endpoint version " + client.getVersion()); 
     96            client.addAuthentications(pushed); 
     97            log.debug("Sent {} events", pushed.getEvents().size()); 
    9798 
    98             log.debug("Accessing the endpoint version " + client.getVersion()); 
    99             client.addAuthentications(pushed); 
    100             log.debug("Sent {} events", pushed.getEvents().size()); 
    101  
    102             return true; 
    103         } catch (SoapFault e) { 
    104             log.error("Could not send events to endpoint [{}] -> {}", new Object[] { endpoint.getServiceEndpoint(), e.getMessage() }); 
    105             //e.printStackTrace(); 
    106             return false; 
    107         } catch (Exception e) { 
    108             log.error("Could not send events to endpoint [{}] -> {}", new Object[] { endpoint.getServiceEndpoint(), e.getMessage() }); 
    109             //e.printStackTrace(); 
    110             return false; 
    111         } 
     99            return true; 
     100        } catch (SoapFault e) { 
     101            log.error("Could not send events to endpoint [{}]", endpoint.getServiceEndpoint(), e); 
     102            return false; 
     103        } catch (Exception e) { 
     104            log.error("Could not send events to endpoint [{}]", endpoint.getServiceEndpoint(), e); 
     105            return false; 
     106        } 
    112107 
    113108    } 
     
    117112     */ 
    118113    public void setTlsParameters(ClientTLSParameters tlsParameters) { 
    119         this.tlsParameters = tlsParameters; 
     114        this.tlsParameters = tlsParameters; 
    120115    } 
    121116 
     
    124119     */ 
    125120    public ClientTLSParameters getTlsParameters() { 
    126         return tlsParameters; 
     121        return tlsParameters; 
    127122    } 
    128123 
Note: See TracChangeset for help on using the changeset viewer.