package org.neo4j.tutor.security;

import org.neo4j.api.core.Node;
import org.neo4j.api.core.RelationshipType;
import org.neo4j.impl.event.Event;
import org.neo4j.impl.event.EventData;

public class SecurityMgr3 extends AbstractSecurityMgr
{
	private static final RelationshipType ACCESS = MyRelationshipTypes.ACCESS;
	private static final RelationshipType MEMBER_OF = 
		MyRelationshipTypes.MEMBER_OF;
	
	public boolean proActiveEventReceived( Event event, EventData data )
	{
		if ( event == SecurityEvent.ACCESS )
		{
			Node file = (Node) data.getData();
			final Node user = AuthorizationService.getCurrentUser();
			// --- TODO
			// --- Access granted by outgoing ACCESS relationship to a user or a
			// --- group that user is member of via the MEMBER_OF relationship
			// --- If no ACCESS relationship exist access is granted
			// --- else if no user registered (null user), access is denied
			// --- else create a traverser that traverses ACCESS relationship
			// --- and MEMBER_OF relationship, if user node is found 
			// --- return true
		}
		// we shouldn't get any other events but returning true by default 
		return true;
	}
}
