Iterator<?> iter = getSecurityContext().getObjects(
new ClassObjectFilter(Role.class)).iterator();
boolean found = false;
while (iter.hasNext()) {
Role r = (Role) iter.next();
if (r.equals(role)) {
found = true;
break;
}
}
if (!found) {
getSecurityContext().insert(role);
}
}
for (Group group : identity.getGroups()) {
Iterator<?> iter = getSecurityContext().getObjects(
new ClassObjectFilter(Group.class)).iterator();
boolean found = false;
while (iter.hasNext()) {
Group g = (Group) iter.next();
if (g.equals(group)) {
found = true;
break;
}
}
if (!found) {
getSecurityContext().insert(group);
}
}
Iterator<?> iter = getSecurityContext().getObjects(
new ClassObjectFilter(Role.class)).iterator();
while (iter.hasNext()) {
Role r = (Role) iter.next();
if (!identity.hasRole(r.getRoleType().getName(),
r.getGroup().getName(), r.getGroup().getGroupType())) {
FactHandle fh = getSecurityContext().getFactHandle(r);
getSecurityContext().retract(fh);
}
}
}