CAS数据库查询认证(xml配置)
上篇博客介绍的 CAS 的 Demo ,登录界面用户名、密码并没有通过数据库查询认证。本博客,将介绍如何通过 xml 配置,进行 CAS 登录数据库查询认证。 所需数据库 sso _cas, 库中的表: tb_user ,表中字段: Id 、 username 、 password ; 数据库查询认证(通
上篇博客介绍的CAS的Demo,登录界面用户名、密码并没有通过数据库查询认证。本博客,将介绍如何通过xml配置,进行CAS登录数据库查询认证。
所需数据库sso_cas,库中的表:tb_user,表中字段:Id、username、password;
数据库查询认证(通过xml配置)
1,修改cas服务端配置
tomcat下webapps/cas/WEB_INF/deployerConfigContext.xml 文件做如下修改:
修改为:
添加datasource bean的定义:
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
注意
1,QueryDatabaseAuthenticationHandler是cas-server-support-jdbc提供的查询接口其中一个是通过配置一个 SQL 语句查出密码,与所给密码匹配;
2,sql语句:select password from tb_user whereusername=?根据用户名username 查询表tb_user中密码password字段,CAS会匹配用户输入的密码,如果匹配则通过;
注:可配置多个数据库
如果需要配置多个数据库,可以配置多个QueryDatabaseAuthenticationHandler和多个datasource
假如a_user中有一个用户:auser,b_user中有一个用户buser,这样你无论用哪一个用户登录,CAS就会先查a_user,如果用户名密码都正确,那么就通过,如果a_user中验证失败,那么CAS就会再查b_user,用户名密码都正确就算通过了,此时不正确,就算这次登录验证没通过。
添加相关的jar包
需要在web项目的lib下添加两个包:cas-server-support-jdbc-x.x.x.jar 和 mysql-connector-java-x.x.x-bin.jar(具体版本号根据情况而定)
按如下配置好后,进入CAS登录页,用户名密码需要通过查询数据库来认证,输入用户名admin,密码123,才可登录成功;如果输入用户名admin,密码admin是不能登录成功。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

To avoid PHP database connection errors, follow best practices: check for connection errors and match variable names with credentials. Use secure storage or environment variables to avoid hardcoding credentials. Close the connection after use to prevent SQL injection and use prepared statements or bound parameters.
