1
votes

I am using Grails : 2.3.5 and Spring Security Core plugin : 1.2.7.3

In Grails Spring Security RequestMap is a separate table but in my application I want to use the requestMap concept with the existing table.

I have a RolePermissionMap table is there and I want to use this table for the RequestMap.

class Role{
    Long id
    String name
    String description
}

class Permission{
    Long id
    String name
    String description
    String requestUrl
}

class RolePermissionMap {
    Long id
    Role role
    Permission permission
}

Now I am overriding the loadRequestmaps() method by extending the RequestmapFilterInvocationDefinition class like below

class RolePermissionMapFilterInvocation extends RequestmapFilterInvocationDefinition {

    @Override
    protected Map<String, String> loadRequestmaps() {
        Map<String, String> data = new HashMap<String, String>();

        for (Object requestmap : ReflectionUtils.loadAllRequestmaps()) {

            // Original code
            //String urlPattern = ReflectionUtils.getRequestmapUrl(requestmap);
            //String configAttribute = ReflectionUtils.getRequestmapConfigAttribute(requestmap);
            //data.put(urlPattern, configAttribute); 

            // modified code
            Permission permission = ReflectionUtils.getRequestmapUrl(requestmap);
            Role role = ReflectionUtils.getRequestmapConfigAttribute(requestmap);
            data.put(permission.getRequestUrl(), role.getName());
        }

        return data;
    }
}

Then I will add this bean in resources.groovy

beans = {
     objectDefinitionSource(RolePermissionMapFilterInvocation)
} 

I am also trying to override the ReflectionUtils class also for getting the return types of getRequestmapUrl(requestmap) and getRequestmapConfigAttribute() methods also as required

When I run with this approach am getting exception below

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectDefinitionSource': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: url matcher is required

for resolving the url matcher I added a bean in resources.groovy but it failed

Do I need to create a bean with urlMaper or need to mention ReflectionUtils class any where ?

Please show me a way.. Thanks in Advance

1

1 Answers

1
votes

The plugin expects the url field in your request map class to be a String, in order to use a different type you'd have to subclass RequestMapFilterInvocationDefinition to extract the URL patterns correctly, and install your custom class as the bean named objectDefinitionSource in your app's resources.groovy to replace the default bean definition supplied by SpringSecurityCoreGrailsPlugin.groovy in its doWithSpring.