Spirng Acegi 身份认证连载2

      构建基于数据库权限信息存储

Spirng Acegi 身份认证连载 的基础上进行配置文件的修改。

    步骤1创建数据库

数据库的脚本如下:

DROP DATABASE IF EXISTS SpringSecurityDB;
CREATE DATABASE SpringSecurityDB DEFAULT CHARACTER SET utf8;
USE SpringSecurityDB;
CREATE TABLE T_USER (
   USER_ID INTEGER NOT NULL AUTO_INCREMENT,
   USERNAME VARCHAR(30) NOT NULL,
   PASSWORD VARCHAR(30) DEFAULT NULL,
   STATUS TINYINT(1) NOT NULL DEFAULT '0',
   PRIMARY KEY (`USER_ID`),
   UNIQUE KEY `USERNAME` (`USERNAME`)
);
CREATE TABLE T_USER_PRIV (
  USER_ID INTEGER NOT NULL DEFAULT '0',
  PRIV_NAME VARCHAR(30) DEFAULT NULL,
  PRIMARY KEY (USER_ID, PRIV_NAME)
);

INSERT INTO T_USER (USER_ID, USERNAME, PASSWORD, STATUS) VALUES
  (1,'tom','tom',1),
  (2,'john','john',1);

INSERT INTO T_USER_PRIV (USER_ID, PRIV_NAME) VALUES
  (1,'PRIV_1'),
  (1,'PRIV_2'),
  (1,'PRIV_COMMON'),
  (2,'PRIV_1'),
  (2,'PRIV_COMMON');
COMMIT;

步骤2 修改applicationContext-acegi-plugin.xml配置文件的修改

<bean id="daoAuthenticationProvider" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">
  <property name="userDetailsService" ref="userDetailsService"/>
</bean>

<bean id="userDetailsService" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">
        <property name="userMap">
            <value>
               john=john,PRIV_COMMON,PRIV_1
               tom=tom,PRIV_COMMON,PRIV_1,PRIV_2
               peter=peter,disabled,PRIV_COMMON,PRIV_1
            </value>
        </property>
    </bean>

修改为

<bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
  <property name="userDetailsService" ref="userDetailsService"/>
</bean>

<bean id="userDetailsService" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
    <property name="dataSource" ref="dataSource"/>
    <property name="usersByUsernameQuery">
       <value>
          <![CDATA[ SELECT u.USERNAME,u.PASSWORD,1 FROM T_USER u where u.STATUS = 1 AND u.USERNAME = ?]]>
       </value>
    </property>
    <property name="authoritiesByUsernameQuery">
       <value>
          <![CDATA[SELECT u.USERNAME,p.PRIV_NAME FROM  T_USER u,T_USER_PRIV p
          WHERE u.USER_ID = p.USER_ID and u.USERNAME=?]]>
       </value>
    </property>
</bean>

步骤3 修改applicationContext.xml配置文件的修改

<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
        <property name="driver" value="com.mysql.jdbc.Driver" />
        <property name="driverUrl">
            <value>jdbc:mysql://127.0.0.1:3306/SpringSecurityDB?user=root&amp;password=kingsoft
            </value>
        </property>
        <property name="user" value="root" />
        <property name="password" value="kingsoft" />
        <property name="alias" value="Pool_dbname" />
        <property name="prototypeCount" value="0" />
        <property name="maximumConnectionCount" value="50" />
        <property name="minimumConnectionCount" value="2" />
        <property name="simultaneousBuildThrottle" value="50" />
        <property name="houseKeepingTestSql" value="select CURRENT_DATE" />
    </bean>

步骤4、项目lib中添加jar

        proxool-0.9.1.jar、proxool-cglib.jar和mysql.jar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值