介绍
CAS认证中心starter,项目打包后放到要使用的项目中即可,通过简单的配置文件就可以使用了,注意本文提供的只是客户端服务端需要自定搭建
配置文件
application.properties或
application.yml中必须使用的属性
cas:
clientEnable: true #是否开启cas认证 默认true
server-url-prefix: http://localhost:8081/firebirds-plume-template #cas server 认证URL地址
server-login-url: http://localhost:8081/firebirds-plume-template/login #cas server 登录页地址
client-host-url: http://localhost:8080 #主页地址
server-logout-url: http://localhost:8081/firebirds-plume-template/logout #cas退出方法
validation-type: cas3 #选择cas3
ignore-Filters: /js/*|/css/* #可忽略文件
使用方法
登录方法
@RequestMapping(value = "login",
method = RequestMethod.GET,
produces = "application/json;charset=utf-8")
public String login(HttpSession session,
HttpServletRequest request, HttpServletResponse response) {
//返回的登录用户信息
//通过cas client获取
Object object = request.getSession().getAttribute("_const_cas_assertion_");
if(null != object) {
Assertion assertion = (Assertion) object;
String loginName = assertion.getPrincipal().getName();
//获取属性值,为一个Map类型。
Map<String, Object> att = assertion.getPrincipal().getAttributes();
logger.info("登陆用户名:{}" ,loginName);
logger.info("登陆返回的属性:{}" ,att);
return loginName+"---登录成功";
}
退出方法
@RequestMapping(value = "loginout",
method = RequestMethod.GET,
produces = "application/json;charset=utf-8")
public void logins(HttpSession session,
HttpServletRequest request, HttpServletResponse response) throws IOException {
//session值去除
session.removeAttribute("_const_cas_assertion_");
session.invalidate();
//service=自定义页面
response.sendRedirect(casout_server_logout_url+"?service=http://www.baidu.com");
logger.info("退出登录成功");
}
下载地址
下载: cas_client.