Announcement Announcement Module
Collapse
No announcement yet.
Ignoring or re-throwing certain exceptions with SimpleMappingExceptionResolver Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ignoring or re-throwing certain exceptions with SimpleMappingExceptionResolver

    Hi All,

    I'm having a bit of trouble and it seems someone must have happened across this before...

    I use SimpleMappingExceptionResolver to map exceptions to views, however, I have certain exceptions that I'd just like to be left alone. This means I essentially need SimpleMappingExceptionResolver to ignore or re-throw those certain exceptions.

    I can find no documented example of how to do this and digging around the API, I see no evidence to suggest that it's even possible (without rolling my own).

    Has anyone else run into this? Can anyone offer a suggestion?

    FTW, the exact use case is that I don't want Spring Security exceptions like AccessDeniedException to be handled by SimpleMappingExceptionResolver because I'd rather let Spring Security's ExceptionTranslationFilter deal with them. This seemed like a more appropriate place for the question than the SS forum though because the question really revolves around how to get SimpleMappingExceptionResolver to ignore or re-throw exceptions.

    Any insight is greatly appereciated!

  • #2
    The name SimpleMappingExceptionResolver should give it away .

    It doesn't support this, but you can easily extend the SimpleMappingExceptionResolver, create a class, override the resolveException method. If it is an instance of SecurityException rethrow, else call the super method.

    You can add as much or less logic as you want ofcourse .

    Comment


    • #3
      Marten,

      Thanks for the reply.

      It strikes me as odd though that there isn't an "out-of-the-box" solution for this problem.

      Anyone who's using Spring MVC and Spring Security together (and that has to be a lot of people) would run into this problem. They're all subclassing SimpleMappingExceptionResolver or writing some other implementation of HandlerExceptionResolver to get around this?

      It's not that I doubt your answer... it just seems that if such a thing does not exist, it should.

      Do you think it would be appropriate for me to open an issue in Jira?

      Comment


      • #4
        IMHO the current implementation suffices. I also need to add that my answer wasn't complete.

        If the HandlerExceptionResolver (or Resolvers) doesn't return a view to render (i.e. you don't specify a default view and don't include a mapping for Exception.Throwable or SecurityException) the exception propagates up the chain and still will be handled by the Spring Security Filter.

        Comment


        • #5
          Ah...

          I did notice this and tried it, but because I do specify a default view, it was to no avail.

          Maybe I can drop the default view altogether, map org.springframework.security.SpringSecurityExcepti on to nothing and map Throwable to my old default view.

          Looking at the code, it seems that might work.

          Thanks for the help.

          Comment


          • #6
            Well, I tried...

            Code:
            <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
              <property name="exceptionMappings">
                <props>
                  <prop key="org.springframework.security.AccessDeniedException"/>
                  <prop key="java.lang.Throwable">.error</prop>
                </props>
              </property>
            </bean>
            No good. AccessDeniedException gets mapped to a view named ""- which naturally is not found. Schema doesn't allow <null/> here either.

            This takes me back to square one.

            I did whip up my own implementation of SimpleMappingExceptionResolver as you suggested earlier. I added the ability to specify a set of classes where they and their subclasses should be ignored.

            I also did open a suggestion in Jira.

            Thanks again for looking at this. Much appreciated.

            Comment

            Working...
            X