如何在spring-mvc中基于域过滤请求 [英] How to filter request based on domain in spring-mvc

查看:15
本文介绍了如何在spring-mvc中基于域过滤请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个 war 文件,我将使用 2 个域来访问它.例如,我想使用 admin.mydomain.com/adminpage 访问 admin.jsp 以及我想使用 local.mydomain.com 访问的其他 jsp 页面.

I have one war file for my application and I will be using 2 domains to access it. For example I want to access admin.jsp using admin.mydomain.com/adminpage and other jsp pages I want to access with local.mydomain.com.

此外,admin.jsp 应该只能通过 admin.mydomain.com 访问,而不能通过 local.mydomain.com 访问.如何在 spring-security/spring-mvc 中做到这一点?spring 框架是否支持此功能?

Also, admin.jsp should be only accessible via admin.mydomain.com and not via local.mydomain.com. How to do this in spring-security / spring-mvc? Is there a support in spring framework for this?

对此的任何帮助都会有所帮助.谢谢.

Any help on this would be helpful. Thanks.

推荐答案

你可以实现 RequestMatcher,也许像

You can implement RequestMatcher, and maybe like

HostOnlyRequestMatch(String relativePath, String hostname)

然后覆盖booleanmatches(HttpServletRequest request)方法,如果relativePathhostname与请求相同,则返回true.

and then override the boolean matches(HttpServletRequest request) method, and if the relativePath and hostname are same with request, return true.

requestMatcher 添加到 http 像这样:

Add the requestMatcher to http like this:

 http
     .authorizeRequests()
         .requestMatcher(new HostOnlyRequestMatch("/admin", "admin.mydomain.com")).permitAll()
         .antMatchers("/admin").denyAll();

这篇关于如何在spring-mvc中基于域过滤请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆