• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring Security Handling @PreAuthorize Exception

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic