qwerthhusn
V2EX  ›  Java

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

  •  
  •   qwerthhusn · Oct 29, 2020 · 2434 views
    This topic created in 2217 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
    Oktfolio
    Oct 29, 2020❤️2
    1
    http.exceptionHandling()
    .accessDeniedHandler(accessDeniedHandler);

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

    http.exceptionHandling()
    .authenticationEntryPoint(authenticationEntryPoint);

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