Implementation of SSO by Yale CAS +. Net client (4)

Source: Internet
Author: User
Tags management studio sql server management sql server management studio
    • Part 1: install and configure Tomcat
    • Part 2: install and configure cas
    • Part 3: Implement ASP. NET webform Client
Part 4: Implement database-based Identity Authentication

1. download microsoft JDBC driver for SQL Server.

(1) Microsoft JDBC driver 4.0 for SQL Server: http://www.microsoft.com/zh-cn/download/details.aspx? Id = 11774

Two types of format files are available for download on the website. One is a self-decompressed exeformat file, and the other is a compressed file in the tar.gz format. You can download one of the two formats. After decompression, you can obtain two jar files: sqljdbc. jar and sqljdbc4.jar.

(2) because I am using SQL Server 2012,Sqljdbc4.jar"Copy to the" % tomcat_home % \ webapps \ CAS \ WEB-INF \ Lib "folder.

(3rd) in the second generation of this series, I have mentioned and downloaded and decompressed cas-server-3.5.1-release.zip from the casnet site. Find "M" in the extracted FileOdules \ cas-server-support-jdbc-3.5.1.jar ",Copy one of them to the "% tomcat_home % \ webapps \ CAS \ WEB-INF \ Lib" folder.

 

2. Create a database for Identity Authentication

(1) start SQL Server Management studio, create a database named "usersdb", and create the table "users". The fields are as follows:

(2) enter several test data in the table:

 

3. Configure CAS for database-based Identity Authentication

(1) Start the text editing tool as administrator and open "% atat_home % \ webapps \ CAS \ WEB-INF \ deployerconfigcontext. xml ". Find the followingCode

 
<BeanID= "Authenticationmanager"Class= "Org. JASIG. Cas. Authentication. authenticationmanagerimpl">

(2) Insert the SQL Server JDBC data source configuration information before the code segment:

 <  Bean  ID  = "Datasource" Class  = "Org. springframework. JDBC. datasource. drivermanagerdatasource"  >      <  Property  Name  = "Driverclassname"  Value  = "Com. Microsoft. sqlserver. JDBC. sqlserverdriver"  > </  Property  >      <  Property  Name = "Url"  Value  = "JDBC: sqlserver: // 192.168.0.123: 1433; databasename = usersdb"  > </  Property  >      <  Property  Name  = "Username"  Value  = "Sa"  > </  Property  >      < Property  Name  = "Password"  Value  = "Yourpassword"  > </  Property  >  </  Bean  > 

As shown in:

(3) Find the following configuration information:

<BeanClass= "Org. JASIG. Cas. Authentication. handler. Support. simpletestusernamepasswordauthenticationhandler" />

This configuration information uses simpletestusernamepasswordauthenticationhandler to verify the user. That is, if the default user name and password are the same, the authentication succeeds. If the user name and password are different, the logon fails. We need to replace it with the configuration information based on database verification.

First, comment out the above configuration information and insert the following configuration information under it:

 <  Bean  Class  = "Org. JASIG. Cas. adaptors. JDBC. querydatabaseauthenticationhandler"  >      <  Property Name  = "SQL"  Value  = "Select password from users where username =? "   />      <  Property  Name  = "Datasource"  Ref  = "Datasource"   />  </  Bean  > 

:

Note: If you are installing SQL Server 2012, the default TCP/IP access protocol will not be enabled, so you cannot access SQL server data through IP addresses, the solution is to start the SQL Server Configuration Manager and enable TCP/IP in it. After enabling it, remember to restart the SQL Server service for the setting to take effect. :

(4) Save the changes to '% atat_home % \ webapps \ CAS \ WEB-INF \ deployerconfigcontext. xml.

(5) restart the Tomcat service.

 

4. Test Database-based Identity Authentication

Run the previously debugged webform from the clientProgram(See Yale CAS +. Net client for SSO (3). Enter the username "admin" and password "123" to test whether the logon is successful. If everything is configured properly, you can see the interface after logging on to the program, as shown in:

 

5. Further improve the logon experience

In actual use, you may want to log on in multiple ways: User Name, password, email address, password, mobile phone number, password. How can you solve the problem of multiple login methods? In the subsequent sections, we will discuss in depth how to solve such problems.

 

To be continued...

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.