Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to restrict HandlerInterceptors to specific controller paths [SPR-4015] #8695

Closed
spring-projects-issues opened this issue Oct 28, 2007 · 11 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 28, 2007

Scott Murphy opened SPR-4015 and commented

Annotation-based controller configuration is by far the best controller configuration I have seen to date. However, my current Spring 2.0 configuration is dependent on interceptors. However, the lack of interceptors has made it unusable to me. Is there any way we can PLEASE get some type on interceptor support in the 2.5 release?

@Interceptor("interceptorName")

I will work full time for FREE until the release if you need someone to write it if you can point me in the right direction.


Affects: 2.5 RC1

Issue Links:

1 votes, 4 watchers

@spring-projects-issues
Copy link
Collaborator Author

Scott Murphy commented

Ignore the 2nd "however". I lost my wireless internet connection during a post and accidentally resubmitted it before editing.
:)

I meant to say this:

Annotation-based controller configuration is by far the best controller configuration I have seen to date. However, my current Spring 2.0 configuration is dependent on interceptors. Is there any way we can PLEASE get some type on interceptor support in the 2.5 release?

@Interceptor("interceptorName")

I will work full time for FREE until the release if you need someone to write it if you can point me in the right direction.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Interceptors can be configured through an explicit "org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" bean definition, using the same "interceptors" property that is available on BeanNameUrlHandlerMapping and SimpleUrlHandlerMapping as well. Such a custom DefaultAnnotationHandlerMapping bean will simply override the default DefaultAnnotationHandlerMapping (which defines no interceptors), following the same approach that DispatcherServlet uses for all of its strategies.

I'm not fond of an @Interceptor annotation simply because interceptors should remain a separate configuration concern. Since interceptors are usually shared across many controllers, a custom HandlerMapping bean still seems to be the right level for defining interceptors.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Scott Murphy commented

What happens if you have 2 annotation controllers that each need different interceptors? I am under impression that you can only have one DefaultAnnotationHandlerMapping.

Can we create a RestrictedAnnotationHandlerMapping where you specify the urls (or controllers) that are part of that mapping?

I tried to extend the DefaultAnnotationHandlerMapping and have a second one with a different order, but it appears that you can not do this. I guess the controller initialization is done in this mapper? (I could not view the source to org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping. It was not included in the distribution and is also not in the CVS respository using the web browse function from SourceForge)

Here would be an example of what I am trying to do:

accountInterceptor
displayAccounts.do
displayAccountDetails.do

bankingInterceptor
depositMoney.do
withdrawMoney.do

If I set up an interceptor for DefaultAnnotationHandlerMapping it would use it for all the controllers.

@spring-projects-issues
Copy link
Collaborator Author

Scott Murphy commented

I retract my last comment, I was able to create a RestrictedAnnotationHandlerMapping where I define valid annotation urls. Everything works great now, thanks. You guys have really done a great job with 2.5. I have been using Spring since the 1.x days and I am really impressed with what you have done in 2.5

I'll mention again that org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping is missing from the src directory in the distribution. I don't know if you have a reason for that, but like I also said, I could not find it in CVS browse either.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

DefaultAnnotationHandlerMapping lives in the "tiger/src" directory. "src" only contains the parts of Spring that are compiled with "-target 1.4", whereas "tiger/src" gets compiled with "-target 1.5". The "spring-sources.jar" that we provide in the "dist" directory contains all of the sources merged into one tree.

Thanks for the praise, BTW :-)

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Scott Murphy commented

Anyone interested in using my classes for having multiple annotation mappers can get them here
http://www.scottmurphy.info/spring_framework_annotation_based_controller_interceptors

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Added mvc:interceptors element to Spring 3 MVC namespace which contains a mvc:interceptor element that allows you to define one to many mvc:mappings, allowing the restricting of an interceptor to specific path mappings.

@spring-projects-issues
Copy link
Collaborator Author

R. A. commented

There should also be a mvc:interceptor mapping parameter to exclude specified path from intercepting.

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Please open another Jira describing what you would like added in more detail

@spring-projects-issues
Copy link
Collaborator Author

R. A. commented

Opened new Jira https://jira.springsource.org/browse/SPR-6570 . Thanks.

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant