Apache Shiro Learning Note (v) Web integration using Jdbcrealm

Source: Internet
Author: User
Tags random seed

Ruchunli's work notes , a good memory is worse than a bad pen


Http://shiro.apache.org/web-features.html


The previous example is to put the user name or password and permissions information in the INI file, but the actual Web project development process, in fact, is generally user<--->role, role<-->permission the configuration of the association relationship, Each time you log on, load the permissions it has or determine its permissions every time you access it.


[Main] #默认是/login.jspauthc.loginurl=/loginroles.unauthorizedurl=/unauthorizedperms.unauthorizedurl=/ unauthorized#  Configuring the JDBC Database connection datasource=com.alibaba.druid.pool.druiddatasourcedatasource.driverclassname= Com.mysql.jdbc.driverdatasource.url=jdbc:mysql://localhost:3306/spring_testdatasource.username=root[email  protected]# jdbcrealmjdbcrealm= org.apache.shiro.realm.jdbc.jdbcrealmjdbcrealm.permissionslookupenabled = true#  Identity authentication jdbcrealm.authenticationquery=select  ' password '  FROM  ' users '  WHERE  ' username '  = ? AND is_delete =  ' 0 ' #  determine if there is a role jdbcrealm.userrolesquery=select  ' Role_name '  FROM  ' user_roles '  WHERE  ' username '  = ? and is_delete =   ' 0 ' #  determine if you have permission jdbcrealm.permissionsquery=select  ' permission '  FROM  ' roles_permissions '  WHERE  ' role_name '  = ? AND is_delete =  ' 0 ' #  Specify the data source jdbcrealm.datasource= $datasource#  Specifies the realms implementation of the SecurityManager securitymanager.realms= $jdbcRealm [urls]/login=anon/static/**=anon/role =authc,roles[admin]/permission=authc,perms["User:create"]/unauthorized=anon/logout=logout


Db

/** table structure for table  ' users '  */CREATE TABLE  ' users '   (    ' id '  int (one)  NOT NULL AUTO_INCREMENT COMMENT  ' primary key ',   ' Username '  varchar  DEFAULT NULL COMMENT  ' username ',   ' password '  varchar (  DEFAULT NULL COMMENT  ' password ',   ' Password_salt '  varchar (Ten)  default  NULL COMMENT  ' random seed used to generate password ',   ' create_by '  varchar ()  default null  COMMENT  ' creator ',   ' create_time '  datetime DEFAULT NULL COMMENT  ' Creation time ',   ' update_by '  varchar ( DEFAULT NULL COMMENT  ' Update People ',   ') Update_time '  datetime DEFAULT NULL COMMENT  ' update Time ',   ' Is_delete '  char (1 )  DEFAULT  ' 0 '  COMMENT  ' Remove logo (0: normal; 1: deleted) ',  primary key  (' id '))   Engine=innodb auto_increment=1 default charset=utf8;/** data for the table  ' users '  */insert   into  ' users ' (' id ', ' username ', ' password ', ' Password_salt ', ' create_by ', ' create_time ', ' update_by ', ' Update_time ', ' Is_delete ')  values  (1, ' lucl ', ' e10adc3949ba59abbe56e057f20f883e ', ' 123456 ', ' 1 ', ' 2016-07-29 10:40:55 ', ' 1 ', ' 2016-07-29 10:40:57 ', ' 0 ');insert  into  ' users ' (' id ', ' Username ', ' password ', ' Password_salt ', ' create_by ', ' create_time ', ' update_by ', ' update_time ', ' is_delete '   values  (2, ' Wang ', ' e10adc3949ba59abbe56e057f20f883e ', ' 123456 ', ' 1 ', ' 2016-07-29 10:41:30 ', ' 1 ', ' 2016-07-29 10:41:32 ', ' 0 ');/** table structure for table  ' user_roles '  */ create table  ' User_roles '   (   ' id '  int (one)  not null auto_increment  COMMENT  ' primary key ',   ' username '  varchar ( DEFAULT NULL COMMENT  ' username ') ,   ' Role_name '  varchar (&NB)sp;default null comment  ' role ',   ' create_by '  varchar ( default null)  COMMENT  ' creator ',   ' create_time '  datetime DEFAULT NULL COMMENT  ' Creation time ',   ' update_by '  varchar ( DEFAULT NULL COMMENT  ' Update People ',   ') Update_time '  datetime DEFAULT NULL COMMENT  ' update Time ',   ' Is_delete '  char (1 )  DEFAULT  ' 0 '  COMMENT  ' Remove logo (0: normal; 1: deleted) ',  primary key  (' id '))   Engine=innodb auto_increment=2 default charset=utf8;/** data for the table   ' user_roles '  */insert  into  ' user_roles ' (' id ', ' username ', ' role_name ', ' create_by ', ' Create_time ', ' update_by ', ' update_time ', ' Is_delete ')  values  (1, ' lucl ', ' admin ', ' 1 ', ' 2016-07-29  10:44:33 ', ' 1 ', ' 2016-07-29 10:44:36 ', ' 0 ');/** table structure for table  ' Roles_ Permissions ' &NBSP;*/CREATE&NBsp table  ' roles_permissions '   (   ' id '  int (one)  not null auto_increment  COMMENT  ' primary key ',   ' Role_name '  varchar ( DEFAULT NULL COMMENT  ' characters ') ,   ' permission '  varchar ( DEFAULT NULL COMMENT  ' Rights ',   ' Create_ By '  varchar  DEFAULT NULL COMMENT  ' creator ',   ' Create_time '  datetime  DEFAULT NULL COMMENT  ' creation time ',   ' update_by '  varchar ( DEFAULT  null comment  ' Update people ',   ' update_time '  datetime DEFAULT NULL COMMENT  ' Update time ',   ' Is_delete '  char (1)  DEFAULT  ' 0 '  COMMENT  ' Delete logo (0: normal; 1: deleted) ',   PRIMARY KEY  (' id '))  engine=innodb auto_increment=4 default charset=utf8;/* * data for the table  ' roles_permissions '  */insert  into  ' Roles_ Permissions ' (' id ', ' rOle_name ', ' permission ', ' create_by ', ' create_time ', ' update_by ', ' update_time ', ' Is_delete ')  values  (1, ' Admin ', ' user:* ', ' 1 ', ' 2016-07-29 10:45:54 ', ' 1 ', ' 2016-07-29 10:45:57 ', ' 0 '); insert  into   ' roles_permissions ' (' id ', ' role_name ', ' permission ', ' create_by ', ' create_time ', ' update_by ', ' update_time ', ' Is_delete ')  values  (2, ' admin ', ' system:edit:1 ', ' 1 ', ' 2016-07-29 10:46:08 ', ' 1 ', ' 2016-07-29  10:46:10 ', ' 0 ');insert  into  ' roles_permissions ' (' id ', ' role_name ', ' permission ', ' create_by ', ' Create_time ', ' update_by ', ' update_time ', ' Is_delete ')  values  (3, ' audit ', ' system:log:* ', ' 1 ', ' 2016-07-29  10:46:45 ', ' 1 ', ' 2016-07-29 10:46:49 ', ' 0 ');


Xml

<context-param> <param-name>shiroConfigLocations</param-name> <param-value>classpath: Shiro/jdbc-shiro.ini</param-value></context-param>

Servlet and JSP are the same as before.


This article is from the "world of Stuffy Gourd" blog, please be sure to keep this source http://luchunli.blog.51cto.com/2368057/1832590

Apache Shiro Learning Note (v) Web integration using Jdbcrealm

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.