UserManager userManager = AccessControlUtil.getUserManager(session);
Authorizable authorizable = userManager.getAuthorizable(name);
if (authorizable == null) {
//principal does not exist yet, so create it
Group group = userManager.createGroup(new Principal() {
public String getName() {
return name;
}
},
hashPath(name)
);
authorizable = group;
} else {
//principal already exists, check to make sure it is the expected type
if (!authorizable.isGroup()) {
throw new RepositoryException("A user already exists with the requested name: " + name);
}
//group already exists so just update it below
}
//update the group members
if (members != null) {
Group group = (Group) authorizable;
for (String member : members) {
Authorizable memberAuthorizable = userManager.getAuthorizable(member);
if (memberAuthorizable != null) {
group.addMember(memberAuthorizable);
}
}
}
if (extraProperties != null) {
ValueFactory valueFactory = session.getValueFactory();