void setPrincipal(NodeImpl node, Principal principal) throws AuthorizableExistsException, RepositoryException {
if (!isValidPrincipal(principal)) {
throw new IllegalArgumentException("Cannot create Authorizable: Principal may not be null and must have a valid name.");
}
if (getAuthorizable(principal) != null) {
throw new AuthorizableExistsException("Authorizable for '" + principal.getName() + "' already exists: ");
}
if (!node.isNew() || node.hasProperty(P_PRINCIPAL_NAME)) {
throw new RepositoryException("rep:principalName can only be set once on a new node.");
}
setProperty(node, P_PRINCIPAL_NAME, getValue(principal.getName()), true);