<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Spring Security 使用數據庫用戶進行認證

      本文參考或摘錄自:http://haohaoxuexi.iteye.com/blog/2157769

      本文使用Spring Security自帶的方式連接數據庫對用戶進行認證。

      1、Spring Security 默認的表腳本:

      /*
      Navicat MySQL Data Transfer
      
      Source Server         : localhost
      Source Server Version : 50621
      Source Host           : localhost:3306
      Source Database       : security
      
      Target Server Type    : MYSQL
      Target Server Version : 50621
      File Encoding         : 65001
      
      Date: 2014-12-10 15:49:04
      */
      
      SET FOREIGN_KEY_CHECKS=0;
      
      -- ----------------------------
      -- Table structure for authorities
      -- ----------------------------
      DROP TABLE IF EXISTS `authorities`;
      CREATE TABLE `authorities` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `username` varchar(20) DEFAULT NULL,
        `authority` varchar(50) DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
      
      -- ----------------------------
      -- Table structure for groups
      -- ----------------------------
      DROP TABLE IF EXISTS `groups`;
      CREATE TABLE `groups` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `groupName` varchar(50) DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
      
      -- ----------------------------
      -- Table structure for group_authorities
      -- ----------------------------
      DROP TABLE IF EXISTS `group_authorities`;
      CREATE TABLE `group_authorities` (
        `group_Id` int(11) NOT NULL AUTO_INCREMENT,
        `authority` varchar(50) DEFAULT NULL,
        PRIMARY KEY (`group_Id`)
      ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
      
      -- ----------------------------
      -- Table structure for group_members
      -- ----------------------------
      DROP TABLE IF EXISTS `group_members`;
      CREATE TABLE `group_members` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `userName` varchar(20) DEFAULT NULL,
        `group_Id` int(11) DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
      
      -- ----------------------------
      -- Table structure for users
      -- ----------------------------
      DROP TABLE IF EXISTS `users`;
      CREATE TABLE `users` (
        `id` int(8) NOT NULL AUTO_INCREMENT,
        `userName` varchar(20) DEFAULT NULL,
        `password` varchar(50) DEFAULT NULL,
        `enabled` tinyint(4) DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

      2、web.xml配置

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
               version="3.1">
          <filter>
              <filter-name>springSecurityFilterChain</filter-name>
              <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
          </filter>
          <filter-mapping>
              <filter-name>springSecurityFilterChain</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
          <context-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/dispatcher-servlet.xml,/WEB-INF/spring-security.xml</param-value>
          </context-param>
          <context-param>
              <param-name>log4jConfigLocation</param-name>
              <param-value>/WEB-INF/log4j.properties</param-value>
          </context-param>
          <context-param>
              <param-name>log4jRefreshInterval</param-name>
              <param-value>60000</param-value>
          </context-param>
          <listener>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          <listener>
              <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
          </listener>
          <servlet>
              <servlet-name>dispatcher</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <load-on-startup>1</load-on-startup>
          </servlet>
          <servlet-mapping>
              <servlet-name>dispatcher</servlet-name>
              <url-pattern>/</url-pattern>
          </servlet-mapping>
      </web-app>

      2、spring-security配置:

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:security="http://www.springframework.org/schema/security"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans.xsd
             http://www.springframework.org/schema/security
             http://www.springframework.org/schema/security/spring-security.xsd">
          <security:http auto-config="true">
              <security:intercept-url pattern="/**" access="ROLE_USER"></security:intercept-url>
          </security:http>
          <security:authentication-manager>
              <security:authentication-provider user-service-ref="userDetailsService">
                  <security:password-encoder hash="md5"></security:password-encoder>
              </security:authentication-provider>
          </security:authentication-manager>
      
          <bean id="userDetailsService" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
              <property name="dataSource" ref="dataSource"/>   --指定數據源
              <property name="enableGroups" value="true"/>
          </bean>
      </beans>

       說明:<security:authentication-provider ref="myAuthenticationProvider"/>是指使用實現了自己的AuthenticationProvider

      <security:authentication-provider user-service-ref="userDetailsService">是指定使用的UserDetailsService

      3、數據源配置:

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
          <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
              <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
              <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/security"></property>
              <property name="user" value="root"></property>
              <property name="password" value="root"></property>
              <property name="acquireIncrement" value="5"></property>  <!-- 當連接池中的連接用完時,C3P0一次性創建新連接的數目2 -->
              <property name="initialPoolSize" value="10"></property>  <!-- 初始化時創建的連接數,必須在minPoolSize和maxPoolSize之間 -->
              <property name="minPoolSize" value="5"></property>
              <property name="maxPoolSize" value="20"></property>
              <!-- 最大空閑時間,超過空閑時間的連接將被丟棄
              [需要注意:mysql默認的連接時長為8小時(28800)【可在my.ini中添加 wait_timeout=30(單位秒)設置連接超時】,這里設置c3p0的超時必須<28800]
              -->
              <property name="maxIdleTime" value="300"></property>
              <property name="idleConnectionTestPeriod" value="60"></property> <!-- 每60秒檢查連接池中的空閑連接 -->
              <property name="maxStatements" value="20"></property>  <!-- jdbc的標準參數  用以控制數據源內加載的PreparedStatement數量,但由于預緩存的Statement屬 于單個Connection而不是整個連接 -->
          </bean>
      </beans>

       

      posted @ 2014-12-10 15:56  tyb1222  閱讀(2584)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 免费看欧美日韩一区二区三区| 在线视频一区二区三区色| 中文字幕日韩有码第一页| 精品在免费线中文字幕久久| 国产av仑乱内谢| 亚洲日本欧美日韩中文字幕| 国产 麻豆 日韩 欧美 久久| 2019香蕉在线观看直播视频| 悠悠人体艺术视频在线播放| 亚洲精品无码高潮喷水A| 国内精品久久毛片一区二区| 粗壮挺进邻居人妻无码| 亚洲综合小说另类图片五月天| 亚洲AV无码午夜嘿嘿嘿| 蜜桃无码一区二区三区| 日韩av在线不卡一区二区| 美女把尿囗扒开让男人添| 中国凸偷窥xxxx自由视频| 日本一区二区三本视频在线观看| 日本道播放一区二区三区| 综合成人亚洲网友偷自拍| 小嫩批日出水无码视频免费| 亚洲av永久无码天堂影院| 国产精品亚洲一区二区三区| 磴口县| 亚洲中文字幕无码日韩精品| 中文字幕理伦午夜福利片| 嘉义县| 人妻在线中文字幕| 国产欧美日韩亚洲一区二区三区| 福利一区二区在线观看| 亚洲国产精品ⅴa在线观看| 成年女性特黄午夜视频免费看| 免费无码成人AV片在线| 亚洲中文字幕国产综合| 四虎国产精品成人免费久久| 久久香蕉国产线看观看怡红院妓院| 日本高清一区免费中文视频| 日韩中文字幕V亚洲中文字幕| 成人激情视频一区二区三区| 99RE6在线观看国产精品|