qwerthhusn
V2EX  ›  Java

在使用 Spring 写 REST 接口工程时,你是使用 Spring Security 还是自定义的逻辑来实现安全?

  •  
  •   qwerthhusn · Oct 29, 2020 · 2110 views
    This topic created in 2051 days ago, the information mentioned may be changed or developed.

    自己实现的话感觉也不复杂,至少逻辑自己很清楚比较清晰。

    使用 Spring Security 的话,感觉看着很简单,但是实际用起来没那么简单。而且 Spring Security 拦截后返回给 Client 的响应不是自己想要的样子。我是加上一个 HandlerInterceptor 处理/error请求。

    3 replies    2020-10-29 11:12:37 +08:00
    Oktfolio
        1
    Oktfolio  
       Oct 29, 2020   ❤️ 2
    http.exceptionHandling()
    .accessDeniedHandler(accessDeniedHandler);

    http.formLogin()
    .successHandler(authenticationSuccessHandler)
    .failureHandler(authenticationFailureHandler);

    http.exceptionHandling()
    .authenticationEntryPoint(authenticationEntryPoint);

    http.logout()
    .logoutSuccessHandler(logoutSuccessHandler);
    qwerthhusn
        2
    qwerthhusn  
    OP
       Oct 29, 2020
    @Oktfolio 还有这些啊,我去,很多 Spring Security 的概念和功能我都不知道,看来我需要仔细看看 Spring Security 的文档了
    leafre
        3
    leafre  
       Oct 29, 2020
    shiro 轻量
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5113 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:23 · PVG 17:23 · LAX 02:23 · JFK 05:23
    ♥ Do have faith in what you're doing.