-
Jun 20th, 2012, 12:14 PM
#1
Configure "global-method-security" programmatically in WebMvcConfigurationSupport?
In my spring application, I have 2 contexts:
* root "applicationContext", which is defined in an XML file.
* MVC "servlet" application context, which is defined programmatically.
I have to define the servlet context programmatically in order to set some Spring core parameters that are not exposed to the XML configuration. However, I now want to add method security via @PreAuthorize annotations.
I'm not sure how to do this. With the Spring core values, it's fairly easy to find them, starting by looking at the
WebMvcConfigurationSupport API.
Does anyone know how to add <global-method-security> support to by @Configuration class?:
@Configuration
@ComponentScan(basePackages={"com.myapp"})
public class MyConfiguration extends WebMvcConfigurationSupport {
// How to add <global-method-security> support???
}
-
Jun 20th, 2012, 02:19 PM
#2
This question has been answered before so please use the forum search. In short take a look at the GlobalMethodSecurityBeanDefinitionParser as that contains the beans that need to be configured. However why not simply use xml for this and use @ImportResource to configure this part (Spring Security currently hasn't any Java Config support like the Spring Framework has).
-
Jun 20th, 2012, 02:31 PM
#3
I had searched the forum but didn't find anything that answered my specific question.
And I had looked at GlobalMethodSecurityBeanDefinitionParser, but to work with it, it seemed complicated -- and I was hoping there was another way to configure it that I had missed.
I was actually just starting down the path of trying to configure the "security" elements in a separate file.
Thanks!
-
Jun 21st, 2012, 01:11 AM
#4
The GlobalMethodSecurityBeanDefinitionParser is the class that contains the beans that are registered you cannot use that bean directly from java config you would have to extract from that class the beans you need to configure.
However for easy of configuration I would simply add an xml and use the namespace to configure security.
-
Jun 21st, 2012, 10:02 AM
#5
Thanks. I have it all working now using @ImportResource(value={"security.xml"}) on my Configuration class.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules