A Maven package for AEM 6.2 that adds a render condition to check if a given user is in at least one of a list of groups before rendering a component.
- Download the package and unzip
- The project has 2 profiles that can be run like:
mvn -PautoInstallBundle install
– Installs only the base code, without examplesmvn -PautoInstallExample install
– Installs the base code and the examples
- /jcr:root/apps/gmrc/groupmember – jsp file to be referenced in Granite markup
- com.aem.community.gmrc.core.MemberOfRenderCondition – Java class containing code to test for the group membership, called from groupmember.jsp
- /jcr:root/apps/gmrc/example (example profile only)
- /jcr:root/content/gmrc (example profile only)
Use on any granite element that supports <renderconditions />:
+ mybutton
- sling:resourceType = "granite/ui/components/coral/foundation/button"
- text = "MyButton"
+ granite:rendercondition
- sling:resourceType = "gmrc/groupmember"
- groupID = "[group1,group2,group3]"
- declaredOnly=true|fasle (optional)"
- authorizableID="someID (optional)"
groupID allows for multiple groups to be tested for membership, which is essentially a shortcut for using built-in OR conditions with several of these render conditions, if you require a user to be members of multiple groups, use the built-in AND contitions.
- declaredOnly – “false”
- authorizableID – request.getRemoteUser()
(see http://localhost:4502/editor.html/content/gmrc.html to view this code live)
<column jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container">
<items jcr:primaryType="nt:unstructured">
<section
sling:resourceType="granite/ui/components/foundation/section">
<layout jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/layouts/well" />
<items jcr:primaryType="nt:unstructured">
<text cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/text"
text="this text will render for [everyone]. Render condition applied to containing granite/ui/components/foundation/section node.">
</text>
</items>
<rendercondition jcr:primaryType="nt:unstructured"
sling:resourceType="gmrc/groupmember"
declaredOnly="false"
groupID="[everyone]" />
</section>
<section2
sling:resourceType="granite/ui/components/foundation/section">
<layout jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/layouts/well" />
<items jcr:primaryType="nt:unstructured">
<text cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/text"
text="this text will render only for [administrators]. Render condition applied to this granite/ui/components/foundation/text node.">
<rendercondition jcr:primaryType="nt:unstructured"
sling:resourceType="gmrc/groupmember"
declaredOnly="false"
groupID="[administrators]" />
</text>
</items>
</section2>
<section3
sling:resourceType="granite/ui/components/foundation/section">
<layout jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/layouts/well" />
<items jcr:primaryType="nt:unstructured">
<text cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/text"
text="this text will render only for [somenonexistantgroup] (probably no one!)">
<rendercondition jcr:primaryType="nt:unstructured"
sling:resourceType="gmrc/groupmember"
declaredOnly="false"
groupID="[somenonexistantgroup]" />
</text>
</items>
</section3>
</items>
</column>
By Ben Stockwell – May 2016
This is released with absolutely no License, use at your own risk.