# cas客户端 **Repository Path**: lee_www/cas_client ## Basic Information - **Project Name**: cas客户端 - **Description**: 简单的介绍下CAS客户端的使用方法 - **Primary Language**: Java - **License**: MulanPSL-1.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-10-22 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CAS认证中心客户端starter ## 介绍 > CAS认证中心starter,项目打包后放到要使用的项目中即可,通过简单的配置文件就可以使用了,注意本文提供的只是客户端 > 服务端需要自定搭建 ## 使用 ### 配置 ##### `application.properties`或`application.yml`中必须使用的属性 ```xml 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/* #可忽略文件 ``` ### 使用方法 ```java @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 att = assertion.getPrincipal().getAttributes(); logger.info("登陆用户名:{}" ,loginName); logger.info("登陆返回的属性:{}" ,att); return loginName+"---登录成功"; } ``` - #### 退出方法 ```java @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("退出登录成功"); } ```