Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

spring @PreAuthorize not working with @EnableGlobalMethodSecurity(prePostEnabled = true)

Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code:

@ComponentScan(basePackages = "com.webapp")
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();

protected void configure(HttpSecurity http) throws Exception {

public void configureGlobal(UserDetailsService userDetailsService, AuthenticationManagerBuilder auth)
throws Exception {


when a request /admin/* comes in, it will verify if the user has admin role by calling "antMatchers("/admin/**").hasRole("ADMIN")." , but in my controller, it does not check if the user has other permissions with @PreAuthorize .

@SessionAttributes({ "user" })
@RequestMapping(value = "/admin/user")
public class UserController {

static Logger logger = LoggerFactory.getLogger(UserController.class);

private RoleDAO roleDao;

private MessageSource messageSource;

private UserDAO userDao;

@RequestMapping(value = { "/", "/list" }, method = RequestMethod.GET)
public ModelAndView listUsers() {

List<User> users = userDao.list();
ModelAndView model = new ModelAndView("/admin/user/user-list");
model.addObject("users", users);
if (model.getModel().get("user") == null) {
model.getModel().put("user", new User());
return model;
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xi brian,

Please use Code tags when you are entering codes in you post, so that it will be helpful to people who want to review your code and offer some help to you. I am trying to answer your post but it is difficult to read your code. so please use code tags.

And not working will not get you any help here. Please tell us the details. Tell us what exception you get, so that we could provide solutions to you.
What are your superhero powers? Go ahead and try them on this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic