ukipoi
V2EX  ›  Java

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

  •  
  •   ukipoi · Oct 23, 2018 · 5197 views
    This topic created in 2941 days ago, the information mentioned may be changed or developed.

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

    33 replies  •  2018-10-24 08:27:23 +08:00
    xinyewdz
    xinyewdz
    Oct 23, 2018
    1
    拦截器,过滤器都可以。
    elgae
    elgae
    Oct 23, 2018
    2
    filter
    chengran630
    chengran630
    Oct 23, 2018
    3
    接口通过 ajax 或者 wss 传送,将他们封装一个函数,在里面判断...
    sutra
    sutra
    Oct 23, 2018
    4
    不知道我题目有没有理解对,用 spring-security (当然其也是通过 filter )?
    gaius
    gaius
    Oct 23, 2018
    5
    HandlerInterceptorAdapter
    ben1024
    ben1024
    Oct 23, 2018
    6
    JWT,Header 验证
    wu67
    wu67
    Oct 23, 2018
    7
    带 token, 没带 token 的请求全部报错就行了
    tribute
    tribute
    Oct 23, 2018 via Android
    8
    decorate ?
    asLw0P981N0M0TCC
    asLw0P981N0M0TCC
    Oct 23, 2018
    9
    继承?
    whypool
    whypool
    Oct 23, 2018
    10
    中间件
    jason19659
    jason19659
    Oct 23, 2018
    11
    filter interceptor
    KingEngine
    KingEngine
    Oct 23, 2018
    12
    spring-security 嘛
    DesmondLiu90
    DesmondLiu90
    Oct 23, 2018
    13
    authFilter 啊,里面写验证 token 的逻辑
    licoycn
    licoycn
    Oct 23, 2018
    14
    过滤器
    licoycn
    licoycn
    Oct 23, 2018
    15
    或者使用 Shiro 或 SpringSecurity 这样的安全框架
    yuanfnadi
    yuanfnadi
    Oct 23, 2018 via iPhone
    16
    拦截器。
    auin
    auin
    Oct 23, 2018
    17
    如果是普通 web servlet/jsp 项目,用:filter
    如果是 springMVC 项目,用:interceptor
    如果是 springMVC 大项目,用:SpringSecurity

    另不推荐使用 Shiro
    xuanbg
    xuanbg
    Oct 23, 2018
    18
    非微服务项目:过滤器实现
    微服务项目:网关实现
    leeho
    leeho
    Oct 23, 2018
    19
    axios 拦截器
    lllllliu
    lllllliu
    Oct 23, 2018
    20
    AOP 可以。
    面向对象继承一个基础类,然后构造方法自动验证也可以。
    路由中间件也可以。
    akira
    akira
    Oct 23, 2018
    21
    做一个前置网关处理更合理吧
    Variazioni
    Variazioni
    Oct 23, 2018
    22
    还不如用 shiro 之类的安全框架。。配置更方便。。
    teg1c
    teg1c
    Oct 23, 2018
    23
    中间件
    wobuhuicode
    wobuhuicode
    Oct 23, 2018
    24
    JWT 啊
    98jiang
    98jiang
    Oct 23, 2018
    25
    @liuxey 能问下为什么呀
    limuyan44
    limuyan44
    Oct 23, 2018 via Android
    26
    filter。。几分钟写完,没什么复杂要求的话随便写写。。登录完 session 丢个 token
    tom
    tom
    Oct 23, 2018
    27
    @liuxey #17 为啥不推荐 Shiro 啊?能说说原因吗?
    JokerZX
    JokerZX
    Oct 23, 2018
    30
    同 jwt header 验证
    loveCoding
    loveCoding
    Oct 23, 2018
    31
    @tom #27 shiro 也是 filter, 轻量级的自己写其实也不要多少时间
    Doodlister
    Doodlister
    Oct 24, 2018 via Android
    32
    @liuxey shiro 咋啦
    auin
    auin
    Oct 24, 2018
    33
    @tom
    @loveCoding
    @Doodlister

    可能我的想法比较主观,做个类比,想想现在的 struts
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2291 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 66ms · UTC 12:48 · PVG 20:48 · LAX 04:48 · JFK 07:48
    ♥ Do have faith in what you're doing.