老师帮忙看下,短信登录,上贴你回答根本不是这个问题,视频和代码都是用Basic的
来源:6-5 重构短信登录
eddie_k2
2018-09-09





章节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
已解决,在看几次视频发现和老师有出入,按老师的做 可以了
00 -
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);
}00
Spring Security技术栈开发企业级认证与授权
2662 学习 · 1561 问题
相似问题