Last active
September 29, 2021 07:52
-
-
Save jpotts/a0e0ecbc9094d1ca0068 to your computer and use it in GitHub Desktop.
This is a custom Share evaluator that checks if the current user is a member of a group. The group to check is grabbed from a property on the node. The node is specified in the evaluator config. If you know the group to check at compile time, there is already an OOTB evaluator for that.
This file contains hidden or 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
import java.util.ArrayList; | |
p | |
import org.alfresco.web.evaluator.BaseEvaluator; | |
import org.alfresco.web.extensibility.SlingshotEvaluatorUtil; | |
import org.json.simple.JSONObject; | |
import org.springframework.extensions.surf.RequestContext; | |
import org.springframework.extensions.surf.support.ThreadLocalRequestContext; | |
public class MemberOfGroupFromProperty extends BaseEvaluator { | |
protected SlingshotEvaluatorUtil util = null; | |
private String accessor = null; | |
public void setSlingshotEvaluatorUtil(SlingshotEvaluatorUtil slingshotExtensibilityUtil) { | |
this.util = slingshotExtensibilityUtil; | |
} | |
@Override | |
public boolean evaluate(JSONObject jsonObject) { | |
if (accessor == null) { | |
return false; | |
} | |
// Assume that the property will hold a single group, could modify if your needs differ | |
String group = (String) getJSONValue(jsonObject, accessor); | |
ArrayList<String> groups = new ArrayList<String>(); | |
groups.add(group); | |
final RequestContext rc = ThreadLocalRequestContext.getRequestContext(); | |
return this.util.isMemberOfGroups(rc, groups, false); | |
} | |
/** | |
* Accessor for value to compare against in dot notation format, e.g. "custom.vtiServer" | |
* | |
* @param accessor | |
*/ | |
public void setAccessor(String accessor) { | |
this.accessor = accessor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, in the description you're talking about an OOTB evaluator for that if we know the group to check at compile time but I haven't find it. Could you please give me the name of that evaluator if you have it ?