Last active
October 23, 2017 18:55
-
-
Save rickx1/069179d79872f7d7c6a89f2ba69241a3 to your computer and use it in GitHub Desktop.
Code of a ChangePreprocessor implementing a security proxy based security scheme.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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