Skip to content

Instantly share code, notes, and snippets.

@rickx1
Last active October 23, 2017 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickx1/069179d79872f7d7c6a89f2ba69241a3 to your computer and use it in GitHub Desktop.
Save rickx1/069179d79872f7d7c6a89f2ba69241a3 to your computer and use it in GitHub Desktop.
Code of a ChangePreprocessor implementing a security proxy based security scheme.
public class UpdateSecurityProxy implements ChangePreprocessor {
@Override
public boolean preprocessObjectChange(IndependentlyPersistableObject object)
throws EngineRuntimeException {
Property department = getDepartment(object);
if (department != null && department.isDirty()) {
updateSecurityProxy(object, department.getStringValue() );
return true;
}
return false;
}
private void updateSecurityProxy(IndependentlyPersistableObject object,
String departmentName ) {
ObjectStore objectStore = ((RepositoryObject) object).getObjectStore();
CustomObject departmentAccess = getDepartmentAccess(departmentName,objectStore);
object.getProperties().putValue("DepartmentAccess", departmentAccess);
}
private Property getDepartment(IndependentlyPersistableObject object) {
Properties properties = object.getProperties();
if (properties.isPropertyPresent("Department")) {
return properties.get("Department");
}
return null;
}
private CustomObject getDepartmentAccess(String department,
ObjectStore objectStore) {
IndependentObjectSet objects = searchDepartmentAccess(department, objectStore);
if (!objects.isEmpty()) {
return (CustomObject) objects.iterator().next();
} else {
throw new RuntimeException("Department '" + department + "' was not found!");
}
}
private IndependentObjectSet searchDepartmentAccess(String department,
ObjectStore objectStore) {
SearchScope searchScope = new SearchScope(objectStore);
String queryString = "SELECT This " +
"FROM DepartmentAccess " +
"WHERE Department = " +
"'" + department + "'";
SearchSQL searchSql = new SearchSQL(queryString);
IndependentObjectSet objects = searchScope.fetchObjects(searchSql, null, null, null);
return objects;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment