V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ukipoi
V2EX  ›  Java

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

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

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

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

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

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