Move authorization check to manager

This commit is contained in:
René Pfeuffer
2020-09-18 10:58:04 +02:00
parent 6d6a41372d
commit 69997a67cd
3 changed files with 10 additions and 17 deletions

View File

@@ -70,12 +70,10 @@ public class DefaultNamespaceManager implements NamespaceManager {
@Override
public void modify(Namespace namespace) {
NamespacePermissions.permissionWrite().check();
Namespace oldNamespace = get(namespace.getNamespace())
.orElseThrow(() -> notFound(entity(Namespace.class, namespace.getNamespace())));
fireEvent(HandlerEventType.BEFORE_MODIFY, namespace, oldNamespace);
if (!get(namespace.getNamespace()).isPresent()) {
throw notFound(entity("Namespace", namespace.getNamespace()));
}
dao.add(namespace);
fireEvent(HandlerEventType.MODIFY, namespace, oldNamespace);
}
@@ -101,9 +99,13 @@ public class DefaultNamespaceManager implements NamespaceManager {
}
private Namespace createNamespaceForName(String namespace) {
return dao.get(namespace)
.map(Namespace::clone)
.orElse(new Namespace(namespace));
if (NamespacePermissions.permissionRead().isPermitted()) {
return dao.get(namespace)
.map(Namespace::clone)
.orElse(new Namespace(namespace));
} else {
return new Namespace(namespace);
}
}
protected void fireEvent(HandlerEventType event, Namespace namespace, Namespace oldNamespace) {