Thursday, November 29, 2012

Adding custom permissions in Alfresco

If your extending the PermssionModel of Alfresco, you might get an Exception when using the new permission groups .. like:

...
Caused by: java.lang.NullPointerException
    at org.alfresco.repo.site.RoleComparatorImpl.compare(RoleComparatorImpl.java:39)
    at org.alfresco.repo.site.RoleComparatorImpl.compare(RoleComparatorImpl.java:24)
    at java.util.TreeMap.put(TreeMap.java:530)
    at java.util.TreeSet.add(TreeSet.java:238)
    at org.alfresco.repo.site.SiteServiceImpl.getMembersRole(SiteServiceImpl.java:1717)

...

This is caused by this RoleComparator not knowing the groups. This can be resolved by some spring magic:

 <!-- adds to script-services-context.xml -->
    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" depends-on="siteRoleComparator">
        <property name="targetObject">
            <util:property-path path="siteRoleComparator.RolePrecedence" />
        </property>
        <property name="targetMethod" value="putAll" />
        <property name="arguments">
            <list>
                <map key-type="java.lang.String" value-type="java.lang.Integer">
                   <entry key="User" value="10" />
                </map>
            </list>
        </property>
    </bean>


This is an addition to the guides http://keytocontent.blogspot.dk/2011/04/alfresco-share-permissionsroles-part-ii.html and https://wiki.alfresco.com/wiki/Custom_Permissions_in_Share