开发者社区 问答 正文

spring security oauth2 如何自定义验证内容?:报错

我使用客户端模式,但想对客户端上传内容进行校验,而不是密码模式中的用户和密码。这种情况不知道如何去验证?

密码模式中,是在authenticationManager中添加UserDetailsService的实现类,在实现类中获取账号密码提供底层框架去验证密码。

如果只能使用密码模式的这套方法,那有没有办法在UserDetailsService的实现类,返回自定义的异常响应?

展开
收起
kun坤 2020-06-06 12:01:36 626 分享 版权
1 条回答
写回答
取消 提交回答
  • 试一下给自定义exceptionTranslator

    public class MyWebResponseExceptionTranslator implements WebResponseExceptionTranslator {
    
      @Override
      public ResponseEntity<OAuth2Exception> translate(Exception e){
        // todo
      }
    }
    @Configuration
    @EnableAuthorizationServer
    public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {
      
      @Override
      public void configure(AuthorizationServerEndpointsConfigurer endpoints){
        //...
        endpoints
          // other configures
          .exceptionTranslator(new MyWebResponseExceptionTranslator());
      }
    }

     

    ######返回错误该怎么做?我百度到的代码,是把错误信息,自定义化而已。但我想要在UserDetailsService实现类中抛异常,是直接被作为异常处理返回请求######
    SecurityConfigurerAdapter
    ######WebSecurityConfigurerAdapter?
    2020-06-06 12:01:41
    赞同 展开评论