Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Security Handling @PreAuthorize Exception

 
Luis Parente
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Before all, I want to apologize for my bad English.

Well I'm trying to handle the @PreAuthorize exeception and redirect to my access denied page.


I have two things:

My custom access denied page that is configured and it's work fine. I have add and the jspx, works perfectly except with de PreAuthorize.

I have put in a controller, on top of the method and it's throw an exception if I have another ROLE.

This is my full configuration:

in webmvc-config.xml:


in applicationContext.xml



and it's ok.... in my class SkipMethodCallAccessDecisionManager with a breakpoint in



the exception is caught in InvocableHandlerMethod.class:



And in the browser I have the default error page.....

When and how I do redirect to my custom access denied page?


I need some help please



Thanks in advance.

Best regards.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to have Exceptions directed to a specific page are xml and annotations. Personally, I like the annotation. In Spring MVC you can annotate a Controller method with

@ExceptionHandler({ExceptionClassesAsArrayHere.class})
public String someMethod() {

I can do anything here
return "viewNameForCustomExceptionPage";
}

Sorry I didn't indent it, but is it such small amount of code.

Good Luck

Mark
 
Luis Parente
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have saw before, but in my file webmvc-config.xml




I have added the definition for my custom access denied page and now it's work


Thanks for your response!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep that is the xml version that I mentioned. I perfer the annotations, but that also works too, just more verbose.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic