cas server 4.1.0 maven版 自定义sql 验证,搭建分享
首先下载CAS v4.1.0 :
https://github.com/apereo/cas/releases/tag/v4.1.0
解压后找到:cas-server-webapp 项目
cas-server-webapp项目pom文件添加:
<!-- zip包中的cas-server-support-jdbc项目,sql验证需要引入 --> <dependency> <groupId>org.jasig.cas</groupId> <artifactId>cas-server-support-jdbc</artifactId> <version>4.1.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency>
cas-server-webapp/src/main/webapp/WEB-INF/deployerConfigContext.xml做如下修改:
1.找到 id="authenticationManager" bean :
<entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" /> <!--<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />--> <entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver"/>
2.添加如下配置bean: <!-- dataSource验证 --> <!-- 数据库连接 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" > <property name="driverClass" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/authority?characterEncoding=UTF-8"/> <property name="user" value="root"/> <property name="password" value="123456"/> </bean> <!-- 可选配置:数据库加密方式 --> <!--<bean id="passwordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder" c:encodingAlgorithm="SHA1" p:characterEncoding="UTF-8" />--> <bean id="dbAuthHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler" p:dataSource-ref="dataSource" p:sql="select password from authority_users where username=?" /> <!--p:passwordEncoder-ref="passwordEncoder"-->
有些情况回报错,gradle-aspectj-1.6.jar未找到,需要自己添加到本地maven仓库中,下载地址
https://download.****.net/download/sinat_34842630/10633703
至此,cas-server已经搭建完成,可以提取出war包放在tomcat容器中运行了。