@PreAuthorize("@userService.isCurrentUserinCourse(authentication, courseId)")
You can get the authentication by following static method
SecurityContextHolder.getContext().getAuthentication()
and the courseId
you need to change to #coureseId
, and you need move this to the method, not class,so you can change to
@PreAuthorize("@userService.isCurrentUserinCourse(#courseId)")
@RequestMapping(value = { "/syllabus" }, method = RequestMethod.GET)
public ModelAndView syllabusPage(@PathVariable("courseId") int courseId) {
...}
manpreet
Best Answer
2 years ago
I'm trying to use preAuthorize to protect url. Only people registered in the course can access the course. Here is my code:
Controller:
UserServiceImpl:
spring-security.xml:
and we I go to /course/{id}/syllabus without out login, it shows the page where it should not. And debug is not go into isCurrentUserinCourse(Authentication authentication, int courseId) method in UserServiceImpl. where