Home  >  Forum  >  Spring
Post New Query

Spring method level security not working


joined on
May 16,2015
Asked on May 20,2015
Hi,

I am developing spring security application in which I am using method level security using annotation.  Methods are

@Secured("authenticated")
public void method1();
   
@PreAuthorize("hasRole('ADMIN')")
public void method2();


While I run my application, they are not working.

joined on
October 10,2013
Replied on May 20,2015

You need to check for global method security configuration.
1. If you are using xml based spring security, check if you have used

 <global-method-security secured-annotations="enabled", pre-post-annotations="enabled"/>

where secured-annotations is for @Secured and pre-post-annotations is for @PreAuthorize and @PostAuthorize

2. If you are using java configuration , you need to check if your java configuration class is annotated with

@EnableGlobalMethodSecurity(securedEnabled=true, prePostEnabled=true)

securedEnabled is for @Secured and prePostEnabled  attribute is for @PreAuthorize and @PostAuthorize
    

joined on
May 16,2015
Replied on May 20,2015

Great its working now. I am using java configuration and I was missing

@EnableGlobalMethodSecurity(securedEnabled=true, prePostEnabled=true) annotation

on my java configuration.
joined on
October 10,2013
Replied on May 20,2015

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us