CAS客户端starter 使用方法

介绍

CAS认证中心starter,项目打包后放到要使用的项目中即可,通过简单的配置文件就可以使用了,注意本文提供的只是客户端服务端需要自定搭建

配置文件

application.propertiesapplication.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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值