Extending SpEL with native methods in Grails?

I would like to add custom SpEL methods in the Grails application, as is done for the regular Spring-Security application in this question by overriding the EvaluationContext . Will this work?

How to connect global-method-security to global-method-security settings? I can configure security , but what to add there? Sort of

 grails.plugins.springsecurity = { 'global-method-security' { 'expression-handler' { ref("myMethodSecurityExpressionHandler") } } } 

? But what code will this interpret?

A look at SpringSecurityCoreGrailsPlugin.groovy also gives me no information.

+3
source share
1 answer

This is only available if you have the spring-security-acl plugin installed. It sets up the expressionHandler bean:

 expressionHandler(DefaultMethodSecurityExpressionHandler) { parameterNameDiscoverer = ref('parameterNameDiscoverer') permissionEvaluator = ref('permissionEvaluator') roleHierarchy = ref('roleHierarchy') trustResolver = ref('authenticationTrustResolver') } 

So, if you have your own subclass of DefaultMethodSecurityExpressionHandler , you can replace the bean with resources.groovy as follows:

 import com.mycompany.myapp.MyMethodSecurityExpressionHandler beans = { expressionHandler(MyMethodSecurityExpressionHandler) { parameterNameDiscoverer = ref('parameterNameDiscoverer') permissionEvaluator = ref('permissionEvaluator') roleHierarchy = ref('roleHierarchy') trustResolver = ref('authenticationTrustResolver') } } 
+2
source

Source: https://habr.com/ru/post/1492726/


All Articles