概述:Spring Security OAuth2构建一个授权服务器来验证用户身份以提供token,并使用这个token来控制接口权限
Spring Security OAuth2的集成过程本文不再介绍
身份认证时通常会调用Spring security oAuth2的原生接口:
http://127.0.0.1:8888/auth/oauth/token?grant_type=password&randomStr=blockPuzzle&scope=server
因为部署环境的字符集差异,当密码错误时接口会有两种返回:
{
"code": 1,
"msg": "Bad credentials",
"data": "invalid_exception"
}
或者
{
"code": 1,
"msg": "用户名或密码错误",
"data": "invalid_exception"
}
中文字符集返回中文msg,英文字符集返回英文msg。
-
可通过ReloadableResourceBundleMessageSource指定所需要的配置文件
-
@Bean public ReloadableResourceBundleMessageSource reloadableResource() { ReloadableResourceBundleMessageSource reloadable = new ReloadableResourceBundleMessageSource(); reloadable.setBasename("classpath:org/springframework/security/messages_zh_CN"); reloadable.setDefaultEncoding("UTF-8"); return reloadable; }