使用Grails 3.3.5和Spring-security-rest 2.0.0-RC1处理REST API应用程序。
当我使用/ api / login登录时,我得到了正确的结果:
{
"username": "name.surname@acme.com",
"roles": [
"ROLE_USER"
],
"access_token": "qgsbpk05jfrbf33xx08m8r4govkg53d1"
}
我想在响应中添加其他信息,例如用户的姓名和姓氏。感谢
更新 感谢Evgeny指出我正确的方向并阅读手册我也实现了UserDetailsService。 从手册:
如果要在JSON响应中呈现其他信息, 你必须:
Configure an alternative userDetailsService bean that retrieves the additional information you want, and put it in a principal object. Configure an alternative accessTokenJsonRenderer that reads that information from the restAuthenticationToken.principal object.
答案 0 :(得分:2)
您可以覆盖 accessTokenJsonRenderer bean
class MyRestAuthTokenJsonRenderer implements AccessTokenJsonRenderer { @Override String generateJson(AccessToken accessToken){ // create response, see DefaultAccessTokenJsonRenderer.groovy from https://github.com/alvarosanchez/grails-spring-security-rest return your_formatted_json_response } }
beans = { accessTokenJsonRenderer(MyRestAuthTokenJsonRenderer) }