mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
Bug 4933: added method
setOwnershipWithoutCheckPermissionForObjectCreationAndRevertOnError that allows to set t he ownership and revert on error for creating an object without checking SERVER:CREATE_OBJECT
This commit is contained in:
1 parent
f260d81b75
commit
5a43660474
3 files changed
+36
No files matched your search
@@ -1667,6 +1667,33 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T setOwnershipWithoutCheckPermissionForObjectCreationAndRevertOnError(HasPermissions type,
|
||||
TypeRelativeObjectIdentifier typeIdentifier, String securityDisplayName, Callable<T> actionWithResult) {
|
||||
QualifiedObjectIdentifier identifier = type.getQualifiedObjectIdentifier(typeIdentifier);
|
||||
T result = null;
|
||||
boolean didSetOwnership = false;
|
||||
try {
|
||||
final OwnershipAnnotation preexistingOwnership = getOwnership(identifier);
|
||||
if (preexistingOwnership == null) {
|
||||
didSetOwnership = true;
|
||||
setDefaultOwnership(identifier, securityDisplayName);
|
||||
} else {
|
||||
logger.fine("Preexisting ownership found for " + identifier + ": " + preexistingOwnership);
|
||||
}
|
||||
SecurityUtils.getSubject().checkPermission(identifier.getStringPermission(DefaultActions.CREATE));
|
||||
result = actionWithResult.call();
|
||||
} catch (AuthorizationException e) {
|
||||
if (didSetOwnership) {
|
||||
deleteOwnership(identifier);
|
||||
}
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultOwnership(QualifiedObjectIdentifier identifier, String description) {
|
||||
setOwnership(identifier, getCurrentUser(), getDefaultTenantForCurrentUser(), description);
|
||||
|
||||
Reference in new issue
Block a user