diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java index 10b28db07..21a76fdf0 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java @@ -1173,6 +1173,20 @@ public abstract class AbstractTransaction implements StrolchTransaction { .validateAction(new TransactedRestrictable(this, operation.getPrivilegeName(element), element)); } + @Override + public void assertHasPrivilege(String privilegeName, String privilegeValue) throws AccessDeniedException { + DBC.PRE.assertNotEmpty("privilegeName must not be empty", privilegeValue); + DBC.PRE.assertNotEmpty("privilegeValue must not be empty", privilegeValue); + getPrivilegeContext().validateAction(privilegeName, privilegeValue); + } + + @Override + public boolean hasPrivilege(String privilegeName, String privilegeValue) throws AccessDeniedException { + DBC.PRE.assertNotEmpty("privilegeName must not be empty", privilegeValue); + DBC.PRE.assertNotEmpty("privilegeValue must not be empty", privilegeValue); + return getPrivilegeContext().hasPrivilege(privilegeName, privilegeValue); + } + @Override public void assertHasRole(String roleName) throws AccessDeniedException { DBC.PRE.assertNotNull("roleName must not be null", roleName); diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java index a26bd28ca..b86ccc054 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java @@ -1722,6 +1722,16 @@ public interface StrolchTransaction extends AutoCloseable { */ void assertHasPrivilege(Operation operation, StrolchRootElement element) throws AccessDeniedException; + /** + * @see PrivilegeContext#validateAction(String, String) + */ + void assertHasPrivilege(String privilegeName, String privilegeValue) throws AccessDeniedException; + + /** + * @see PrivilegeContext#hasPrivilege(Restrictable) + */ + boolean hasPrivilege(String privilegeName, String privilegeValue) throws AccessDeniedException; + /** * Asserts that the current {@link Certificate} has the given role * diff --git a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/PrivilegeContext.java b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/PrivilegeContext.java index d62e117ba..4c7841ebd 100644 --- a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/PrivilegeContext.java +++ b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/PrivilegeContext.java @@ -131,6 +131,28 @@ public class PrivilegeContext { // business logic // + /** + *

Validates if the user for this context has the Privilege with the given name, and is allowed access to the + * given value. If the user has the privilege, then this method returns with no exception and void, if the user does + * not have the privilege, then a {@link AccessDeniedException} is thrown.

+ * + *

This method uses the {@link SimpleRestrictable} to verify access

+ * + * @param privilegeName + * the name of the privilege to verify + * @param privilegeValue + * the value + * + * @throws AccessDeniedException + * if the user does not have access + * @throws PrivilegeException + * if there is an internal error due to wrongly configured privileges or programming errors + */ + public void validateAction(String privilegeName, String privilegeValue) + throws PrivilegeException, AccessDeniedException { + validateAction(new SimpleRestrictable(privilegeName, privilegeValue)); + } + /** * Validates if the user for this context has the privilege to access to the given {@link Restrictable}. If the user * has the privilege, then this method returns with no exception and void, if the user does not have the privilege, @@ -192,4 +214,24 @@ public class PrivilegeContext { // delegate to the policy return policy.hasPrivilege(this, privilege, restrictable); } + + /** + * Validates if the user for this context has the privilege to access to the given {@link Restrictable}. Returning + * true if the user has the privilege, and false if not + * + *

This method uses the {@link SimpleRestrictable} to verify access

+ * + * @param privilegeName + * the name of the privilege to verify + * @param privilegeValue + * the value + * + * @return returns true if the user has the privilege, and false if not + * + * @throws PrivilegeException + * if there is an internal error due to wrongly configured privileges or programming errors + */ + public boolean hasPrivilege(String privilegeName, String privilegeValue) throws PrivilegeException { + return hasPrivilege(new SimpleRestrictable(privilegeName, privilegeValue)); + } }