use of org.alfresco.repo.security.permissions.impl.SimplePermissionReference in project alfresco-repository by Alfresco.
the class AclCrudDAOTest method testCreatePermissionWithRollback.
public void testCreatePermissionWithRollback() throws Exception {
String name = getName() + "-" + System.currentTimeMillis();
final SimplePermissionReference permRef = SimplePermissionReference.getPermissionReference(QName.createQName("cm:cmobject"), name);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
createPermission(permRef);
// Now force a rollback
throw new RuntimeException("Forced");
}
};
try {
txnHelper.doInTransaction(callback);
fail("Transaction didn't roll back");
} catch (RuntimeException e) {
// Expected
}
// Check that it doesn't exist
assertNull(getPermission(permRef));
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionReference in project alfresco-repository by Alfresco.
the class AclDAOImpl method getAccessControlList.
/**
* {@inheritDoc}
*/
@Override
public AccessControlList getAccessControlList(Long id) {
// Used the cached properties as our cache key
AccessControlListProperties properties = getAccessControlListProperties(id);
if (properties == null) {
return null;
}
AccessControlList aclCached = aclCache.get((Serializable) properties);
if (aclCached != null) {
return aclCached;
}
SimpleAccessControlList acl = new SimpleAccessControlList();
acl.setProperties(properties);
List<Map<String, Object>> results = aclCrudDAO.getAcesAndAuthoritiesByAcl(id);
List<AccessControlEntry> entries = new ArrayList<AccessControlEntry>(results.size());
for (Map<String, Object> result : results) // for (AclMemberEntity member : members)
{
Boolean aceIsAllowed = (Boolean) result.get("allowed");
Integer aceType = (Integer) result.get("applies");
String authority = (String) result.get("authority");
Long permissionId = (Long) result.get("permissionId");
Integer position = (Integer) result.get("pos");
// Long result_aclmemId = (Long) result.get("aclmemId"); // not used here
SimpleAccessControlEntry sacEntry = new SimpleAccessControlEntry();
sacEntry.setAccessStatus(aceIsAllowed ? AccessStatus.ALLOWED : AccessStatus.DENIED);
sacEntry.setAceType(ACEType.getACETypeFromId(aceType));
sacEntry.setAuthority(authority);
// if (entry.getContext() != null)
// {
// SimpleAccessControlEntryContext context = new SimpleAccessControlEntryContext();
// context.setClassContext(entry.getContext().getClassContext());
// context.setKVPContext(entry.getContext().getKvpContext());
// context.setPropertyContext(entry.getContext().getPropertyContext());
// sacEntry.setContext(context);
// }
Permission perm = aclCrudDAO.getPermission(permissionId);
// Has an ID so must exist
QName permTypeQName = qnameDAO.getQName(perm.getTypeQNameId()).getSecond();
SimplePermissionReference permissionRefernce = SimplePermissionReference.getPermissionReference(permTypeQName, perm.getName());
sacEntry.setPermission(permissionRefernce);
sacEntry.setPosition(position);
entries.add(sacEntry);
}
Collections.sort(entries);
acl.setEntries(entries);
// Cache it for next time
aclCache.put((Serializable) properties, acl);
return acl;
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionReference in project alfresco-repository by Alfresco.
the class AbstractAclCrudDAOImpl method renamePermission.
public void renamePermission(QName oldTypeQName, String oldName, QName newTypeQName, String newName) {
ParameterCheck.mandatory("oldTypeQName", oldTypeQName);
ParameterCheck.mandatory("oldName", oldName);
ParameterCheck.mandatory("newTypeQName", newTypeQName);
ParameterCheck.mandatory("newName", newName);
if (oldTypeQName.equals(newTypeQName) && oldName.equals(newName)) {
throw new IllegalArgumentException("Cannot move permission to itself: " + oldTypeQName + "-" + oldName);
}
SimplePermissionReference oldPermRef = SimplePermissionReference.getPermissionReference(oldTypeQName, oldName);
PermissionEntity permission = getPermissionForUpdate(oldPermRef);
if (permission != null) {
Long newTypeQNameId = qnameDAO.getOrCreateQName(newTypeQName).getFirst();
permission.setTypeQNameId(newTypeQNameId);
permission.setName(newName);
int updated = permissionEntityCache.updateValue(permission.getId(), permission);
if (updated < 1) {
aclEntityCache.removeByKey(permission.getId());
throw new ConcurrencyFailureException("PermissionEntity with ID (" + permission.getId() + ") no longer exists or has been updated concurrently");
}
}
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionReference in project alfresco-repository by Alfresco.
the class AbstractPermissionChangePatch method renamePermission.
/**
* Helper method to rename (move) a permission. This involves checking for the existence of the
* new permission and then moving all the entries to point to the new permission.
*
* @param oldTypeQName the old permission type
* @param oldName the old permission name
* @param newTypeQName the new permission type
* @param newName the new permission name
* @return Returns the number of permission entries modified
*/
protected int renamePermission(QName oldTypeQName, String oldName, QName newTypeQName, String newName) {
if (oldTypeQName.equals(newTypeQName) && oldName.equals(newName)) {
throw new IllegalArgumentException("Cannot move permission to itself: " + oldTypeQName + "-" + oldName);
}
SimplePermissionReference oldPermRef = SimplePermissionReference.getPermissionReference(oldTypeQName, oldName);
Permission permission = aclCrudDAO.getPermission(oldPermRef);
if (permission == null) {
// create the permission
SimplePermissionReference newPermRef = SimplePermissionReference.getPermissionReference(newTypeQName, newName);
aclCrudDAO.createPermission(newPermRef);
} else {
// rename the permission
aclCrudDAO.renamePermission(oldTypeQName, oldName, newTypeQName, newName);
}
// done
return 1;
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionReference in project alfresco-repository by Alfresco.
the class AclDAOImpl method disableInheritanceImpl.
private List<AclChange> disableInheritanceImpl(Long id, boolean setInheritedOnAcl, AclEntity aclIn) {
List<AclChange> changes = new ArrayList<AclChange>();
if (!aclIn.getInherits()) {
return Collections.<AclChange>emptyList();
}
// Manages caching
getWritable(id, null, null, null, null, false, changes, WriteMode.COPY_ONLY);
AclUpdateEntity acl = aclCrudDAO.getAclForUpdate(changes.get(0).getAfter());
final Long inheritsFrom = acl.getInheritsFrom();
acl.setInherits(Boolean.FALSE);
acl.setAclChangeSetId(getCurrentChangeSetId());
aclCrudDAO.updateAcl(acl);
// Keep inherits from so we can reinstate if required
// acl.setInheritsFrom(-1l);
// Manages caching
getWritable(acl.getId(), null, null, null, null, true, changes, WriteMode.TRUNCATE_INHERITED);
if ((inheritsFrom != null) && (inheritsFrom != -1) && setInheritedOnAcl) {
// get aces for acl (via acl member)
List<AclMember> members = aclCrudDAO.getAclMembersByAcl(inheritsFrom);
for (AclMember member : members) {
// TODO optimise
Ace ace = aclCrudDAO.getAce(member.getAceId());
Authority authority = aclCrudDAO.getAuthority(ace.getAuthorityId());
SimpleAccessControlEntry entry = new SimpleAccessControlEntry();
entry.setAccessStatus(ace.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED);
entry.setAceType(ace.getAceType());
entry.setAuthority(authority.getAuthority());
/* NOTE: currently unused - intended for possible future enhancement
if (ace.getContextId() != null)
{
AceContext aceContext = aclCrudDAO.getAceContext(ace.getContextId());
SimpleAccessControlEntryContext context = new SimpleAccessControlEntryContext();
context.setClassContext(aceContext.getClassContext());
context.setKVPContext(aceContext.getKvpContext());
context.setPropertyContext(aceContext.getPropertyContext());
entry.setContext(context);
}
*/
Permission perm = aclCrudDAO.getPermission(ace.getPermissionId());
// Has an ID so must exist
QName permTypeQName = qnameDAO.getQName(perm.getTypeQNameId()).getSecond();
SimplePermissionReference permissionRefernce = SimplePermissionReference.getPermissionReference(permTypeQName, perm.getName());
entry.setPermission(permissionRefernce);
entry.setPosition(Integer.valueOf(0));
setAccessControlEntry(id, entry);
}
}
return changes;
}
Aggregations