CAS客户端(spring boot + spring security)如何从CAS Server获取更多字段?
How the CAS client (spring boot + spring security) can get more fields from CAS Server?
我阅读了这篇文章CAS SSO With Spring Security并且运行成功获得了源代码,但是这个客户端只能获取用户名,我希望我的客户端需要更多来自CAS服务器的字段。
在我以前使用传统SpringMVC的CAS客户端中,我可以获取所有文件,包括用户名、电话号码、密码和电子邮件。主要步骤如下:
在 CAS 服务器的文件 WEB-INF/classes/services/Apereo-10000002.json 中,我添加了一个选项:
"attributeReleasePolicy" : {
"@class" : "org.apereo.cas.services.ReturnAllAttributeReleasePolicy"
}
在客户端,我使用了getUserPrincipal
如下
@RequestMapping("/cas/login.do")
@ResponseBody
public String casLogin(String uri,
HttpServletRequest request,...){
...
Principal principal = request.getUserPrincipal();
Map<String,Object> userInfo = new HashMap<>();
if (p instanceof AttributePrincipal) {
userInfo =( (AttributePrincipal)principal).getAttributes();
}
System.err.println("image:"+userInfo.get("image"));
System.err.println("username:"+userInfo.get("username"));
System.err.println("email:"+userInfo.get("email"));
System.err.println("phoneNo:"+userInfo.get("phoneNo"));
...
}
现在我想实现一个基于spring boot + spring security
的CAS客户端,如上文所述。但是基于文章代码,我该怎么办?提前致谢!
this client only get username, I hope my client need more fields from CAS server
您需要确保您的客户端正在点击正确的端点进行验证。基于 notes here:
If your client application is not receiving attributes, you will need to make sure:
- The client is using a version of CAS protocol that is able to release attributes.
- The client, predicated on #1, is hitting the appropriate endpoint for service ticket validation (i.e.
/p3/serviceValidate
).
- The CAS server itself is resolving and retrieving attributes correctly.
- The CAS server is authorized to release attributes to that particular client application inside its service registry.
我阅读了这篇文章CAS SSO With Spring Security并且运行成功获得了源代码,但是这个客户端只能获取用户名,我希望我的客户端需要更多来自CAS服务器的字段。
在我以前使用传统SpringMVC的CAS客户端中,我可以获取所有文件,包括用户名、电话号码、密码和电子邮件。主要步骤如下: 在 CAS 服务器的文件 WEB-INF/classes/services/Apereo-10000002.json 中,我添加了一个选项:
"attributeReleasePolicy" : {
"@class" : "org.apereo.cas.services.ReturnAllAttributeReleasePolicy"
}
在客户端,我使用了getUserPrincipal
如下
@RequestMapping("/cas/login.do")
@ResponseBody
public String casLogin(String uri,
HttpServletRequest request,...){
...
Principal principal = request.getUserPrincipal();
Map<String,Object> userInfo = new HashMap<>();
if (p instanceof AttributePrincipal) {
userInfo =( (AttributePrincipal)principal).getAttributes();
}
System.err.println("image:"+userInfo.get("image"));
System.err.println("username:"+userInfo.get("username"));
System.err.println("email:"+userInfo.get("email"));
System.err.println("phoneNo:"+userInfo.get("phoneNo"));
...
}
现在我想实现一个基于spring boot + spring security
的CAS客户端,如上文所述。但是基于文章代码,我该怎么办?提前致谢!
this client only get username, I hope my client need more fields from CAS server
您需要确保您的客户端正在点击正确的端点进行验证。基于 notes here:
If your client application is not receiving attributes, you will need to make sure:
- The client is using a version of CAS protocol that is able to release attributes.
- The client, predicated on #1, is hitting the appropriate endpoint for service ticket validation (i.e.
/p3/serviceValidate
).- The CAS server itself is resolving and retrieving attributes correctly.
- The CAS server is authorized to release attributes to that particular client application inside its service registry.