java - 在 Spring Security 之前使用 Spring Mobile 设备检测
问题描述
我想在登录后将用户重定向到不同的页面,具体取决于他们是什么类型的用户,以及他们是否在移动设备上。我的项目使用 Spring MVC 和 Spring Security。为了使重定向逻辑正常工作,我使用 Spring Security AuthenticationSuccessHandler 来识别用户登录后的类型并将他们引导到正确的页面。
我希望此时使用 Spring Mobile 检查它们是否在移动设备上,如果是,则将它们发送到 URL 的移动版本。但是,似乎 DeviceResolverHandlerInterceptor 之类的拦截器在 Spring Security 过滤器之后执行,因此在我需要它的时候还没有解决。
目前,我能看到的唯一解决方案是禁用拦截器,而是直接使用 LiteDeviceResolver 的 resolveDevice() 方法。这感觉有点hacky,但我看不到另一个明显的选择。
有没有更好的方法来配置这个人们都知道?
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Bean
public DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor() {
return new DeviceResolverHandlerInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(deviceResolverHandlerInterceptor()).order(Ordered.HIGHEST_PRECEDENCE);
}
}
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
boolean isMobile = DeviceUtils.getCurrentDevice(request) != null
&& DeviceUtils.getCurrentDevice(request).isMobile();
...
解决方案
推荐阅读
- javascript - 有没有办法在生产中使用 VueJS 进行新构建时强制浏览器自动重新加载?
- phoenix-framework - 如何在 Phoenix / Ecto 中聚合 has_many 字段?
- cookies - 如何使用具有特定登录详细信息 cookie 的灯塔?
- angular - 使用 Angular 刷新组件
- highcharts - 如何在钻取中添加同步图表?
- node.js - 没有进入猫鼬中的保存功能
- amazon-web-services - 在训练数据中反映用户的负面反馈
- node.js - 节点 JS - 无法在 ubuntu 16.04 中安装节点 js 版本 8.9 或更高版本
- linux - SI_TKILL ARM 上的 si_code 用于除零
- python - 尝试将模型从 keras 导出到 CoreML