wiki:TechnicalInfo/Community/groupereventhandler
Last modified 7 years ago Last modified on 07/12/12 13:46:21

The following page describes the steps to include a new event handler for Grouper (not currently working, but hopefully not too far away...)

*Current progress is that our ICA and MUA are talking, the ICA is sending 236 records to the MUA. The MUA receives these entries but does not seem to be able to insert them into the newly (auto) created Grouper Authentication Event table in our database. *

Download the source from the repository,

svn checkout https://iam.cf.ac.uk/repos/RAPTOR/raptor-information-model/tags .

Add a grouper authentication event java file in the uk/ac/cardiff/model/event directory.

Grouper Authentication Event Java

 package uk.ac.cardiff.model.event;

import uk.ac.cardiff.utility.EqualsUtil;
import uk.ac.cardiff.utility.HashCodeUtil;
import uk.ac.cardiff.utility.StringUtils;

/**
 * The Class GrouperAuthenticationEvent.
 * 
 */
public class GrouperAuthenticationEvent extends AuthenticationEvent {

    /**
     * The name of a field not included in any of the superclasses and specific to this event.
     */
    private String groupAction;
    private String groupUser;

    /**
     * Instantiates a new Generic Authentication Event.
     */
    public GrouperAuthenticationEvent() {
        super();
    }

    /**
     * New instance.
     * 
     * @return the Grouper Authentication Event
     */
    public static GrouperAuthenticationEvent newInstance() {
        return new GrouperAuthenticationEvent();
    }

    /**
     * Copy constructor.
     * 
     * @param event
     *            the event to copy
     */
    protected GrouperAuthenticationEvent(GrouperAuthenticationEvent event) {
        super(event);
        groupAction = event.getGroupAction();
        groupUser = event.getGroupUser();

    }

    /**
     * Copy method. Alternative to clone. Returns a copied version of this event.
     * 
     * @return the Grouper Authentication Event
     */
    public GrouperAuthenticationEvent copy() {
        return new GrouperAuthenticationEvent(this);
    }

    /**
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if ((obj == null) || (obj.getClass() != this.getClass()))
            return false;
        GenericAuthenticationEvent that = (GenericAuthenticationEvent) obj;
        boolean areEqual = EqualsUtil.areEqual(this.getEventTimeMillis(), that.getEventTimeMillis()) && EqualsUtil.areEqual(this.getEventId(), that.getEventId())
                && EqualsUtil.areEqual(this.getAuthenticationType(), that.getAuthenticationType()) && EqualsUtil.areEqual(this.getServiceHost(), that.getServiceHost())
                && EqualsUtil.areEqual(this.getResourceHost(), that.getResourceHost()) && EqualsUtil.areEqual(this.getPrincipalName(), that.getPrincipalName())
                && EqualsUtil.areEqual(this.getServiceId(), that.getServiceId()) && EqualsUtil.areEqual(this.getEventType(), that.getEventType())
                && EqualsUtil.areEqual(this.getResourceId(), that.getResourceId()) &&
                // all new fields should be included in the quality method under here.
                EqualsUtil.areEqual(this.getGroupUser(), that.getGroupUser()) && EqualsUtil.areEqual(this.getGroupAction(), that.getGroupAction()); 

        return areEqual;
    }

    /**
     * For hibernate, so the hashcode can be persisted.
     * 
     * @return the hash code
     */
    public int getHashCode() {
        return hashCode();
    }

    /**
     * For hibernate, does nothing as the hascode is computed on the fly from the <code>hashCode</code> method.
     * 
     * @param hashCode
     *            the new hash code
     */
    public void setHashCode(int hashCode) {

    }

    /**
     * create a unique hash, with as uniform a distribution as possible.
     * 
     * @return the int
     */
    @Override
    public int hashCode() {
        int hash = HashCodeUtil.SEED;
        // all inherited fields are hashed here.
        hash = HashCodeUtil.hash(hash, getEventTimeMillis());
        hash = HashCodeUtil.hash(hash, getAuthenticationType());
        hash = HashCodeUtil.hash(hash, getEventId());
        hash = HashCodeUtil.hash(hash, getServiceHost());
        hash = HashCodeUtil.hash(hash, getResourceHost());
        hash = HashCodeUtil.hash(hash, getPrincipalName());
        hash = HashCodeUtil.hash(hash, getEventType());
        hash = HashCodeUtil.hash(hash, getServiceId());
        hash = HashCodeUtil.hash(hash, getResourceId());
        // all new fields part of the business key should be hashed below.
        hash = HashCodeUtil.hash(hash, getGroupAction());
        hash = HashCodeUtil.hash(hash, getGroupUser());
        

        return hash;

    }

    /**
     * Automatic construction of a basic to string method for this class using reflection. Does not require modification unless different behavior is desired.
     */
    public String toString() {
        return StringUtils.buildToString(this);
    }

    /**
     * @param groupUser
     *            the groupUser to set
     */
    public void setGroupUser(String groupUser) {
        this.groupUser = groupUser;
    }

    /**
     * @return the groupUser
     */
    public String getGroupUser() {
        return groupUser;
    }
    
      /**
     * @param groupAction
     *            the groupAction to set
     */
    public void setGroupAction(String groupAction) {
        this.groupAction = groupAction;
    }

    /**
     * @return the groupUser
     */
    public String getGroupAction() {
        return groupAction;
    }

}

event.hbm.xml

Added the new fields to the hbm file as below.

<union-subclass  extends="uk.ac.cardiff.model.event.AuthenticationEvent"
	name="uk.ac.cardiff.model.event.GrouperAuthenticationEvent">

		<property name="groupUser" column="groupUser" type="string" />
		<property name="groupAction" column="groupAction" type="string" />
		<property name="hashCode" column="current_hashCode" type="integer"
			index="hashcode_i" />

	</union-subclass>

Once you've done this, then you need to rebuild the package.

mvn clean package

Will create a new raptor-information-model-1.0.1.jar file in the target directory. This will include the new class you have created along side the database configuration. This jar file should then be copied to the lib directory of both the ICA and the MUA.

ICA Configuration

After putting the new information model jar in place, we configure event-parse-formats-custom.xml to pick up the appropriate grouper entries. The amended ICA config files are included in the attachments section on this page.

MUA Configuration

Similar to the ICA, we have configured the mua to recognise the new grouper authentication event class.

Attachments