Skip to content

Instantly share code, notes, and snippets.

@jpotts
Last active September 29, 2021 07:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpotts/a0e0ecbc9094d1ca0068 to your computer and use it in GitHub Desktop.
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.
<beans>
<bean id="someco.evaluator.groupMembershipProperty" class="com.someco.web.evaluator.MemberOfGroupFromProperty">
<property name="slingshotEvaluatorUtil" ref="slingshot.evaluator.utility" />
</bean>
<bean id="someco.evaluator.approvalGroup" parent="someco.evaluator.groupMembershipProperty">
<property name="accessor" value="node.properties.sc:approvalGroup" />
</bean>
</beans>
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;
}
}
@Jod21
Copy link

Jod21 commented Sep 29, 2021

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment