[New] Added StrolchTransaction privilege methods
This commit is contained in:
parent
6bff9b144f
commit
33fe4ae603
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -131,6 +131,28 @@ public class PrivilegeContext {
|
|||
// business logic
|
||||
//
|
||||
|
||||
/**
|
||||
* <p>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.</p>
|
||||
*
|
||||
* <p>This method uses the {@link SimpleRestrictable} to verify access</p>
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* <p>This method uses the {@link SimpleRestrictable} to verify access</p>
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue