public void addMember(Principal principal) { // Add the principal as member in this principal if it isn't // already a member. if (findMemberRelationshipTo(principal) != null) { return; } principal .getUnderlyingNode() .createRelationshipTo(getUnderlyingNode(), SecurityRelationshipTypes.MEMBER); principal.deleteRootRelIfAny(); }
private Relationship findMemberRelationshipTo(Principal principal) { for (Relationship rel : principal .getUnderlyingNode() .getRelationships(SecurityRelationshipTypes.MEMBER, Direction.OUTGOING)) { if (rel.getEndNode().equals(getUnderlyingNode())) { return rel; } } return null; }
public void removeMember(Principal principal) { Relationship rel = findMemberRelationshipTo(principal); if (rel == null) { throw new IllegalArgumentException(principal + " not a member of " + this); } rel.delete(); if (!principal.getMemberships().iterator().hasNext()) { getGraphDb() .getReferenceNode() .createRelationshipTo(principal.getUnderlyingNode(), SecurityRelationshipTypes.PRINCIPAL); } }