Spring Security3.1

來源:互聯網
上載者:User
  [置頂] Spring Security3.1 最新配置執行個體 分類: spring 2011-04-28 11:21  72171人閱讀  評論(159)  收藏  舉報 security spring resources null interceptor object

這幾天學習了一下Spring Security3.1,從官網下載了Spring Security3.1版本進行練習,經過多次嘗試才摸清了其中的一些原理。本人不才,希望能協助大家。還有,這次我第二次寫部落格啊,文體不是很行。希望能讓觀看者不產生疲憊的感覺,我已經心滿意足了。

一、資料庫結構

     先來看一下資料庫結構,採用的是基於角色-資源-使用者的許可權管理設計。(MySql資料庫)

    為了節省篇章,只對比較重要的欄位進行注釋。

    1.使用者表Users

    CREATE TABLE `users` (

       -- 帳號是否有限 1. 是 0.否
       `enable` int(11) default NULL,
       `password` varchar(255) default NULL,
       `account` varchar(255) default NULL,
       `id` int(11) NOT NULL auto_increment,
       PRIMARY KEY  (`id`)
    )

 

   2.角色表Roles

   CREATE TABLE `roles` (
     `enable` int(11) default NULL,
     `name` varchar(255) default NULL,
     `id` int(11) NOT NULL auto_increment,
     PRIMARY KEY  (`id`)
   )

 

   3 使用者_角色表users_roles

   CREATE TABLE `users_roles` (

     --使用者表的外鍵
     `uid` int(11) default NULL,

     --角色表的外鍵
     `rid` int(11) default NULL,
     `urId` int(11) NOT NULL auto_increment,
     PRIMARY KEY  (`urId`),
     KEY `rid` (`rid`),
     KEY `uid` (`uid`),
    CONSTRAINT `users_roles_ibfk_1` FOREIGN KEY (`rid`) REFERENCES `roles` (`id`),
    CONSTRAINT `users_roles_ibfk_2` FOREIGN KEY (`uid`) REFERENCES `users` (`id`)
   )

 

   4.資源表resources

   CREATE TABLE `resources` (
     `memo` varchar(255) default NULL,

     -- 許可權所對應的url地址
     `url` varchar(255) default NULL,

     --優先權
     `priority` int(11) default NULL,

     --類型
     `type` int(11) default NULL,

     --許可權所對應的編碼,例201代表發表文章
     `name` varchar(255) default NULL,
     `id` int(11) NOT NULL auto_increment,
     PRIMARY KEY  (`id`)
   )

 

   5.角色_資源表roles_resources

    CREATE TABLE `roles_resources` (
      `rsid` int(11) default NULL,
      `rid` int(11) default NULL,
      `rrId` int(11) NOT NULL auto_increment,
      PRIMARY KEY  (`rrId`),
      KEY `rid` (`rid`),
      KEY `roles_resources_ibfk_2` (`rsid`),
      CONSTRAINT `roles_resources_ibfk_2` FOREIGN KEY (`rsid`) REFERENCES `resources` (`id`),
      CONSTRAINT `roles_resources_ibfk_1` FOREIGN KEY (`rid`) REFERENCES `roles` (`id`)
      )

 

  二、系統配置

   所需要的jar包,請自行到官網下載,我用的是Spring Security3.1.0.RC1版的。把dist下的除了源碼件包匯入就行了。還有那些零零碎的   資料庫驅動啊,log4j.jar等等,我相信在用Spring Security之前,大家已經會的了。

  1) web.xml

  [xhtml]  view plain copy <!-- Spring -->     <context-param>       <param-name>contextConfigLocation</param-name>       <param-value>classpath:applicationContext.xml,classpath:applicationContext-security.xml</param-value>     </context-param>                 <listener>       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>     </listener>     <!-- 許可權 -->     <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>       

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.