简单实现CAS单点登录连接MYSQL用户登录验证

一、 CAS服务器单独部署在tomcat中:下载地址: https://github.com/apereo/cas-overlay-template
1、下载后解压 cas-overlay-template-xxx.zip

1、解压后在根目录下使用命令行执行以下命令

 		build.cmd package

2、执行上述命令后会在target目录下生成 cas.war
3、将cas.war放到tomcat的webapp中启动tomcat
4、启动成功后访问 http://localhost:8080/cas/login
5、默认用户名:casuser 密码: Mellon 详细信息在tomcat启动后编译生成的cas文件夹:
cas\WEB-INF\classes\application.properties

2、开发环境去除https认证,在tomcat启动编译生成的cas文件夹

1、在cas\WEB-INF\classes文件夹下application.properties添加以下配置

		cas.tgc.secure=false #去除https
		cas.serviceRegistry.initFromJson=true #json验证

2、在cas\WEB-INF\classes\services下的HTTPSandIMAPS-10000001.json修改配置:

		"serviceId" : "^(https|http|imaps)://.*" #添加 http 

以上cas服务的搭建

二、连接mysql

1、回到之前解压好的cas文件夹中找到pom.xml文件在dependencies中添加依赖

		  <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <id>default</id>
            <dependencies>
                <dependency>
                    <groupId>org.apereo.cas</groupId>
                    <artifactId>cas-server-webapp${app.server}</artifactId>
                    <version>${cas.version}</version>
                    <type>war</type>
                    <scope>runtime</scope>
                </dependency>
				 <dependency>
					<groupId>org.apereo.cas</groupId>
					<artifactId>cas-server-support-jdbc</artifactId>
					<version>${cas.version}</version>
				</dependency>
				<dependency>
					<groupId>org.apereo.cas</groupId>
					<artifactId>cas-server-support-jdbc-drivers</artifactId>
					<version>${cas.version}</version>
				</dependency>
				<dependency>
					<groupId>mysql</groupId>
					<artifactId>mysql-connector-java</artifactId>
					<version>${mysql.driver.version}</version>
				</dependency>
                <!--
                ...Additional dependencies may be placed here...
                -->
            </dependencies>
        </profile>
		

2、在properties中添加 mysql.driver.version

  <properties>
        <cas.version>5.3.16</cas.version>
        <springboot.version>1.5.18.RELEASE</springboot.version>
        <!-- app.server could be -jetty, -undertow, -tomcat, or blank if you plan to provide appserver -->
        <app.server>-tomcat</app.server>

        <mainClassName>org.springframework.boot.loader.WarLauncher</mainClassName>
        <isExecutable>false</isExecutable>
        <manifestFileToUse>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp${app.server}/META-INF/MANIFEST.MF</manifestFileToUse>

        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<mysql.driver.version>5.1.49</mysql.driver.version>
    </properties>

3、完成以上操作后删除target中的文件,并命令行执行 build.cmd package 生成新的cas.war
4、把tomcat中webapps中的cas相关文件删除
5、把新生成的cas.war复制到tomcat的webapps
6、启动tomcat
7、启动完成后在\webapps\cas\WEB-INF\classes找到application.properties
注释以下属性:

#cas.authn.accept.users=casuser::Mellon

添加以下属性,添加完成后重启tomcat:

# 查询账号密码SQL,必须包含密码字段 
cas.authn.jdbc.query[0].sql=select * from user where username=?  
# 指定上面的SQL查询字段名(必须)
cas.authn.jdbc.query[0].fieldPassword=password 
# 数据库连接 cas:数据库名
cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/cas?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false 
# 数据库用户名
cas.authn.jdbc.query[0].user=casuser 
# 数据库用户密码
cas.authn.jdbc.query[0].password=123456 
# 数据库驱动
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver

补充:创建相应的数据库、用户、表,添加自定义用户账号及密码如需看创建方式可见 MYSQL相关创建
最后访问地址测试登录:http://localhost:8080/cas/login

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值