CAS5.2X Single Sign-on (ii) CAS server connection database

Source: Internet
Author: User
Tags cas

The previous section should have told you how to build a CAS server, but the building can use it? Where is our user verification now? Which default user name and password are there?

This section tells you how to use the CAS server to connect to our own user database, after all, no company user is written to die on the configuration file. OK, so let's go, this way I'll use MySQL as an application. Before the 5.0 version of the configuration database for authentication is directly injected into the XML corresponding beans and drivers, but after 5.0 changed a bit, using the configuration file to achieve the operation of the database. Perhaps you will ask why just configure a few configurations can reach the role of the operational database, because CAS has actually helped us to implement a lot of classes, and configuration file configuration is to let him find the corresponding class to execute, such as you configure the database of ordinary authentication, he went to find the appropriate method, if you configure the encryption, He's going to look for something else, and if you want to customize it, you're going to define it in his way.

  

OK, just look at the following: Before we put CAs into Tomcat run, there is a file called Application.properties, our configuration will be written in the inside, as shown in
    The last line we see is the default password set, which is configured with the port number, certificate, and so on. This is not of any use to us for the time being. We will directly see how to connect to the database for user authentication. In fact, the official documents of these things have been given, you can check it yourself.


To connect to the database, you must import some necessary packages, such as database driver, MySQL connection and other packages, these maven can be found on the internet, my side of the example I use the pom file

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelversion>4.0.0</modelversion>    <groupId>Fxma</groupId>    <Artifactid>Word2html</Artifactid>    <version>0.0.1-snapshot</version>    <Packaging>Jar</Packaging>    <name>Word2html</name>    <URL>http://maven.apache.org</URL>    <Properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>          <cas.version>5.2.4</cas.version>      </Properties>    <Dependencies>        <Dependency>            <groupId>Org.apereo.cas</groupId>            <Artifactid>Cas-server-support-jdbc-drivers</Artifactid>            <version>${cas.version}</version>        </Dependency>        <Dependency>            <groupId>Org.apereo.cas</groupId>            <Artifactid>Cas-server-support-jdbc</Artifactid>            <version>${cas.version}</version>        </Dependency> <Dependency>            <groupId>Mysql</groupId>            <Artifactid>Mysql-connector-java</Artifactid>            <version>6.0.6</version></Dependency>            </Dependencies></Project>

And then in the configuration file with the following simple configuration to reach the database access

Cas. authn. jdbc. query[0]. url=jdbc:mysql://127.0.0.1:3306/test?useunicode=true&characterencoding=utf-8&autoreconnect=true&usessl=falsecas. authn. jdbc. query[0]. User=rootcas. authn. jdbc. query[0] .password=rootcas.authn .jdbc.query[0].sql=select * from test_table where Name=?cas.authn.jdbc.query[0].fieldpassword=pdcas.authn.query[0]com.mysql .jdbc               
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

When you introduce this, you need to delete the previous default password.
At this time we will regenerate a war package when we proceed to the MVN Clean Package command, we will put this new war package into Tomcat and start to see as shown

We use the data inside the database to log in.
We are now using ciphertext password, more often we use encrypted password, and CAS also provide us with these, such as the simplest MD5, add salt and SHA, etc., CAs are provided as long as they add in the configuration file can be, but many times our password is not simple these, At this time, we need to customize the encryption, in fact, the configuration file has a Cas.authn.jdbc.query[0].passwordencoder.type This property is the role of our own custom encryption to use. Just implement Passwordencoder (or other) this interface, and then write your encryption logic inside.

CAS5.2X Single Sign-on (ii) CAS server connection database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.