use of org.obiba.mica.security.event.SubjectAclUpdatedEvent in project mica2 by obiba.
the class SubjectAclService method removeSubjectPermission.
public void removeSubjectPermission(@NotNull SubjectAcl.Type type, @NotNull String principal, @NotNull String resource, @NotNull String action, @NotNull String instance) {
subjectAclRepository.findByPrincipalAndTypeAndResourceAndInstance(principal, type, resource, encode(instance)).forEach(acl -> {
if (acl.hasAction(action)) {
acl.removeAction(action);
if (acl.hasActions()) {
subjectAclRepository.save(acl);
} else {
subjectAclRepository.delete(acl);
}
}
});
// inform acls update (for caching)
eventBus.post(new SubjectAclUpdatedEvent(type.subjectFor(principal)));
}
use of org.obiba.mica.security.event.SubjectAclUpdatedEvent in project mica2 by obiba.
the class SubjectAclService method addSubjectPermission.
/**
* Add a permission for the subject principal on a given instance.
*
* @param type
* @param principal
* @param resource
* @param action
* @param instance
*/
public synchronized void addSubjectPermission(@NotNull SubjectAcl.Type type, @NotNull String principal, @NotNull String resource, @Nullable String action, @Nullable String instance) {
List<SubjectAcl> acls = subjectAclRepository.findByPrincipalAndTypeAndResourceAndInstance(principal, type, resource, encode(instance));
SubjectAcl acl;
if (acls == null || acls.isEmpty()) {
acl = SubjectAcl.newBuilder(principal, type).resource(resource).action(action).instance(encode(instance)).build();
} else {
acl = acls.get(0);
acl.removeActions();
acl.addAction(action);
}
subjectAclRepository.save(acl);
// inform acls update (for caching)
eventBus.post(new SubjectAclUpdatedEvent(type.subjectFor(principal)));
}
use of org.obiba.mica.security.event.SubjectAclUpdatedEvent in project mica2 by obiba.
the class SubjectAclService method removeSubjectPermissions.
/**
* Remove permissions for the subject principal on a given instance.
*
* @param type
* @param principal
* @param resource
* @param instance
*/
public void removeSubjectPermissions(@NotNull SubjectAcl.Type type, @NotNull String principal, @NotNull String resource, @Nullable String instance) {
subjectAclRepository.findByPrincipalAndTypeAndResourceAndInstance(principal, type, resource, encode(instance)).forEach(subjectAclRepository::delete);
// inform acls update (for caching)
eventBus.post(new SubjectAclUpdatedEvent(type.subjectFor(principal)));
}
Aggregations