return permissibleObjects;
}
public void setPermissions(PermissibleObject permissibleObject, List<Permission> permissions) throws SimpleMessageException {
if (permissibleObject == null) {
throw new SimpleMessageException("PermissibleObject not supplied.");
}
if (permissions == null) {
throw new SimpleMessageException("Permissions not supplied.");
}
User authUser = getAuthenticatedUser(session.get());
if (authUser == null) {
throw new SimpleMessageException("User is not authenticated.");
}
Transaction tx = session.get().beginTransaction();
try {
PermissibleObject hibPermissibleObject = ((PermissibleObject) session.get().load(PermissibleObject.class, permissibleObject.getId()));
if (!authUser.isAdministrator() && !hibPermissibleObject.getOwner().equals(authUser)) {
throw new SimpleMessageException("User is not authorized to set permissions on this object.");
}
session.get().evict(authUser);
SecurityHelper.deletePermissions(session.get(), permissibleObject);
for (Permission permission : permissions) {
session.get().save(permission);
}
List<Field> fields = ReflectionCache.getFields(permissibleObject.getClass());
for (Field field : fields) {
try {
// do not update parent permission only our 'owned' objects
if (!"parent".equals(field.getName())) {
Object obj = field.get(permissibleObject);
if (obj instanceof PermissibleObject) {
PermissibleObject childObj = (PermissibleObject) obj;
childObj.setGlobalRead(permissibleObject.isGlobalRead());
childObj.setGlobalWrite(permissibleObject.isGlobalWrite());
childObj.setGlobalExecute(permissibleObject.isGlobalExecute());
childObj.setGlobalCreateChild(permissibleObject.isGlobalCreateChild());
SecurityHelper.deletePermissions(session.get(), childObj);
for (Permission permission : permissions) {
Permission newPerm = new Permission();
newPerm.setPermissibleObject(childObj);
newPerm.setSecurityPrincipal(permission.getSecurityPrincipal());
newPerm.setReadPerm(permission.isReadPerm());
newPerm.setWritePerm(permission.isWritePerm());
newPerm.setExecutePerm(permission.isExecutePerm());
newPerm.setCreateChildPerm(permission.isCreateChildPerm());
session.get().save(newPerm);
}
}
}
} catch (Exception e) {
Logger.log(e);
}
}
tx.commit();
} catch (Throwable t) {
Logger.log(t);
try {
tx.rollback();
} catch (Throwable tt) {
}
throw new SimpleMessageException(t.getMessage());
}
}