一:安装CAS

下载cas:https://github.com/apereo/cas

1.1 将cas并打成war包。放入一个干净的tomcat中,启动tomcat测试: http://localhost:8080/cas/login

  

1.2 默认账号密码:casuser     Mellon     我们可以在tomcat\webapps\cas\WEB-INF\deployerConfigContext.xml文件添加一个账号密码

  

1.3 修改tomcat端口为9080, 并将tomcat\webapps\cas\WEB-INF\cas.properties的server.name改为http://localhost:9080

1.4 去除https认证:

1.4.1 在tomcat\webapps\cas\WEB-INF\deployerConfigContext.xml文件
的p:httpClient-ref="httpClient"后面添加p:requireSecure="false"
1.4.2 把tomcat\webapps\cas\WEB-INF\spring-configuration的
ticketGrantingTicketCookieGenerator.xml文件里面把p:cookieSecure="true"改为false;
p:cookieMaxAge="-1"改为3600(-1是不保存cookie,3600秒是一个小时,保存登录信息)
1.4.3 把tomcat\webapps\cas\WEB-INF\spring-configuration的
warnCookieGenerator.xml的p:cookieSecure="true"改为false
p:cookieMaxAge="-1"改为3600

  

1.5 配置单点登出: 将tomcat\webapps\cas\WEB-INF\cas-servlet.xml中${cas.logout.followServiceRedirects:false}括号里的值改为true

1.6 启动测试:  输入刚才配置的账号密码   wulei / wulei

  

二:配置数据源(CAS对接数据库)

2.1 在tomcat\webapps\cas\WEB-INF\lib里添加 c3p0连接池   mysql驱动   cas的jdbc支持包

  

2.2 修改tomcat\webapps\cas\WEB-INF\deployerConfigContext.xml文件

2.2.1 注释掉<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />;添加<entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver"/>

  

2.2.2  添加数据源   <bean id="dataSource"    添加加密方式 <bean id="passwordEncoder"     添加sql语句  <bean id="dbAuthHandler"

    <!-- 第一个bean -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/youfanshop?characterEncoding=utf8"
p:user="root"
p:password="root" />
<!-- 第二个bean
<bean id="passwordEncoder"
class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"
c:encodingAlgorithm="MD5"
p:characterEncoding="UTF-8" /> -->
<!-- 第三个bean
<bean id="dbAuthHandler"
class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"
p:dataSource-ref="dataSource"
p:sql="select passwordencrypt from user where name = ?"
我们密码用明文, 所以把加密方式注释掉,
p:passwordEncoder-ref="passwordEncoder"
/> -->
<bean id="dbAuthHandler"
class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"
p:dataSource-ref="dataSource"
p:sql="select passwordencrypt from user where name = ?" />

  

2.3 重启测试(此时就能用数据库的账号密码登录了)

  

三:springBoot客户端

3.1 导包

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<!--web场景启动器,包含 Tomcat 和 spring-mvc restful aop jackjson支持。 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- CAS依赖包 -->
<dependency>
<groupId>net.unicon.cas</groupId>
<artifactId>cas-client-autoconfig-support</artifactId>
<version>1.5.0-GA</version>
</dependency>
</dependencies>

3.2 application.properties

server.port=8081

cas.server-url-prefix=http\://127.0.0.1\:9080/cas
cas.server-login-url=http\://127.0.0.1\:9080/cas/login
cas.client-host-url=http\://127.0.0.1\:8081
cas.validation-type=CAS

3.3 配置类

import net.unicon.cas.client.configuration.CasClientConfigurerAdapter;
import net.unicon.cas.client.configuration.EnableCasClient;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Configuration; @Configuration
@EnableCasClient
public class CasConfigure extends CasClientConfigurerAdapter {
@Override
public void configureAuthenticationFilter(FilterRegistrationBean authenticationFilter) {
super.configureAuthenticationFilter(authenticationFilter);
authenticationFilter.getInitParameters().put("authenticationRedirectStrategyClass","com.patterncat.CustomAuthRedirectStrategy");
}
}

3.4 控制器

@RestController
public class IndexController { @RequestMapping("/login")
public String auth() {
return "login success";
}
}

3.5 主函数

@SpringBootApplication
public class Application { private static Logger log = Logger.getLogger(Application.class); public static void main(String[] args) {
SpringApplication.run(Application.class, args);
log.info("SpringBoot Start Success");
}
}

测试:  浏览器输入   127.0.0.1:8081/login之前会先跳转到CAS的登陆页面,登录成功之后才会进入Controller。

Springboot+CAS单点登录的更多相关文章

  1. CAS单点登录原理简单介绍

    1. SSO简介 1.1 单点登录定义 单点登录(Single sign on),英文名称缩写SSO,SSO的意思就是在多系统的环境中,登录单方系统,就可以在不用再次登录的情况下访问相关受信任的系统. ...

  2. Spring boot security权限管理集成cas单点登录

    挣扎了两周,Spring security的cas终于搞出来了,废话不多说,开篇! Spring boot集成Spring security本篇是使用spring security集成cas,因此,先 ...

  3. CAS单点登录系列之极速入门于实战教程(4.2.7)

    @ 目录 一. SSO简介 1.1 单点登录定义 1.2 单点登录角色 1.3 单点登录分类 二. CAS简介 2.1 CAS简单定义 2.2 CAS体系结构 2.3 CAS原理 三.CAS服务端搭建 ...

  4. SSO之CAS单点登录实例演示

    本文目录: 一.概述 二.演示环境 三.JDK安装配置 四.安全证书配置 五.部署CAS-Server相关的Tomcat 六.部署CAS-Client相关的Tomcat 七. 测试验证SSO 一.概述 ...

  5. cas 单点登录出现org.jasig.cas.client.util.CommonUtils.getResponseFromServer - 拒绝连接 Connection refused

    cas 单点登录出现org.jasig.cas.client.util.CommonUtils.getResponseFromServer - 拒绝连接 Connection refused 环境: ...

  6. CAS单点登录中文用户名乱码问题

    CAS单点登录中文用户名乱码问题,有两种情况 1. CAS server乱码 即在向server端提交用户名和密码时,发生了乱码,解决方法是: 打开WEB-INF/web.xml,在其它的Filter ...

  7. CAS单点登录系统整合——注册的问题

    最近一段时间在搞CAS单点登录系统,涉及到几个子系统的整合问题.对于注册,这里遇到了一个选择: 在子系统内完成注册,然后把信息同步到CAS系统: 在CAS系统中完成基本信息的注册,比如:用户名.邮箱. ...

  8. Asp.net Mvc4 使用Cas单点登录

    因项目需要,使用了耶鲁大学的Cas单点登录方案,在java中使用一直正常,但是在.Net中碰到了循环重定向的问题,反复测试后,总算解决了,最终的配置如下: <?xml version=" ...

  9. CAS单点登录之mysql数据库用户验证及常见问题

    前面已经介绍了CAS服务器的搭建,详情见:搭建CAS单点登录服务器.然而前面只是简单地介绍了服务器的搭建,其验证方式是原始的配置文件的方式,这显然不能满足日常的需求.下面介绍下通过mysql数据库认证 ...

随机推荐

  1. JAVA批量文件下载

    1,看看我们封装的方法 方法中有三个参数:视频url,文件夹路径,视频名称. 调用方法进行下载. 2,看看结果 打印结果 文件夹下的视频下载成功 详细的参数配置可以参考我写的这篇文章:http://b ...

  2. springboot(一).初识springboot以及基本项目搭建

    初识springboot 以及基本项目搭建 由于新的项目需要搭建后台框架,之前的springmvc架构也使用多次,在我印象中springboot的微服务架构更轻量级更容易搭建,所以想去试试spring ...

  3. 管理es索引-使用 Xput创建索引

    curl是利用URL语法在命令行方式下工作的开源文件传输工具,使用curl可以简单实现常见的get/post请求.简单的认为是可以在命令行下面访问url的一个工具.在centos的默认库里面是有cur ...

  4. sqli-labs(25a)

    0X01 看见bind好像是盲注的意思 尝试闭合语句 加入’ 报错  双引号也报错 难道是不许要闭合的? 我们尝试一下 发现过滤了and ?id= and = 那么我们构造 ?id= aandnd = ...

  5. ACCESS数据库注入

    0X01 我们想来了解一下access数据库 Access注入是暴力猜解 Access数据结构(access只有一个数据库) Access数据库 表名 列名 数据 没有库这个概念 只有表这个概念 这应 ...

  6. centos7 升级gcc9.1.0版本

    centos7 环境 查缺补漏 yum install gcc gcc-c++ -y yum install bzip2 -y gcc版本下载:https://gcc.gnu.org/mirrors. ...

  7. ES6注

    1.Promise构造函数 //resolve(成功),reject(失败)两个参数 function runAsync(){ var p = new Promise(function(resolve ...

  8. 关闭layer.open打开的页面

    window.parent.location.reload(); //刷新父页面 var index = parent.layer.getFrameIndex(window.name); //获取窗口 ...

  9. Selenium学习之==>Css Selector使用方法

    一.什么是Css Selector Css Selector定位实际就是HTML的Css选择器的标签定位 工具 Css Selector的练习建议大家安装火狐浏览器后,下载插件,FireFinder ...

  10. C 语言中的预处理

    C 语言中以 # 开头的就是预处理指令,例如 #include . 预处理指令的用途 所有的预处理指令都会在 GCC 编译过程的预处理步骤解析执行,替换为对应的内容.在下一步编译过程中,看不到任何预处 ...