Changeset 784


Ignore:
Timestamp:
05/12/11 00:15:52 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-information-model/trunk/src
Files:
1 added
1 deleted
8 edited
1 moved

Legend:

Unmodified
Added
Removed
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/AuthenticationEvent.java

    r701 r784  
    2121import uk.ac.cardiff.model.event.auxiliary.PrincipalInformation; 
    2222 
    23  
    2423/** 
    2524 * @author philsmart 
    26  * 
     25 *  
    2726 */ 
    28 public class AuthenticationEvent extends Event{ 
     27public class AuthenticationEvent extends Event { 
    2928 
    30         private String authenticationType; 
    31         private String principalName; 
     29    private String authenticationType; 
     30    private String principalName; 
     31     
     32    /** This is fixed to a principal expansion */ 
     33    private PrincipalInformation principalInformation; 
     34     
     35     
     36    public AuthenticationEvent(){ 
     37        super(); 
     38    } 
     39     
     40    /** 
     41     * Copy constructor 
     42     *  
     43     * @param event 
     44     */ 
     45    public AuthenticationEvent(AuthenticationEvent event){ 
     46        super(event); 
     47        this.authenticationType = event.getAuthenticationType(); 
     48        this.principalName = event.getPrincipalName(); 
     49        this.principalInformation = new PrincipalInformation(event.getPrincipalInformation()); 
     50         
     51    } 
    3252 
    33         /**This is fixed to a principal expansion */ 
    34         private PrincipalInformation principalInformation; 
     53    public void setPrincipalName(String principalName) { 
     54        this.principalName = principalName; 
     55    } 
    3556 
    36         public void setPrincipalName(String principalName) { 
    37             this.principalName = principalName; 
    38         } 
    39         public String getPrincipalName() { 
    40             return principalName; 
    41         } 
    42         public void setAuthenticationType(String authenticationType) { 
    43             this.authenticationType = authenticationType; 
    44         } 
    45         public String getAuthenticationType() { 
    46             return authenticationType; 
    47         } 
     57    public String getPrincipalName() { 
     58        return principalName; 
     59    } 
     60 
     61    public void setAuthenticationType(String authenticationType) { 
     62        this.authenticationType = authenticationType; 
     63    } 
     64 
     65    public String getAuthenticationType() { 
     66        return authenticationType; 
     67    } 
     68 
    4869    /** 
    49      * @param principalInformation the principalInformation to set 
     70     * @param principalInformation 
     71     *            the principalInformation to set 
    5072     */ 
    5173    public void setPrincipalInformation(PrincipalInformation principalInformation) { 
    5274        this.principalInformation = principalInformation; 
    5375    } 
     76 
    5477    /** 
    5578     * @return the principalInformation 
     
    5982    } 
    6083 
    61  
    6284} 
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/Event.java

    r781 r784  
    4444    private int resourceIdCategory; 
    4545 
     46     
     47    public Event(){ 
     48         
     49    } 
     50     
     51    /** A Copy constructor */ 
     52    public Event(Event event){ 
     53        //this has a defensive getter, so a direct assignment is possible 
     54        this.eventTime = event.getEventTime(); 
     55        this.eventId = event.getEventId(); 
     56        this.serviceId = event.getServiceId(); 
     57        this.eventType = event.getEventType(); 
     58        this.serviceHost = event.getServiceHost(); 
     59        this.resourceHost = event.getServiceHost(); 
     60        this.resourceId = event.getResourceId(); 
     61        this.resourceIdCategory = event.getResourceIdCategory(); 
     62    } 
     63     
     64    public static Event newInstance() { 
     65        return new Event(); 
     66      } 
     67     
     68     
    4669    public void setEventTime(DateTime eventTime) { 
    4770        this.eventTime = eventTime; 
    4871    } 
    4972 
     73    /** 
     74     * Returns the eventTime using a defensive copy 
     75     * @return 
     76     */ 
    5077    public DateTime getEventTime() { 
    51         return eventTime; 
     78        return new DateTime(eventTime); 
    5279    } 
    53  
    54      public String toString() { 
    55          return getClass().getName()+"@[" + this.getEventTime() + "," + this.getServiceHost() + "," + this.getResourceHost() + "]"; 
    56      } 
    5780 
    5881    /** 
     
    89112    public long getEventTimeMillis(){ 
    90113        return eventTime.getMillis(); 
    91     } 
    92  
    93     public void setEventTimeMillis(long millis){ 
    94         eventTime = new DateTime(millis); 
    95114    } 
    96115 
     
    164183        return serviceId; 
    165184    } 
     185     
     186 
     187    public String toString() { 
     188        return getClass().getName()+"@[" + this.getEventTime() + "," + this.getServiceHost() + "," + this.getResourceHost() + "]"; 
     189    } 
    166190} 
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/EzproxyAuthenticationEvent.java

    r781 r784  
    1818    private String requesterIp; 
    1919    private String sessionId; 
     20     
     21    public EzproxyAuthenticationEvent(){ 
     22        super(); 
     23    } 
     24     
     25    public EzproxyAuthenticationEvent(EzproxyAuthenticationEvent event){ 
     26        super(event); 
     27        this.requesterIp = event.getRequesterIp(); 
     28        this.sessionId = event.getSessionId(); 
     29    } 
    2030 
    2131    public void setRequesterIp(String requesterIp) { 
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/EzproxyProxyEvent.java

    r660 r784  
    1414 
    1515    private String sessionId; 
     16     
     17    public EzproxyProxyEvent(){ 
     18        super(); 
     19    } 
     20     
     21    /** 
     22     * Copy constructor 
     23     *  
     24     * @param event 
     25     */ 
     26    public EzproxyProxyEvent(EzproxyProxyEvent event){ 
     27        super(event); 
     28        this.sessionId = event.getSessionId(); 
     29    } 
    1630 
    1731    /** 
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/OpenathenslaAuthenticationEvent.java

    r614 r784  
    88 * 
    99 */ 
    10 public class OpenathenslaAuthenticationEvent { 
     10public class OpenathenslaAuthenticationEvent extends Event{ 
    1111 
    1212    private String requesterIP; 
    1313 
     14    public OpenathenslaAuthenticationEvent(){ 
     15        super(); 
     16    } 
     17     
     18    public OpenathenslaAuthenticationEvent(OpenathenslaAuthenticationEvent event){ 
     19        super(event); 
     20        this.requesterIP = event.getRequesterIP(); 
     21    } 
     22     
    1423    public void setRequesterIP(String requesterIP) { 
    1524        this.requesterIP = requesterIP; 
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/ProxyEvent.java

    r660 r784  
    1818    private DateTime responseTime; 
    1919    private String requesterIp; 
     20     
     21    public ProxyEvent(){ 
     22        super(); 
     23    } 
     24     
     25    /** 
     26     * Copy constructor 
     27     * @param event 
     28     */ 
     29    public ProxyEvent(ProxyEvent event){ 
     30        super(event); 
     31        this.requestURL = event.getRequestURL(); 
     32        this.httpResponseCode = event.getHttpResponseCode(); 
     33        this.responseSize = event.getResponseSize(); 
     34        this.responseTime = event.getResponseTime(); 
     35        this.requesterIp = event.getRequesterIp(); 
     36    } 
    2037 
    2138 
     
    4158        this.responseTime = responseTime; 
    4259    } 
     60     
     61    /** 
     62     * Get response time, using a defensive copy 
     63     *  
     64     * @return 
     65     */ 
    4366    public DateTime getResponseTime() { 
    44         return responseTime; 
     67        return new DateTime(responseTime); 
    4568    } 
    4669    /** 
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/ShibbolethIdpAuthenticationEvent.java

    r781 r784  
    2929        private String[] releasedAttributes; 
    3030 
    31  
     31         
     32        public ShibbolethIdpAuthenticationEvent(){ 
     33            super(); 
     34        } 
     35         
     36        public static ShibbolethIdpAuthenticationEvent newInstance() { 
     37            return new ShibbolethIdpAuthenticationEvent(); 
     38          } 
     39 
     40        /**  
     41         * Copy constructor  
     42         *  
     43         * @param event 
     44         */ 
     45        public ShibbolethIdpAuthenticationEvent(ShibbolethIdpAuthenticationEvent event){ 
     46            super (event); 
     47            this.requestPath = event.getRequestPath(); 
     48            this.requestId = event.getRequestId(); 
     49            this.messageProfileId = event.getMessageProfileId(); 
     50            this.responseBinding = event.getResponseBinding(); 
     51            this.responseId = event.getResponseId(); 
     52            this.requestBinding = event.getRequestBinding(); 
     53            this.nameIdentifier = event.getNameIdentifier(); 
     54             
     55            //shallow copy is OK here, as a new array is created with immutable objects (String). 
     56            this.assertionId = event.getAssertionId().clone(); 
     57            this.releasedAttributes = event.getReleasedAttributes().clone(); 
     58        } 
    3259 
    3360        public void setRequestPath(String requestPath) { 
     
    81108                            if (object instanceof Collection){ 
    82109                                 builder.append(method.getName() + " [" + Arrays.asList(object) + "],"); 
     110                            } 
     111                            else if (object.getClass().isArray()){ 
     112                                Object[] array = (Object[])object; 
     113                                builder.append(method.getName() + " [" + Arrays.asList(array) + "],"); 
    83114                            } 
    84115                            else{ 
  • raptor-information-model/trunk/src/main/java/uk/ac/cardiff/model/event/auxiliary/PrincipalInformation.java

    r708 r784  
    1515    /** The affiliation this principal has with their current school or department */ 
    1616    private String affiliation; 
     17     
     18     
     19    /** 
     20     * Default constructor 
     21     *  
     22     */ 
     23    public PrincipalInformation(){ 
     24         
     25    } 
     26     
     27    /** 
     28     * Copy constructor 
     29     *  
     30     * @param principalInformation 
     31     */ 
     32    public PrincipalInformation(PrincipalInformation principalInformation){ 
     33        this.school = principalInformation.getSchool(); 
     34        this.affiliation = principalInformation.getAffiliation(); 
     35    } 
    1736 
    1837    /** 
  • raptor-information-model/trunk/src/test/java/uk/ac/cardiff/model/event/ShibbolethEntryTest.java

    r783 r784  
    22 * 
    33 */ 
    4 package uk.ac.cardiff.model; 
     4package uk.ac.cardiff.model.event; 
    55 
    66 
    77import static org.junit.Assert.assertTrue; 
    88 
     9import org.hibernate.mapping.PrimaryKey; 
    910import org.joda.time.DateTime; 
    1011import org.joda.time.format.DateTimeFormat; 
     
    1314 
    1415import uk.ac.cardiff.model.event.ShibbolethIdpAuthenticationEvent; 
     16import uk.ac.cardiff.model.event.auxiliary.PrincipalInformation; 
    1517 
    1618 
     
    152154 
    153155    } 
     156     
     157    @Test 
     158    public void testConstructorCopy(){ 
     159        ShibbolethIdpAuthenticationEvent entry = new ShibbolethIdpAuthenticationEvent(); 
     160        entry.setAuthenticationType("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); 
     161        String eventTime ="20101117T184343"; 
     162        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss"); 
     163        DateTime dt = dtf.parseDateTime(eventTime); 
     164        entry.setEventTime(dt); 
     165        entry.setMessageProfileId("urn:mace:shibboleth:2.0:profiles:saml2:sso"); 
     166        entry.setPrincipalName("scmps2"); 
     167        entry.setRequestBinding("urn:mace:shibboleth:1.0:profiles:AuthnRequest"); 
     168        entry.setReleasedAttributes(new String[]{"eduPersonScopedAffiliation","eduPersonEntitlement"}); 
     169        entry.setServiceHost("https://abc.cardiff.ac.uk/sp/shibboleth"); 
     170        entry.setRequestId(""); 
     171        entry.setRequestPath(""); 
     172        entry.setResponseBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"); 
     173        entry.setResourceHost("https://idp.cardiff.ac.uk/shibboleth"); 
     174        entry.setAssertionId(new String[]{"1"}); 
     175        entry.setEventId(100); 
     176        entry.setNameIdentifier("name1"); 
     177        PrincipalInformation principle = new PrincipalInformation(); 
     178        principle.setAffiliation("U"); 
     179        principle.setSchool("COMSC"); 
     180        entry.setPrincipalInformation(principle); 
     181        entry.setResourceId("http://raptor.test"); 
     182         
     183        System.out.println("testConstructorCopy:First Event :"+entry); 
     184        int hashBefore = entry.getHashCode(); 
     185 
     186 
     187        ShibbolethIdpAuthenticationEvent copy =  new ShibbolethIdpAuthenticationEvent(entry); 
     188        copy.setAuthenticationType("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport-new"); 
     189        eventTime ="20111117T184343"; 
     190        dtf = DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss"); 
     191        dt = dtf.parseDateTime(eventTime); 
     192        copy.setEventTime(dt); 
     193        copy.setMessageProfileId("urn:mace:shibboleth:2.0:profiles:saml2:sso-new"); 
     194        copy.setPrincipalName("new"); 
     195        copy.setRequestBinding("urn:mace:shibboleth:1.0:profiles:AuthnRequest-new"); 
     196        copy.setReleasedAttributes(new String[]{"eduPersonScopedAffiliation"}); //removed eduPersonEntitlement 
     197        copy.setServiceHost("https://abc.cardiff.ac.uk/sp/shibboleth-new"); 
     198        copy.setRequestId("new"); 
     199        copy.setRequestPath("new"); 
     200        copy.setResponseBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-SOAP-new"); 
     201        copy.setResourceHost("https://idp.cardiff.ac.uk/shibboleth-new"); 
     202        copy.setAssertionId(new String[]{"1","4"}); 
     203        copy.setEventId(300); 
     204        copy.setNameIdentifier("new"); 
     205        PrincipalInformation principleCopy = new PrincipalInformation(principle); 
     206        copy.setPrincipalInformation(principleCopy); 
     207        copy.setResourceId("http://raptor.test.new"); 
     208 
     209         
     210        System.out.println("testConstructorCopy:Copied Event:"+copy); 
     211        System.out.println("testConstructorCopy:First After :"+entry); 
     212         
     213        System.out.println("testConstructorCopy:First:Shibboleth Event, First Instance has hash ["+hashBefore+"], " + 
     214                "Copy has Hash ["+copy.getHashCode()+"], First after copy has hash ["+entry.getHashCode()+"], first and firts after copy" + 
     215                                "should be equal ["+(hashBefore==entry.getHashCode())+"]"); 
     216         
     217        assertTrue(hashBefore==entry.getHashCode()); 
     218    } 
     219     
     220    /** 
     221     * Test that a copy produces the same object 
     222     */ 
     223    @Test 
     224    public void testShibConstructorCopyEquals(){ 
     225        ShibbolethIdpAuthenticationEvent entry = new ShibbolethIdpAuthenticationEvent(); 
     226        entry.setAuthenticationType("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); 
     227        String eventTime ="20101117T184343"; 
     228        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss"); 
     229        DateTime dt = dtf.parseDateTime(eventTime); 
     230        entry.setEventTime(dt); 
     231        entry.setMessageProfileId("urn:mace:shibboleth:2.0:profiles:saml2:sso"); 
     232        entry.setPrincipalName("scmps2"); 
     233        entry.setRequestBinding("urn:mace:shibboleth:1.0:profiles:AuthnRequest"); 
     234        entry.setReleasedAttributes(new String[]{"eduPersonScopedAffiliation","eduPersonEntitlement"}); 
     235        entry.setServiceHost("https://abc.cardiff.ac.uk/sp/shibboleth"); 
     236        entry.setRequestId(""); 
     237        entry.setRequestPath(""); 
     238        entry.setResponseBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"); 
     239        entry.setResourceHost("https://idp.cardiff.ac.uk/shibboleth"); 
     240        entry.setAssertionId(new String[]{"1"}); 
     241        entry.setEventId(100); 
     242        entry.setNameIdentifier("name1"); 
     243        PrincipalInformation principle = new PrincipalInformation(); 
     244        principle.setAffiliation("U"); 
     245        principle.setSchool("COMSC"); 
     246        entry.setPrincipalInformation(principle); 
     247        entry.setResourceId("http://raptor.test"); 
     248         
     249 
     250 
     251        ShibbolethIdpAuthenticationEvent copy = new ShibbolethIdpAuthenticationEvent(entry); 
     252        copy.setAuthenticationType("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); 
     253        eventTime ="20101117T184343"; 
     254        dtf = DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss"); 
     255        dt = dtf.parseDateTime(eventTime); 
     256        copy.setEventTime(dt); 
     257        copy.setMessageProfileId("urn:mace:shibboleth:2.0:profiles:saml2:sso"); 
     258        copy.setPrincipalName("scmps2"); 
     259        copy.setRequestBinding("urn:mace:shibboleth:1.0:profiles:AuthnRequest"); 
     260        copy.setReleasedAttributes(new String[]{"eduPersonScopedAffiliation","eduPersonEntitlement"}); //removed eduPersonEntitlement 
     261        copy.setServiceHost("https://abc.cardiff.ac.uk/sp/shibboleth"); 
     262        copy.setRequestId(""); 
     263        copy.setRequestPath(""); 
     264        copy.setResponseBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"); 
     265        copy.setResourceHost("https://idp.cardiff.ac.uk/shibboleth"); 
     266        entry.setAssertionId(new String[]{"1"}); 
     267        entry.setEventId(100); 
     268        entry.setNameIdentifier("name1"); 
     269        PrincipalInformation principleCopy = new PrincipalInformation(principle); 
     270        entry.setPrincipalInformation(principleCopy); 
     271        entry.setResourceId("http://raptor.test"); 
     272         
     273        System.out.println("testShibConstructorCopyEquals:Shibboleth Event, First Instance has hash ["+entry.getHashCode()+"], " + 
     274                        "Copy has Hash ["+copy.getHashCode()+"], are equal ["+(entry.getHashCode()==copy.getHashCode())+"]"); 
     275 
     276        assertTrue(entry.getHashCode()==copy.getHashCode()); 
     277    } 
    154278 
    155279} 
Note: See TracChangeset for help on using the changeset viewer.