Tomcat enables BASIC authentication, using database authentication, password MD5 encryption __ Database

Source: Internet
Author: User
Tags auth md5 md5 digest md5 encryption table name tomcat

Prepare the database:
Table name
Users
Column Name value
Username User11
Password 698d51a19d8a121ce581499d7b701668
is the MD5 32-bit http://md5jiami.51240.com/of password 111

Table name
Users-roles
Column Name value
Username User11
RoleName Roles22

===================================================================================
Modify Apache configuration file, enable JDBC database realm, Support MD5 Digest encryption password
D:\apache-tomcat-7.0.62\conf\context.xml

<realm classname= "Org.apache.catalina.realm.JDBCRealm"  
                drivername= "Com.mysql.jdbc.Driver
                " Connectionurl= "Jdbc:mysql://xxxxxx:3306/spiis"
                connectionname= "root" connectionpassword= "1q2w3e4r"
                usertable= "Users" usernamecol= "Usercode" 
                usercredcol= "password"  
                userroletable= "Users-roles"
                digest= "MD5"
                rolenamecol= "RoleName"/>

Modified Apache example application examples, using Basic authentication, role ROLES22 users can access/jsp/security/protected/* resources

Web. XML changed to Basic,role to Roles22

<auth-constraint> <!--Anyone with one of the listed roles could access this area--and
         <role-name>t omcat</role-name>
         <role-name>roles22</role-name>
      </auth-constraint>
    </ Security-constraint>

    <!--Default Login configuration uses form-based Authentication--
    < login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>example form-based Authentication area</realm-name>
    </login-config>

    <!--Security roles referenced by the This web Application-
    <security-role>
      <role-name>roles22</role-name>
    </ security-role>
    <security-role>
      <role-name>tomcat</role-name>
    </ Security-role>

Copy Mysql-connector-java-5.1.34-bin.jar to

D:\apache-tomcat-7.0.62-authentication-mysql\lib

Browser access URL, enter user name password user11/111 for identity authentication
http://localhost:8088/examples/jsp/security/protected/

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.