From b6a04c19b213f2dc5d8a09f1ee64c6c876cf0087 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Thu, 14 Dec 2023 14:33:10 +0100 Subject: [PATCH] refact: removed not needed type constructor from NamedAccessObject, reuse it for IndividualAccessObject --- .../auth/objects/IndividualAccessObject.java | 17 ++--------------- .../webapp/auth/objects/NamedAccessObject.java | 10 +--------- .../auth/permissions/SimplePermission.java | 2 +- .../controller/freemarker/PageController.java | 2 +- 4 files changed, 5 insertions(+), 26 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/IndividualAccessObject.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/IndividualAccessObject.java index c67fe78f61..c68ee43776 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/IndividualAccessObject.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/IndividualAccessObject.java @@ -1,28 +1,15 @@ package edu.cornell.mannlib.vitro.webapp.auth.objects; -import java.util.Optional; - import edu.cornell.mannlib.vitro.webapp.auth.attributes.AccessObjectType; -public class IndividualAccessObject extends AccessObject { - - private final String uri; +public class IndividualAccessObject extends NamedAccessObject { public IndividualAccessObject(String uri) { - this.uri = uri; + super(uri); } @Override public AccessObjectType getType() { return AccessObjectType.INDIVIDUAL; } - - @Override - public Optional getUri() { - if (uri == null) { - return Optional.empty(); - } - return Optional.of(uri); - } - } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/NamedAccessObject.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/NamedAccessObject.java index 8b9f025ac9..f3a3eecfde 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/NamedAccessObject.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/objects/NamedAccessObject.java @@ -11,21 +11,13 @@ */ public class NamedAccessObject extends AccessObject { private final String uri; - private AccessObjectType type; public NamedAccessObject() { this.uri = ""; - this.type = AccessObjectType.NAMED_OBJECT; - } - - public NamedAccessObject(String uri, AccessObjectType type) { - this.uri = uri; - this.type = type; } public NamedAccessObject(String uri) { this.uri = uri; - this.type = AccessObjectType.NAMED_OBJECT; } @Override @@ -61,7 +53,7 @@ public String toString() { @Override public AccessObjectType getType() { - return type; + return AccessObjectType.NAMED_OBJECT; } private static String getShortName(String entityUri) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java index 3cfbc4a3e1..a86036dd1e 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java @@ -75,7 +75,7 @@ public String getUri() { private SimplePermission(String uri) { this.uri = SimplePermission.NS + uri; - NamedAccessObject ao = new NamedAccessObject(this.uri, AccessObjectType.NAMED_OBJECT); + NamedAccessObject ao = new NamedAccessObject(this.uri); this.ACTION = new SimpleAuthorizationRequest(ao, AccessOperation.EXECUTE); } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java index a5e2a99829..f27c07aa90 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java @@ -73,7 +73,7 @@ private AuthorizationRequest getActionsForPage( VitroRequest vreq ) throws Excep if (StringUtils.isBlank(uri)) { continue; } - NamedAccessObject ao = new NamedAccessObject(uri, AccessObjectType.NAMED_OBJECT); + NamedAccessObject ao = new NamedAccessObject(uri); auth = auth.and( new SimpleAuthorizationRequest(ao, AccessOperation.EXECUTE)); } return auth;