web 的项目如果所有的接口都是需要验证登陆状态的,有什么全局搞定的方法吗?

2018-10-23 13:26:12 +08:00
 ukipoi

AOP ?
现在是写了一个方法,所有接口都调用一遍。

3758 次点击
所在节点    Java
33 条回复
xinyewdz
2018-10-23 13:31:27 +08:00
拦截器,过滤器都可以。
elgae
2018-10-23 13:31:38 +08:00
filter
lcy630409
2018-10-23 13:33:10 +08:00
接口通过 ajax 或者 wss 传送,将他们封装一个函数,在里面判断...
sutra
2018-10-23 13:38:28 +08:00
不知道我题目有没有理解对,用 spring-security (当然其也是通过 filter )?
gaius
2018-10-23 13:39:31 +08:00
HandlerInterceptorAdapter
ben1024
2018-10-23 13:41:35 +08:00
JWT,Header 验证
wu67
2018-10-23 13:59:51 +08:00
带 token, 没带 token 的请求全部报错就行了
bankroft
2018-10-23 14:01:29 +08:00
decorate ?
qwertyzzz
2018-10-23 15:21:24 +08:00
继承?
whypool
2018-10-23 15:41:29 +08:00
中间件
jason19659
2018-10-23 15:46:22 +08:00
filter interceptor
KingEngine
2018-10-23 15:51:08 +08:00
spring-security 嘛
DesmondLiu90
2018-10-23 16:14:10 +08:00
authFilter 啊,里面写验证 token 的逻辑
licoycn
2018-10-23 16:24:38 +08:00
过滤器
licoycn
2018-10-23 16:25:05 +08:00
或者使用 Shiro 或 SpringSecurity 这样的安全框架
yuanfnadi
2018-10-23 16:29:26 +08:00
拦截器。
liuxey
2018-10-23 16:35:13 +08:00
如果是普通 web servlet/jsp 项目,用:filter
如果是 springMVC 项目,用:interceptor
如果是 springMVC 大项目,用:SpringSecurity

另不推荐使用 Shiro
xuanbg
2018-10-23 16:40:55 +08:00
非微服务项目:过滤器实现
微服务项目:网关实现
leeho
2018-10-23 16:47:32 +08:00
axios 拦截器
lllllliu
2018-10-23 16:49:02 +08:00
AOP 可以。
面向对象继承一个基础类,然后构造方法自动验证也可以。
路由中间件也可以。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/500177

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX