cas5.3 → connect to mysql database

For convenience, use http protocol to test directly.
For specific configuration, see: cas5.3 uses http request

1. Add dependencies and modify the pom.xml file

	<!--数据库认证相关 start-->            
    <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>5.1.27</version>
    </dependency>
    <!--数据库认证相关 end-->

2. Create user table

First create a user table for testing

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for t_user
-- ----------------------------
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of t_user
-- ----------------------------
INSERT INTO `t_user` VALUES ('1', 'admin', '123');

3. Configure database connection

Configure the application.properties file

  1. First comment out the default username and password

  1. Add database connection
cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
cas.authn.jdbc.query[0].user=root
cas.authn.jdbc.query[0].password=root
cas.authn.jdbc.query[0].sql=select * from t_user where username=?
cas.authn.jdbc.query[0].fieldPassword=password
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
  • The first three lines of configuration are the basic database connection configuration.
  • The fourth line indicates that the user is configured to query sql, and all the user information is queried based on the user name.
  • The fifth line indicates what is the name of the password field in the database.
  • The sixth line is the database driver.

Finally, restart the cas server and enter http://127.0.0.1:8443/cas to log in and verify.

Guess you like

Origin blog.csdn.net/weixin_42201180/article/details/107692318