老师帮忙看下,短信登录,上贴你回答根本不是这个问题,视频和代码都是用Basic的

来源:6-5 重构短信登录

eddie_k2

2018-09-09

http://img.mukewang.com/szimg/5b9479820001748808930479.jpg

http://img.mukewang.com/szimg/5b9479910001224f09020507.jpg

http://img.mukewang.com/szimg/5b9479a90001e7e309070526.jpg

http://img.mukewang.com/szimg/5b9479b80001d14e08830297.jpg

http://img.mukewang.com/szimg/5b9479da00011a1b12650210.jpg


章节6-5 重构短信登录


后台打印是登录成功, 返回是异常???


{

    "timestamp": 1536456540725,

    "status": 500,

    "error": "Internal Server Error",

    "exception": "org.springframework.security.authentication.BadCredentialsException",

    "message": "Failed to decode basic authentication token",

    "path": "/secuity/mobile"

}


写回答

2回答

eddie_k2

提问者

2018-09-09

已解决,在看几次视频发现和老师有出入,按老师的做 可以了

0
0

eddie_k2

提问者

2018-09-09

测试: 通过老师的6-5代码实现运行,同样出现 “Failed to decode basic authentication token”

为什么视频里面可以,但是我们不行?


之前老师说是:“token前面不应该是basic 应该是 bearer”

但是代码是:“Basic ” 不然就抛出 “请求头中无client信息” 


卡了几天,谁说一下 谢谢!~~~~~~~~~~~


@SuppressWarnings("unchecked")
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
     Authentication authentication) throws IOException, ServletException {

  logger.info("登录成功");

  String header = request.getHeader("Authorization");

  if (header == null || !header.startsWith("Basic ")) {
     throw new UnapprovedClientAuthenticationException("请求头中无client信息");
  }

  String[] tokens = extractAndDecodeHeader(header, request);
  assert tokens.length == 2;

  String clientId = tokens[0];
  String clientSecret = tokens[1];

  ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);

  if (clientDetails == null) {
     throw new UnapprovedClientAuthenticationException("clientId对应的配置信息不存在:" + clientId);
  } else if (!StringUtils.equals(clientDetails.getClientSecret(), clientSecret)) {
     throw new UnapprovedClientAuthenticationException("clientSecret不匹配:" + clientId);
  }

0
0

Spring Security技术栈开发企业级认证与授权

Spring Security技术栈,REST风格开发常见接口,独立开发认证授权模块保证REST服务安全

2662 学习 · 1561 问题

查看课程