Results 1 to 5 of 5

Thread: Configure "global-method-security" programmatically in WebMvcConfigurationSupport?

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Question 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???

    }

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jun 2012
    Posts
    3

    Default

    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!

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jun 2012
    Posts
    3

    Default

    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
  •