|
sparta-紫杉 2011-4-2 22:00javascript
前言css
南朝《述異記》中記載,晉王質上山砍柴,見二童子下棋,未看完,斧柄已爛,下山回村,聞同代人都去世了,自已還未變老。 所以發出「山中方一日,世上幾千年」 的慨嘆。原文寥寥幾筆,讀來卻發人深省。html
另有宋朝周敦頤在《暮春即事》中也有詩云:雙雙瓦雀行書案,點點楊花入硯池。閒坐小窗讀周易,不知春去幾多時。java
上述古文或古詩中對於時間的論述最符合我如今的感覺。已經整整十五日,對於Spring Serurity3的研究終於能夠告一個段落了。node
感受這過往的十五日彷彿一瞬間而過,我沉浸在此中,一種強烈的求知願望使我樂此不疲。到今天爲止,終於將一種版本調通,能夠正常使用了。 再回頭看時,樓下的小公園裏已經開放了一叢叢黃色的花朵,整齊的柳樹叢林裏,已被春風剪出嫩綠的風景。 再回頭看本身其間的經歷,有幾多所得作爲鋪墊,全部的痛苦和疲憊已經煙消雲散了。 欣喜之餘整理一下,一來梳理一下本身的認知,進一步深刻的理解;二來能夠記錄下來做爲參考。git
使用Spring Security3的四種方法概述程序員
那麼在Spring Security3的使用中,有4種方法:web
一種是所有利用配置文件,將用戶、權限、資源(url)硬編碼在xml文件中,已經實現過,並通過驗證;ajax
二種是用戶和權限用數據庫存儲,而資源(url)和權限的對應採用硬編碼配置,目前這種方式已經實現,並通過驗證。算法
三種是細分角色和權限,並將用戶、角色、權限和資源均採用數據庫存儲,而且自定義過濾器,代替原有的FilterSecurityInterceptor過濾器, 並分別實現AccessDecisionManager、InvocationSecurityMetadataSourceService和UserDetailsService,並在配置文件中進行相應配置。 目前這種方式已經實現,並通過驗證。
四是修改spring security的源代碼,主要是修改InvocationSecurityMetadataSourceService和UserDetailsService兩個類。 前者是將配置文件或數據庫中存儲的資源(url)提取出來加工成爲url和權限列表的Map供Security使用,後者提取用戶名和權限組成一個完整的(UserDetails)User對象,該對象能夠提供用戶的詳細信息供AuthentationManager進行認證與受權使用。 該方法理論上可行,可是比較暴力,也沒有時間實現,未驗證,之後再研究。
說明一下,我目前調通的環境爲: java1.6 + struts2.1.6 + spring3.0.1 + hibernate3.3.1 + spring security3.0.2 + oracle9i + weblogic10.3, 順便提一下,目前(2011-4-2)serutity的最新版本爲3.1,比較穩定的版本爲3.0.5和2.0.6。
固然在進行spring security3的下面4種方法介紹以前,先假定SSH2的環境已經配置完畢,進入正常開發的過程,而且已經導入 spring security3.0.2的5個jar包,分別爲: spring-security-acl-3.0.2.RELEASE.jar spring-security-config-3.0.2.RELEASE.jar spring-security-core-3.0.2.RELEASE.jar spring-security-taglibs-3.0.2.RELEASE.jar spring-security-web-3.0.2.RELEASE.jar 固然還有其餘相關的jar包,在此再也不贅述。
第一種方法
第一種方法比較簡單,可參考Spring Security自帶的例子spring-security-samples-tutorial-3.0.2.RELEASE。 這裏給出下載網址:http://www.springsource.com/download/community?sid=1087087,不過在下載以前必須填寫相應的用戶信息,才容許下載。各類版本號的都可如下載。
在spring-security-samples-tutorial-3.0.2.RELEASE的例子裏,硬編碼的配置請參見applicationContext-security.xml文件中的內容。 裏面配置了用戶名、通過MD5加密後的密碼密文、相關的權限,以及與權相對應的訪問資源(URL)。還有對於Session超時時的處理。 特別是由於版本號爲3.0.2,所以還增長了對錶達式的配置演示,具體內容請參見該例子。
固然你最好運行起該例子來,感覺一下,你能夠直接將下載下來的解壓縮後的文件夾中找到spring-security-samples-tutorial-3.0.2.RELEASE.war文件,而後拷貝到Tomcat的安裝目錄下的\webapps文件夾下,而後運行Tomcat的服務器,服務器在啓動過程當中,會自動解開該war文件,在IE內輸入http://localhost:8080/webapps/spring-security-samples-tutorial-3.0.2.RELEASE 就能夠運行該系統了。在此再也不贅述。
第二種方法
第二種方法的代碼以下:
使用到的兩個表,用戶表和權限表的SQL語句。將用戶和權限以數據庫進行存儲。
create
table
USERS(
USERNAME
VARCHAR2
(
50
)
not
null
,
PASSWORD
VARCHAR2
(
50
)
not
null
,
ENABLED
NUMBER
(
1
)
not
null
,
USERNAMECN
VARCHAR2
(
50
),
primary
key
( username )
)
![](http://static.javashuo.com/static/loading.gif)
create
table
AUTHORITIES(
USERNAME
VARCHAR2
(
50
)
not
null
,
AUTHORITY
VARCHAR2
(
50
)
not
null
)
-- 外鍵使用戶和權限相聯。
Create
/
Recreate
primary
,
unique
and
foreign
key
constraints
alter
table
AUTHORITIES
add
constraint
FK_AUTHORITIES_USERS
foreign
key
(USERNAME)
references
USERS (USERNAME);
可插入幾條數據作爲試驗,首先插入用戶:
insert
into
users (USERNAME, PASSWORD, ENABLED, USERNAMECN, ROWID)
values
(
'
lxb
'
,
'
c7d3f4c857bc8c145d6e5d40c1bf23d9
'
,
1
,
'
登陸用戶
'
,
'
AAAHmhAALAAAAAOAAA
'
);
![](http://static.javashuo.com/static/loading.gif)
insert
into
users (USERNAME, PASSWORD, ENABLED, USERNAMECN, ROWID)
values
(
'
admin
'
,
'
ceb4f32325eda6142bd65215f4c0f371
'
,
1
,
'
系統管理員
'
,
'
AAAHmhAALAAAAAPAAA
'
);
![](http://static.javashuo.com/static/loading.gif)
insert
into
users (USERNAME, PASSWORD, ENABLED, USERNAMECN, ROWID)
values
(
'
user
'
,
'
47a733d60998c719cf3526ae7d106d13
'
,
1
,
'
普通用戶
'
,
'
AAAHmhAALAAAAAPAAB
'
);
再插入角色:
insert
into
authorities (USERNAME, AUTHORITY, ROWID)
values
(
'
admin
'
,
'
ROLE_PLATFORMADMIN
'
,
'
AAAHmjAALAAAAAgAAA
'
);
![](http://static.javashuo.com/static/loading.gif)
insert
into
authorities (USERNAME, AUTHORITY, ROWID)
values
(
'
admin
'
,
'
ROLE_SYSADMIN
'
,
'
AAAHmjAALAAAAAgAAB
'
);
![](http://static.javashuo.com/static/loading.gif)
insert
into
authorities (USERNAME, AUTHORITY, ROWID)
values
(
'
lxb
'
,
'
ROLE_LOGIN
'
,
'
AAAHmjAALAAAAAeAAA
'
);
![](http://static.javashuo.com/static/loading.gif)
insert
into
authorities (USERNAME, AUTHORITY, ROWID)
values
(
'
lxb
'
,
'
ROLE_LOGINTOWELCOME
'
,
'
AAAHmjAALAAAAAeAAB
'
);
![](http://static.javashuo.com/static/loading.gif)
insert
into
authorities (USERNAME, AUTHORITY, ROWID)
values
(
'
user
'
,
'
ROLE_USER
'
,
'
AAAHmjAALAAAAAgAAC
'
);
第二種方法之密碼加密
可能要有人要問,用戶表裏面的密碼是如何取得的呢?這個密碼是經過MD5進行加密過的,而且以用戶名作爲了鹽值,最後就成爲32位數字這個樣子,這個你能夠參見下面applicationContext-Security.xml中的password-encoder和salt-source的配置就會明白。 那麼在spring security3中是如何加密的呢?當咱們設置了pawwrod-encoder和salt-source以後,Spring Security3會根據配置,採用相匹配的加密算法(好比設置了MD5加密算法)再加上salt-source進行加密,造成32位數字的密文。 好比用戶名爲yew,密碼爲yew1234,鹽值爲用戶名yew。那麼最後加密的明文爲「yew1234{yew}」,密文就爲「8fe2657d1599dba8e78a7a0bda8651bb」。
咱們在試驗過程當中,一般喜歡先將幾個經常使用的用戶及密碼插入數據庫進行試驗,這種狀況下如何獲得該用戶的密碼密文呢? 不妨試試我這個辦法,假設,用戶名爲user,密碼明文爲user369,並且在配置文件裏面設置了以MD5做爲加密算法,並以用戶名作爲鹽值。 那麼你能夠首先將各個信息組合成待加密的密碼明文, 應是 密碼明文 + { + 鹽值 + }, 那麼很明顯,上述user的密碼明文應當是:
user369{user}
拿上述的字串拷貝到 http://www.51240.com/md5jiami/ 網頁上的輸入框裏,點擊加密按鈕,下面便可生成32位數字的密碼密文。
哈哈,屢試不爽啊。這個方法要謹慎使用,通常人我不告訴他。
第二種方法之相關配置
將權限及資源(URL或Action)的關係配置在xml文件中,而且配置與Spring Security3相關的其餘配置:
一、applicationContext-Security.xml代碼:
<
b:beans
xmlns
="http://www.springframework.org/schema/security"
xmlns:b
="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-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd"
>
![](http://static.javashuo.com/static/loading.gif)
<
http
auto-config
="true"
access-denied-page
="/accessDenied.jsp"
>
<!--
不要過濾圖片等靜態資源,其中**表明能夠跨越目錄,*不能夠跨越目錄。
-->
<
intercept-url
pattern
="/**/*.jpg"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.png"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.gif"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.css"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.js"
filters
="none"
/>
<!--
登陸頁面和忘記密碼頁面不過濾
-->
<
intercept-url
pattern
="/login.jsp"
filters
="none"
/>
<
intercept-url
pattern
="/jsp/forgotpassword.jsp"
filters
="none"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
下面是對Action配置。表示具備訪問/unitsManager資源的用戶必須具備ROLE_PLATFORMADMIN的權限。
當用戶登陸時,SS3將用戶的全部權限從數據庫中提取出來,造成列表。 當用戶訪問該資源時,SS3將
登陸用戶的權限列表提出來跟下面配置的權限進行比對,如有,則容許訪問,若沒有,則給出AccessDeniedException。
-->
<
intercept-url
pattern
="/unitsManager"
access
="ROLE_PLATFORMADMIN"
/>
<
intercept-url
pattern
="/usersManager"
access
="ROLE_PLATFORMADMIN"
/>
![](http://static.javashuo.com/static/loading.gif)
<
intercept-url
pattern
="/horizontalQuery"
access
="ROLE_PLATFORMADMIN"
/>
<
intercept-url
pattern
="/verticalQuery"
access
="ROLE_PLATFORMADMIN"
/>
<
form-login
login-page
="/login.jsp"
authentication-failure-url
="/login.jsp?error=true"
default-target-url
="/index.jsp"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
"記住我"功能,採用持久化策略(將用戶的登陸信息存放在數據庫表中)
-->
<
remember-me
data-source-ref
="dataSource"
/>
<!--
檢測失效的sessionId,超時時定位到另一個URL
-->
<
session-management
invalid-session-url
="/sessionTimeout.jsp"
/>
</
http
>
![](http://static.javashuo.com/static/loading.gif)
<!--
注意可以爲authentication-manager 設置alias別名
-->
<
authentication-manager
alias
="authenticationManager"
>
<
authentication-provider
user-service-ref
="userDetailsManager"
>
<
password-encoder
ref
="passwordEncoder"
>
<!--
用戶名作爲鹽值
-->
<
salt-source
user-property
="username"
/>
</
password-encoder
>
</
authentication-provider
>
</
authentication-manager
>
![](http://static.javashuo.com/static/loading.gif)
</
b:beans
>
二、applicationContext.service.xml:
<
beans
xmlns
="http://www.springframework.org/schema/beans"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util
="http://www.springframework.org/schema/util"
xmlns:jee
="http://www.springframework.org/schema/jee"
xmlns:aop
="http://www.springframework.org/schema/aop"
xmlns:tx
="http://www.springframework.org/schema/tx"
xmlns:context
="http://www.springframework.org/schema/context"
xsi:schemaLocation
="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd"
>
<!--
定義上下文返回的消息的國際化。
-->
<
bean
id
="messageSource"
class
="org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<
property
name
="basename"
value
="classpath:org/springframework/security/messages_zh_CN"
/>
</
bean
>
![](http://static.javashuo.com/static/loading.gif)
<!--
事件監聽:實現了 ApplicationListener監聽接口,包括AuthenticationCredentialsNotFoundEvent 事件,
AuthorizationFailureEvent事件,AuthorizedEvent事件, PublicInvocationEvent事件
-->
<
bean
class
="org.springframework.security.authentication.event.LoggerListener"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
用戶的密碼加密或解密
-->
<
bean
id
="passwordEncoder"
class
="org.springframework.security.authentication.encoding.Md5PasswordEncoder"
/>
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
<!--
用戶詳細信息管理 : 數據源、用戶緩存、啓用用戶組功能。
-->
<
bean
id
="userDetailsManager"
class
="org.springframework.security.provisioning.JdbcUserDetailsManager"
>
<
property
name
="dataSource"
ref
="dataSource"
/>
<
property
name
="userCache"
ref
="userCache"
/>
</
bean
>
<
bean
id
="userCache"
class
="org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache"
>
<
property
name
="cache"
ref
="userEhCache"
/>
</
bean
>
<
bean
id
="userEhCache"
class
="org.springframework.cache.ehcache.EhCacheFactoryBean"
>
<
property
name
="cacheName"
value
="userCache"
/>
<
property
name
="cacheManager"
ref
="cacheManager"
/>
</
bean
>
<!--
緩存用戶管理
-->
<
bean
id
="cacheManager"
class
="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
spring security自帶的與權限有關的數據讀寫Jdbc模板
-->
<
bean
id
="jdbcTemplate"
class
="org.springframework.jdbc.core.JdbcTemplate"
>
<
property
name
="dataSource"
ref
="dataSource"
/>
</
bean
>
![](http://static.javashuo.com/static/loading.gif)
</
beans
>
三、web.xml:
<
web-app
version
="2.5"
xmlns
="http://java.sun.com/xml/ns/javaee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
<!--
設置log4j存放Log文件位置(經過spring統一進行管理)
-->
<
context-param
>
<
param-name
>
webAppRootKey
</
param-name
>
<
param-value
>
log.root
</
param-value
>
</
context-param
>
![](http://static.javashuo.com/static/loading.gif)
<!--
加載log4j的配置文件
-->
<
context-param
>
<
param-name
>
log4jConfigLocation
</
param-name
>
<
param-value
>
classpath:/log4j.properties
</
param-value
>
</
context-param
>
![](http://static.javashuo.com/static/loading.gif)
<!--
Spring默認刷新Log4j配置文件的間隔,單位爲millisecond
-->
<
context-param
>
<
param-name
>
log4jRefreshInterval
</
param-name
>
<
param-value
>
60000
</
param-value
>
</
context-param
>
![](http://static.javashuo.com/static/loading.gif)
<!--
Spring用於log4j初始化的監聽器
-->
<
listener
>
<
listener-class
>
org.springframework.web.util.Log4jConfigListener
</
listener-class
>
</
listener
>
![](http://static.javashuo.com/static/loading.gif)
<!--
加載Spring XML配置文件,Spring安全配置及各種資源文件,暫不加
/WEB-INF/applicationContext-security.xml,
-->
<
context-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
/WEB-INF/applicationContext*.xml,
classpath*:applicationContext.xml
</
param-value
>
</
context-param
>
![](http://static.javashuo.com/static/loading.gif)
<!--
spring監聽器的配置,用於在啓動Web容器時,自動裝配ApplicationContext的配置信息
-->
<
listener
>
<
listener-class
>
org.springframework.web.context.ContextLoaderListener
</
listener-class
>
</
listener
>
![](http://static.javashuo.com/static/loading.gif)
<!--
使用Spring中的過濾器解決在請求和應答中的中文亂碼問題
-->
<
filter
>
<
filter-name
>
characterEncodingFilter
</
filter-name
>
<
filter-class
>
org.springframework.web.filter.CharacterEncodingFilter
</
filter-class
>
<
init-param
>
<
param-name
>
encoding
</
param-name
>
<
param-value
>
gbk
</
param-value
>
</
init-param
>
<
init-param
>
<!--
強制轉換編碼(request和response均適用)
-->
<
param-name
>
ForceEncoding
</
param-name
>
<
param-value
>
true
</
param-value
>
</
init-param
>
</
filter
>
![](http://static.javashuo.com/static/loading.gif)
<
filter-mapping
>
<
filter-name
>
characterEncodingFilter
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
![](http://static.javashuo.com/static/loading.gif)
<!--
Spring Secutiry3.0.2的過濾器鏈配置
-->
<
filter
>
<
filter-name
>
springSecurityFilterChain
</
filter-name
>
<
filter-class
>
org.springframework.web.filter.DelegatingFilterProxy
</
filter-class
>
</
filter
>
![](http://static.javashuo.com/static/loading.gif)
<
filter-mapping
>
<
filter-name
>
springSecurityFilterChain
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
![](http://static.javashuo.com/static/loading.gif)
<!--
配置Struts2的FilterDispathcer的Filter
-->
<
filter
>
<
filter-name
>
struts2
</
filter-name
>
<
filter-class
>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</
filter-class
>
</
filter
>
![](http://static.javashuo.com/static/loading.gif)
<!--
struts2用以處理用戶Web請求的路徑模式
-->
<
filter-mapping
>
<
filter-name
>
struts2
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<!--
避免亂碼問題
-->
<
filter
>
<
filter-name
>
struts-cleanup
</
filter-name
>
<
filter-class
>
org.apache.struts2.dispatcher.ActionContextCleanUp
</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
struts-cleanup
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<!--
Spring刷新Interceptor防止內存泄漏
-->
<
listener
>
<
listener-class
>
org.springframework.web.util.IntrospectorCleanupListener
</
listener-class
>
</
listener
>
![](http://static.javashuo.com/static/loading.gif)
<!--
設置session 超時時間爲20分鐘
-->
<
session-config
>
<
session-timeout
>
20
</
session-timeout
>
</
session-config
>
![](http://static.javashuo.com/static/loading.gif)
<!--
系統歡迎頁面
-->
<
welcome-file-list
>
<
welcome-file
>
login.jsp
</
welcome-file
>
</
welcome-file-list
>
![](http://static.javashuo.com/static/loading.gif)
</
web-app
>
使人欣喜的是,整個Security配置過程當中,除了創建數據庫和編寫配置文件以外,不須要編寫任何的代碼。怎麼樣? 有點意思吧!
第二種方法中碰見的問題
固然,首次使用Spring serutiry,在整合的過程當中,我仍是碰見了很多問題,固然有些問題好比找不到類呀,包呀,和框架的整合呀等問題不做爲談論的重點。主要仍是探討Spring Security的配置和注意事項的問題。
我在其中碰到的對我印象最深的問題是,當徹底配置好以後,重啓Web服務器,卻發現Spring Security不能攔截任何的URL了,這使我感到驚詫,由於在去年時,我已經將該框架搭建完成,在當時正是使用的該種方法,而且在試驗是否可以攔截jsp文件時進行了確認是沒有問題的。
接下來我又整理了一下applicationContext-security.xml的文件才發現, 除了不須要進行檢測的圖片及登陸頁面以外,沒有對任何的資源和權限之間的對應關係進行配置,參見下面的代碼:
<
http
auto-config
="true"
access-denied-page
="/accessDenied.jsp"
>
<!--
不要過濾圖片等靜態資源,其中**表明能夠跨越目錄,*不能夠跨越目錄。
-->
<
intercept-url
pattern
="/**/*.jpg"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.png"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.gif"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.css"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.js"
filters
="none"
/>
<!--
登陸頁面和忘記密碼頁面不過濾
-->
<
intercept-url
pattern
="/login.jsp"
filters
="none"
/>
<
intercept-url
pattern
="/jsp/forgotpassword.jsp"
filters
="none"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
下面是對Struts2的Action請求時的配置。注意在前面加/,不然不會被SS3進行攔截驗證。
表示具備訪問/unitsManager資源的用戶必須具備ROLE_PLATFORMADMIN的權限。
當用戶登陸時,SS3將用戶的全部權限從數據庫中提取出來,造成列表。 當用戶訪問該資源時,
SS3將登陸用戶的權限列表提出來跟下面配置的權限進行比對,如有,則容許訪問,若沒有,
則給出AccessDeniedException。
<intercept-url pattern="/unitsManager" access="ROLE_PLATFORMADMIN" />
<intercept-url pattern="/usersManager" access="ROLE_PLATFORMADMIN" />
<intercept-url pattern="/horizontalQuery" access="ROLE_PLATFORMADMIN" />
<intercept-url pattern="/verticalQuery" access="ROLE_PLATFORMADMIN" />
-->
<
form-login
login-page
="/login.jsp"
authentication-failure-url
="/login.jsp?error=true"
default-target-url
="/index.jsp"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
"記住我"功能,採用持久化策略(將用戶的登陸信息存放在數據庫表中)
-->
<
remember-me
data-source-ref
="dataSource"
/>
<!--
檢測失效的sessionId,超時時定位到另一個URL
-->
<
session-management
invalid-session-url
="/sessionTimeout.jsp"
/>
</
http
>
這樣一來,spring security3就會認爲根本不須要對任何的URL或Action進行檢測(注意上面代碼中被註釋掉的4條配置)。 哈哈,當時這個問題深深動搖了我對Spring security的信心,花費了這麼多天的精力,倒是這樣的結果,當時就在考慮是否有更好的替代品。有點崩潰啊。 還好,深深地求知慾和征服欲讓我堅持下來了。 哈哈,這算不算Spring Security的一個Bug呢?沒有任何的權限與資源的配置,就認爲登陸後的用戶具備訪問任何資源的權限,提及來有點可怕哈。
固然,當我將上述代碼中被註釋的4條配置放開後,Spring security奇蹟般的恢復了活力。
接下來實現了jsp型URL的攔截以後,我又碰見了不能攔截action的狀況,不過通過屢次的配置和重啓服務試驗,終於發現,在配置Action與權限時,必定要在Action的路徑前面加「/」斜槓,不然,Spring Security就會對該請求的URL熟視無睹,無視它的存在,即便你在Action的先後加上*號進行匹配也不會起任何做用,哈哈,不由慨嘆Spring Security的牛脾氣。
第二種方法BTW
順便提一會兒,Spring Security3須要配置的過濾器是雙重的,首先在web.xml中配置一個過濾器代理,參見上述web.xml中的springSecurityFilterChain配置。 咱們一般設置過濾的url模式爲/*,就是說任何的url訪問都要進行過濾,工做量有點大哈。固然咱們能夠爲之設置不一樣的過濾url模式,好比.action、.do、.jsp等。這樣的話,遇到.action或.jsp或.do結尾的url訪問,Spring Security就會忽然站出來打截,如果其餘的訪問,Spring Security就會揮一揮手,瀟灑地讓你路過。 因此說,這個過濾器主要對大的方面進行攔截,一些細小的活兒,仍是要交給第二重過濾器。 就是說,這第一重過濾器是個總代理,他威武地管理着一個過濾器鏈。
那麼這第二重過濾器的配置,就是那些所謂的過濾器鏈,分別包括「記住我」、「登陸」、「註銷」、「url訪問」等的過濾器,這個過濾器依順序排開,造成一個過濾鏈條。具體攔截咱們明細Url的是一個叫作FilterInterCeptor的夥計,我認爲這個傢伙是在整個過濾器鏈條中是最重要的一個,由於咱們登陸系統以後,要訪問的任何資源都必須經得他的贊成。 那麼這第二重鏈條就設置在applicationContext-security.xml文件中的<http>元素下面。 什麼,你看不到? 忘記告訴你了,從spring security2開始,就使用了命名空間,若你在<http>中設置了auto="true",Spring Security就會在服務啓動時自動加載 全部的過濾器鏈,省事了吧!
第三種方法
固然,spring security3畢竟是西方國家的東西,以英文爲主,使用習慣和文化的差別共存,何況爲了適應大多數Web應用的權限管理,做者將Spring Security3打造的精簡而靈活。精簡指Spring Security3對用戶和權限的表設計的很是簡單,而且沒有采用數據庫來管理資源(URL)。這樣的話,對於咱們國人用戶來講,是個很大的遺憾,這個遺憾甚至可以影響到咱們對安全框架的選型。你想啊,在國內大多數項目中,均設置了比較複雜的權限控制,通常就會涉及到用戶、角色、權限、資源4張表,若要加上4張表之間的對應關係表3張,得有7張表才行。
得7張表才行,可是Spring Security3纔給咱們提供了2張最簡潔的表,這足以不能完成國人用戶的項目應用。那麼在對Spring Security3一無所知的狀況下, 咱們很容易就會放棄對該安全框架的選型。
還好,Spring Security3提供了靈活的擴展方法。具體應該擴展哪些類呢? 或者到底Spring Security3工做的流程如何,你不妨參看下面一篇文章,就會得到 一些啓示,網址爲:http://www.blogjava.net/youxia/archive/2008/12/07/244883.html , 哈哈,謝謝分享。
還有一個地址頗有價值, http://wenku.baidu.com/view/4ec7e324ccbff121dd368364.html ,我就參考着上面的介紹擴展了4個類。
不過我得提一下,原文的做者爲了考驗你的耐性和自信心,故意在代碼裏面賣了幾點小小的關子,所以如果徹底按照做者的原文代碼裝配起來的權限系統,是不會那麼順利地工做的,天下彷佛真是沒有不花費力氣的午飯!在裝配完成後,我也是通過九九八十一難的折磨,在用戶、角色、權限、資源的 「天下黃河九曲十八彎」裏面盤旋迂迴,終於到達了成功的彼岸。至此纔對Spring Security有了更深層次的理解,更加佩服做者的良苦用心。 哈哈。
並擴展了User類以增長其相關的各種其餘信息(如Email,職務,所在單位id等)。
相關的代碼以下(包含5個關鍵類):
/*
* @(#) MyFilterSecurityInterceptor.java 2011-3-23 上午07:53:03
*
* Copyright 2011 by Sparta
*/
![](http://static.javashuo.com/static/loading.gif)
package
avatar.base.security;
![](http://static.javashuo.com/static/loading.gif)
import
java.io.IOException;
![](http://static.javashuo.com/static/loading.gif)
import
javax.servlet.Filter;
import
javax.servlet.FilterChain;
import
javax.servlet.FilterConfig;
import
javax.servlet.ServletException;
import
javax.servlet.ServletRequest;
import
javax.servlet.ServletResponse;
![](http://static.javashuo.com/static/loading.gif)
import
org.springframework.security.access.SecurityMetadataSource;
import
org.springframework.security.access.intercept.AbstractSecurityInterceptor;
import
org.springframework.security.access.intercept.InterceptorStatusToken;
import
org.springframework.security.web.FilterInvocation;
import
org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
![](http://static.javashuo.com/static/loading.gif)
/**
* 該過濾器的主要做用就是經過spring著名的IoC生成securityMetadataSource。
* securityMetadataSource至關於本包中自定義的MyInvocationSecurityMetadataSourceService。
* 該MyInvocationSecurityMetadataSourceService的做用提從數據庫提取權限和資源,裝配到HashMap中,
* 供Spring Security使用,用於權限校驗。
* @author sparta 11/3/29
*
*/
![](http://static.javashuo.com/static/loading.gif)
public
class
MyFilterSecurityInterceptor
extends
AbstractSecurityInterceptor
implements
Filter
{
![](http://static.javashuo.com/static/loading.gif)
private FilterInvocationSecurityMetadataSource securityMetadataSource;
public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException{
FilterInvocation fi = new FilterInvocation( request, response, chain );
invoke(fi);
}
public FilterInvocationSecurityMetadataSource getSecurityMetadataSource(){
return this.securityMetadataSource;
}
public Class<? extends Object> getSecureObjectClass(){
return FilterInvocation.class;
}
![](http://static.javashuo.com/static/loading.gif)
public void invoke( FilterInvocation fi ) throws IOException, ServletException{
InterceptorStatusToken token = super.beforeInvocation(fi);
try{
fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
}finally{
super.afterInvocation(token, null);
}
}
@Override
public SecurityMetadataSource obtainSecurityMetadataSource(){
return this.securityMetadataSource;
}
public void setSecurityMetadataSource(FilterInvocationSecurityMetadataSource securityMetadataSource){
this.securityMetadataSource = securityMetadataSource;
}
public void destroy(){
}
public void init( FilterConfig filterconfig ) throws ServletException{
}
}
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
/*
* @(#) MyInvocationSecurityMetadataSourceService.java 2011-3-23 下午02:58:29
*
* Copyright 2011 by Sparta
*/
![](http://static.javashuo.com/static/loading.gif)
package
avatar.base.security;
![](http://static.javashuo.com/static/loading.gif)
import
java.util.ArrayList;
import
java.util.Collection;
import
java.util.HashMap;
import
java.util.Iterator;
import
java.util.List;
import
java.util.Map;
![](http://static.javashuo.com/static/loading.gif)
import
org.hibernate.Session;
import
org.hibernate.SessionFactory;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
import
org.springframework.security.access.ConfigAttribute;
import
org.springframework.security.access.SecurityConfig;
import
org.springframework.security.core.GrantedAuthority;
import
org.springframework.security.core.context.SecurityContextHolder;
import
org.springframework.security.core.userdetails.UserDetails;
import
org.springframework.security.web.FilterInvocation;
import
org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import
org.springframework.security.web.util.AntUrlPathMatcher;
import
org.springframework.security.web.util.UrlMatcher;
import
org.springframework.stereotype.Service;
![](http://static.javashuo.com/static/loading.gif)
import
avatar.base.security.dao.PubAuthoritiesResourcesHome;
![](http://static.javashuo.com/static/loading.gif)
/**
* 最核心的地方,就是提供某個資源對應的權限定義,即getAttributes方法返回的結果。 此類在初始化時,應該取到全部資源及其對應角色的定義。
*
*/
@Service
public
class
MyInvocationSecurityMetadataSourceService
implements
FilterInvocationSecurityMetadataSource
{
![](http://static.javashuo.com/static/loading.gif)
@Autowired
private PubAuthoritiesResourcesHome pubAuthoritiesResourcesHome;
![](http://static.javashuo.com/static/loading.gif)
private UrlMatcher urlMatcher = new AntUrlPathMatcher();
![](http://static.javashuo.com/static/loading.gif)
private static Map<String, Collection<ConfigAttribute>> resourceMap = null;
![](http://static.javashuo.com/static/loading.gif)
public MyInvocationSecurityMetadataSourceService() {
loadResourceDefine();
}
![](http://static.javashuo.com/static/loading.gif)
private void loadResourceDefine() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:applicationContext.xml");
![](http://static.javashuo.com/static/loading.gif)
SessionFactory sessionFactory = (SessionFactory) context
.getBean("sessionFactory");
![](http://static.javashuo.com/static/loading.gif)
Session session = sessionFactory.openSession();
![](http://static.javashuo.com/static/loading.gif)
String username = "";
String sql = "";
![](http://static.javashuo.com/static/loading.gif)
// 在Web服務器啓動時,提取系統中的全部權限。
sql = "select authority_name from pub_authorities";
![](http://static.javashuo.com/static/loading.gif)
List<String> query = session.createSQLQuery(sql).list();
![](http://static.javashuo.com/static/loading.gif)
/*
* 應當是資源爲key, 權限爲value。 資源一般爲url, 權限就是那些以ROLE_爲前綴的角色。 一個資源能夠由多個權限來訪問。
* sparta
*/
resourceMap = new HashMap<String, Collection<ConfigAttribute>>();
![](http://static.javashuo.com/static/loading.gif)
for (String auth : query) {
ConfigAttribute ca = new SecurityConfig(auth);
![](http://static.javashuo.com/static/loading.gif)
List<String> query1 = session
.createSQLQuery(
"select b.resource_string "
+ "from Pub_Authorities_Resources a, Pub_Resources b, "
+ "Pub_authorities c where a.resource_id = b.resource_id "
+ "and a.authority_id=c.authority_id and c.Authority_name='"
+ auth + "'").list();
![](http://static.javashuo.com/static/loading.gif)
for (String res : query1) {
String url = res;
/*
* 判斷資源文件和權限的對應關係,若是已經存在相關的資源url,則要經過該url爲key提取出權限集合,將權限增長到權限集合中。
* sparta
*/
if (resourceMap.containsKey(url)) {
![](http://static.javashuo.com/static/loading.gif)
Collection<ConfigAttribute> value = resourceMap.get(url);
value.add(ca);
resourceMap.put(url, value);
} else {
Collection<ConfigAttribute> atts = new ArrayList<ConfigAttribute>();
atts.add(ca);
resourceMap.put(url, atts);
}
![](http://static.javashuo.com/static/loading.gif)
}
![](http://static.javashuo.com/static/loading.gif)
}
![](http://static.javashuo.com/static/loading.gif)
}
![](http://static.javashuo.com/static/loading.gif)
@Override
public Collection<ConfigAttribute> getAllConfigAttributes() {
![](http://static.javashuo.com/static/loading.gif)
return null;
}
![](http://static.javashuo.com/static/loading.gif)
// 根據URL,找到相關的權限配置。
@Override
public Collection<ConfigAttribute> getAttributes(Object object)
throws IllegalArgumentException {
![](http://static.javashuo.com/static/loading.gif)
// object 是一個URL,被用戶請求的url。
String url = ((FilterInvocation) object).getRequestUrl();
int firstQuestionMarkIndex = url.indexOf("?");
![](http://static.javashuo.com/static/loading.gif)
if (firstQuestionMarkIndex != -1) {
url = url.substring(0, firstQuestionMarkIndex);
}
![](http://static.javashuo.com/static/loading.gif)
Iterator<String> ite = resourceMap.keySet().iterator();
![](http://static.javashuo.com/static/loading.gif)
while (ite.hasNext()) {
String resURL = ite.next();
if (urlMatcher.pathMatchesUrl(url, resURL)) {
![](http://static.javashuo.com/static/loading.gif)
return resourceMap.get(resURL);
}
}
![](http://static.javashuo.com/static/loading.gif)
return null;
}
![](http://static.javashuo.com/static/loading.gif)
@Override
public boolean supports(Class<?> arg0) {
![](http://static.javashuo.com/static/loading.gif)
return true;
}
![](http://static.javashuo.com/static/loading.gif)
}
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
/*
* @(#) MyUserDetailsService.java 2011-3-23 上午09:04:31
*
* Copyright 2011 by Sparta
*/
![](http://static.javashuo.com/static/loading.gif)
package
avatar.base.security;
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
import
java.util.ArrayList;
import
java.util.Collection;
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
import
javax.sql.DataSource;
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.dao.DataAccessException;
import
org.springframework.security.core.GrantedAuthority;
import
org.springframework.security.core.userdetails.User;
import
org.springframework.security.core.userdetails.UserCache;
import
org.springframework.security.core.userdetails.UserDetails;
import
org.springframework.security.core.userdetails.UserDetailsService;
import
org.springframework.security.core.userdetails.UsernameNotFoundException;
import
org.springframework.stereotype.Service;
![](http://static.javashuo.com/static/loading.gif)
import
avatar.base.security.dao.PubAuthoritiesResourcesHome;
import
avatar.base.security.dao.PubUsersHome;
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
/**
*該類的主要做用是爲Spring Security提供一個通過用戶認證後的UserDetails。
*該UserDetails包括用戶名、密碼、是否可用、是否過時等信息。
*sparta 11/3/29
*/
@Service
public
class
MyUserDetailsService
implements
UserDetailsService
{
![](http://static.javashuo.com/static/loading.gif)
@Autowired
private PubUsersHome pubUsersHome;
@Autowired
private PubAuthoritiesResourcesHome pubAuthoritiesResourcesHome;
@Autowired
private DataSource dataSource;
@Autowired
private UserCache userCache;
![](http://static.javashuo.com/static/loading.gif)
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
//獲得用戶的權限
auths = pubUsersHome.loadUserAuthoritiesByName( username );
String password = null;
//取得用戶的密碼
password = pubUsersHome.getPasswordByUsername( username );
return new User( username, password, true, "", true, true, true, auths);
}
//set PubUsersHome
public void setPubUsersHome( PubUsersHome pubUsersHome ){
this.pubUsersHome = pubUsersHome;
}
public PubUsersHome getPubUsersHome(){
return pubUsersHome;
}
//set PubAuthoritiesResourcesHome
public void setPubAuthoritiesResourcesHome( PubAuthoritiesResourcesHome pubAuthoritiesResourcesHome ){
this.pubAuthoritiesResourcesHome = pubAuthoritiesResourcesHome;
}
public PubAuthoritiesResourcesHome getPubAuthoritiesResourcesHome(){
return pubAuthoritiesResourcesHome;
}
//set DataSource
public void setDataSource( DataSource dataSource ){
this.dataSource = dataSource;
}
public DataSource getDataSource(){
return dataSource;
}
//設置用戶緩存功能。
public void setUserCache(UserCache userCache) {
this.userCache = userCache;
}
public UserCache getUserCache(){
return this.userCache;
}
}
![](http://static.javashuo.com/static/loading.gif)
/*
* @(#) MyAccessDecisionManager.java 2011-3-23 下午04:41:12
*
* Copyright 2011 by Sparta
*/
![](http://static.javashuo.com/static/loading.gif)
package
avatar.base.security;
![](http://static.javashuo.com/static/loading.gif)
import
java.util.Collection;
import
java.util.Iterator;
![](http://static.javashuo.com/static/loading.gif)
import
org.springframework.security.access.AccessDecisionManager;
import
org.springframework.security.access.AccessDeniedException;
import
org.springframework.security.access.ConfigAttribute;
import
org.springframework.security.access.SecurityConfig;
import
org.springframework.security.authentication.InsufficientAuthenticationException;
import
org.springframework.security.core.Authentication;
import
org.springframework.security.core.GrantedAuthority;
![](http://static.javashuo.com/static/loading.gif)
/**
*AccessdecisionManager在Spring security中是很重要的。
*
*在驗證部分簡略提過了,全部的Authentication實現須要保存在一個GrantedAuthority對象數組中。
*這就是賦予給主體的權限。 GrantedAuthority對象經過AuthenticationManager
*保存到 Authentication對象裏,而後從AccessDecisionManager讀出來,進行受權判斷。
*
*Spring Security提供了一些攔截器,來控制對安全對象的訪問權限,例如方法調用或web請求。
*一個是否容許執行調用的預調用決定,是由AccessDecisionManager實現的。
*這個 AccessDecisionManager 被AbstractSecurityInterceptor調用,
*它用來做最終訪問控制的決定。 這個AccessDecisionManager接口包含三個方法:
*
void decide(Authentication authentication, Object secureObject,
List<ConfigAttributeDefinition> config) throws AccessDeniedException;
boolean supports(ConfigAttribute attribute);
boolean supports(Class clazz);
從第一個方法能夠看出來,AccessDecisionManager使用方法參數傳遞全部信息,這好像在認證評估時進行決定。
特別是,在真實的安全方法指望調用的時候,傳遞安全Object啓用那些參數。
好比,讓咱們假設安全對象是一個MethodInvocation。
很容易爲任何Customer參數查詢MethodInvocation,
而後在AccessDecisionManager裏實現一些有序的安全邏輯,來確認主體是否容許在那個客戶上操做。
若是訪問被拒絕,實現將拋出一個AccessDeniedException異常。
![](http://static.javashuo.com/static/loading.gif)
這個 supports(ConfigAttribute) 方法在啓動的時候被
AbstractSecurityInterceptor調用,來決定AccessDecisionManager
是否能夠執行傳遞ConfigAttribute。
supports(Class)方法被安全攔截器實現調用,
包含安全攔截器將顯示的AccessDecisionManager支持安全對象的類型。
*/
public
class
MyAccessDecisionManager
implements
AccessDecisionManager
{
public void decide( Authentication authentication, Object object,
Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException{
if( configAttributes == null ) {
return ;
}
Iterator<ConfigAttribute> ite = configAttributes.iterator();
while( ite.hasNext()){
ConfigAttribute ca = ite.next();
String needRole = ((SecurityConfig)ca).getAttribute();
//ga 爲用戶所被賦予的權限。 needRole 爲訪問相應的資源應該具備的權限。
for( GrantedAuthority ga: authentication.getAuthorities()){
if(needRole.trim().equals(ga.getAuthority().trim())){
![](http://static.javashuo.com/static/loading.gif)
return;
}
}
}
throw new AccessDeniedException("");
}
public boolean supports( ConfigAttribute attribute ){
return true;
![](http://static.javashuo.com/static/loading.gif)
}
public boolean supports(Class<?> clazz){
return true;
![](http://static.javashuo.com/static/loading.gif)
}
![](http://static.javashuo.com/static/loading.gif)
}
數據庫的SQL及預置數據:
prompt PL
/
SQL Developer import
file
prompt Created
on
2011年6月1日
by
Administrator
set
feedback
off
set
define
off
prompt Creating SYS_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
create
table
SYS_AUTHORITIES
(
AUTHORITY_ID
VARCHAR2
(
32
)
not
null
,
AUTHORITY_NAME
VARCHAR2
(
40
),
AUTHORITY_DESC
VARCHAR2
(
100
),
ENABLED
NUMBER
(
1
),
ISSYS
NUMBER
(
1
),
MODULE
VARCHAR2
(
4
)
)
tablespace SCJD
pctfree
10
initrans
1
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
comment
on
table
SYS_AUTHORITIES
is
'
權限表
'
;
comment
on
column
SYS_AUTHORITIES.MODULE
is
'
所屬的子系統,好比平臺裏面包括10個系統,分別爲成本、做業、集輸等。
'
;
alter
table
SYS_AUTHORITIES
add
constraint
PK_PUB_AUTHORITIES
primary
key
(AUTHORITY_ID)
using
index
tablespace SCJD
pctfree
10
initrans
2
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
![](http://static.javashuo.com/static/loading.gif)
prompt Creating SYS_RESOURCES![](http://static.javashuo.com/static/loading.gif)
create
table
SYS_RESOURCES
(
RESOURCE_ID
VARCHAR2
(
32
)
not
null
,
RESOURCE_NAME
VARCHAR2
(
100
),
RESOURCE_DESC
VARCHAR2
(
100
),
RESOURCE_TYPE
VARCHAR2
(
40
),
RESOURCE_STRING
VARCHAR2
(
200
),
PRIORITY
NUMBER
(
1
),
ENABLED
NUMBER
(
1
),
ISSYS
NUMBER
(
1
),
MODULE
VARCHAR2
(
4
)
)
tablespace SCJD
pctfree
10
initrans
1
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
comment
on
table
SYS_RESOURCES
is
'
資源表
'
;
comment
on
column
SYS_RESOURCES.PRIORITY
is
'
(暫不用,保留)
'
;
comment
on
column
SYS_RESOURCES.MODULE
is
'
所屬的子系統,好比平臺裏面包括10個系統,分別爲成本、做業、集輸等。 (暫不用,保留)
'
;
alter
table
SYS_RESOURCES
add
constraint
PK_PUB_RESOURCES
primary
key
(RESOURCE_ID)
using
index
tablespace SCJD
pctfree
10
initrans
2
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
![](http://static.javashuo.com/static/loading.gif)
prompt Creating SYS_AUTHORITIES_RESOURCES![](http://static.javashuo.com/static/loading.gif)
create
table
SYS_AUTHORITIES_RESOURCES
(
ID
NUMBER
(
13
)
not
null
,
AUTHORITY_ID
VARCHAR2
(
32
),
RESOURCE_ID
VARCHAR2
(
32
),
ENABLED
NUMBER
(
1
)
)
tablespace SCJD
pctfree
10
initrans
1
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
comment
on
table
SYS_AUTHORITIES_RESOURCES
is
'
權限資源表
'
;
alter
table
SYS_AUTHORITIES_RESOURCES
add
constraint
PK_PUB_AUTHORITIES_RE
primary
key
(ID)
using
index
tablespace SCJD
pctfree
10
initrans
2
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
alter
table
SYS_AUTHORITIES_RESOURCES
add
constraint
FK_PUB_AUTHORITIES_RE_AU
foreign
key
(AUTHORITY_ID)
references
SYS_AUTHORITIES (AUTHORITY_ID);
alter
table
SYS_AUTHORITIES_RESOURCES
add
constraint
FK_PUB_AUTHORITIES_RE_RE
foreign
key
(RESOURCE_ID)
references
SYS_RESOURCES (RESOURCE_ID);
![](http://static.javashuo.com/static/loading.gif)
prompt Creating SYS_ROLES![](http://static.javashuo.com/static/loading.gif)
create
table
SYS_ROLES
(
ROLE_ID
VARCHAR2
(
32
)
not
null
,
ROLE_NAME
VARCHAR2
(
40
),
ROLE_DESC
VARCHAR2
(
100
),
ENABLED
NUMBER
(
1
),
ISSYS
NUMBER
(
1
),
MODULE
VARCHAR2
(
4
)
)
tablespace SCJD
pctfree
10
initrans
1
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
comment
on
table
SYS_ROLES
is
'
角色表
'
;
comment
on
column
SYS_ROLES.MODULE
is
'
所屬的子系統,好比平臺裏面包括10個系統,分別爲成本、做業、集輸等。
'
;
alter
table
SYS_ROLES
add
constraint
PK_PUB_ROLES
primary
key
(ROLE_ID)
using
index
tablespace SCJD
pctfree
10
initrans
2
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
![](http://static.javashuo.com/static/loading.gif)
prompt Creating SYS_ROLES_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
create
table
SYS_ROLES_AUTHORITIES
(
ID
NUMBER
(
13
)
not
null
,
ROLE_ID
VARCHAR2
(
32
),
AUTHORITY_ID
VARCHAR2
(
32
),
ENABLED
NUMBER
(
1
)
)
tablespace SCJD
pctfree
10
initrans
1
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
comment
on
table
SYS_ROLES_AUTHORITIES
is
'
角色權限表
'
;
alter
table
SYS_ROLES_AUTHORITIES
add
constraint
PK_PUB_ROLES_AUTHORITY
primary
key
(ID)
using
index
tablespace SCJD
pctfree
10
initrans
2
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
alter
table
SYS_ROLES_AUTHORITIES
add
constraint
FK_PUB_ROLES_AUTHORITIES_AU
foreign
key
(AUTHORITY_ID)
references
SYS_AUTHORITIES (AUTHORITY_ID);
alter
table
SYS_ROLES_AUTHORITIES
add
constraint
FK_PUB_ROLES_AUTHORITIES_ROLES
foreign
key
(ROLE_ID)
references
SYS_ROLES (ROLE_ID);
![](http://static.javashuo.com/static/loading.gif)
prompt Creating SYS_USERS![](http://static.javashuo.com/static/loading.gif)
create
table
SYS_USERS
(
USER_ID
VARCHAR2
(
32
)
not
null
,
USER_ACCOUNT
VARCHAR2
(
30
),
USER_NAME
VARCHAR2
(
40
),
USER_PASSWORD
VARCHAR2
(
100
),
USER_DESC
VARCHAR2
(
100
),
ENABLED
NUMBER
(
1
),
ISSYS
NUMBER
(
1
),
USER_DEPT
VARCHAR2
(
20
),
USER_DUTY
VARCHAR2
(
10
),
SUB_SYSTEM
VARCHAR2
(
30
)
)
tablespace SCJD
pctfree
10
initrans
1
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
comment
on
table
SYS_USERS
is
'
用戶表
'
;
comment
on
column
SYS_USERS.USER_PASSWORD
is
'
該密碼是經加鹽值加密的,格式爲password{username}。 好比用戶的密碼爲user,用戶名爲user,那麼經過MD5進行加密的串爲: user{user}
'
;
comment
on
column
SYS_USERS.ISSYS
is
'
是不是超級用戶
'
;
comment
on
column
SYS_USERS.USER_DEPT
is
'
所在單位
'
;
comment
on
column
SYS_USERS.USER_DUTY
is
'
經理或主任
'
;
comment
on
column
SYS_USERS.SUB_SYSTEM
is
'
該用戶所負責的各子系統,可多個,中間用逗號分隔。(目前暫未用,做爲保留字段)
'
;
alter
table
SYS_USERS
add
constraint
PK_PUB_USERS
primary
key
(
USER_ID
)
using
index
tablespace SCJD
pctfree
10
initrans
2
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
![](http://static.javashuo.com/static/loading.gif)
prompt Creating SYS_USERS_ROLES![](http://static.javashuo.com/static/loading.gif)
create
table
SYS_USERS_ROLES
(
ID
NUMBER
(
13
)
not
null
,
USER_ID
VARCHAR2
(
32
),
ROLE_ID
VARCHAR2
(
32
),
ENABLED
NUMBER
(
1
)
)
tablespace SCJD
pctfree
10
initrans
1
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
comment
on
table
SYS_USERS_ROLES
is
'
用戶角色表
'
;
alter
table
SYS_USERS_ROLES
add
constraint
PK_PUB_USERS_ROLES
primary
key
(ID)
using
index
tablespace SCJD
pctfree
10
initrans
2
maxtrans
255
storage
(
initial 64K
minextents
1
maxextents unlimited
);
alter
table
SYS_USERS_ROLES
add
constraint
FK_USERS_ROLES_ROLES
foreign
key
(ROLE_ID)
references
SYS_ROLES (ROLE_ID);
alter
table
SYS_USERS_ROLES
add
constraint
FK_USERS_ROLES_USERS
foreign
key
(
USER_ID
)
references
SYS_USERS (
USER_ID
);
![](http://static.javashuo.com/static/loading.gif)
prompt Disabling triggers
for
SYS_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_AUTHORITIES disable
all
triggers;
prompt Disabling triggers
for
SYS_RESOURCES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_RESOURCES disable
all
triggers;
prompt Disabling triggers
for
SYS_AUTHORITIES_RESOURCES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_AUTHORITIES_RESOURCES disable
all
triggers;
prompt Disabling triggers
for
SYS_ROLES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_ROLES disable
all
triggers;
prompt Disabling triggers
for
SYS_ROLES_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_ROLES_AUTHORITIES disable
all
triggers;
prompt Disabling triggers
for
SYS_USERS![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_USERS disable
all
triggers;
prompt Disabling triggers
for
SYS_USERS_ROLES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_USERS_ROLES disable
all
triggers;
prompt Disabling
foreign
key
constraints
for
SYS_AUTHORITIES_RESOURCES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_AUTHORITIES_RESOURCES disable
constraint
FK_PUB_AUTHORITIES_RE_AU;
alter
table
SYS_AUTHORITIES_RESOURCES disable
constraint
FK_PUB_AUTHORITIES_RE_RE;
prompt Disabling
foreign
key
constraints
for
SYS_ROLES_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_ROLES_AUTHORITIES disable
constraint
FK_PUB_ROLES_AUTHORITIES_AU;
alter
table
SYS_ROLES_AUTHORITIES disable
constraint
FK_PUB_ROLES_AUTHORITIES_ROLES;
prompt Disabling
foreign
key
constraints
for
SYS_USERS_ROLES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_USERS_ROLES disable
constraint
FK_USERS_ROLES_ROLES;
alter
table
SYS_USERS_ROLES disable
constraint
FK_USERS_ROLES_USERS;
prompt Deleting SYS_USERS_ROLES![](http://static.javashuo.com/static/loading.gif)
delete
from
SYS_USERS_ROLES;
commit
;
prompt Deleting SYS_USERS![](http://static.javashuo.com/static/loading.gif)
delete
from
SYS_USERS;
commit
;
prompt Deleting SYS_ROLES_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
delete
from
SYS_ROLES_AUTHORITIES;
commit
;
prompt Deleting SYS_ROLES![](http://static.javashuo.com/static/loading.gif)
delete
from
SYS_ROLES;
commit
;
prompt Deleting SYS_AUTHORITIES_RESOURCES![](http://static.javashuo.com/static/loading.gif)
delete
from
SYS_AUTHORITIES_RESOURCES;
commit
;
prompt Deleting SYS_RESOURCES![](http://static.javashuo.com/static/loading.gif)
delete
from
SYS_RESOURCES;
commit
;
prompt Deleting SYS_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
delete
from
SYS_AUTHORITIES;
commit
;
prompt Loading SYS_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
insert
into
SYS_AUTHORITIES (AUTHORITY_ID, AUTHORITY_NAME, AUTHORITY_DESC, ENABLED, ISSYS, MODULE)
values
(
'
1303910437484
'
,
'
AUTH_xxx
'
,
'
xxx
'
,
null
,
null
,
'
01
'
);
insert
into
SYS_AUTHORITIES (AUTHORITY_ID, AUTHORITY_NAME, AUTHORITY_DESC, ENABLED, ISSYS, MODULE)
values
(
'
AUTH_LOGIN4
'
,
'
AUTH_LOGIN
'
,
'
登陸
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_AUTHORITIES (AUTHORITY_ID, AUTHORITY_NAME, AUTHORITY_DESC, ENABLED, ISSYS, MODULE)
values
(
'
AUTH_AFTERLOGINWELCOME5
'
,
'
AUTH_AFTERLOGINWELCOME
'
,
'
登陸後歡迎界面
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_AUTHORITIES (AUTHORITY_ID, AUTHORITY_NAME, AUTHORITY_DESC, ENABLED, ISSYS, MODULE)
values
(
'
AUTH_XTSZ_DEPT1
'
,
'
AUTH_XTSZ_DEPT
'
,
'
單位設置
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_AUTHORITIES (AUTHORITY_ID, AUTHORITY_NAME, AUTHORITY_DESC, ENABLED, ISSYS, MODULE)
values
(
'
AUTH_XTSZ_USER2
'
,
'
AUTH_XTSZ_USER
'
,
'
用戶設置、橫向查詢
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_AUTHORITIES (AUTHORITY_ID, AUTHORITY_NAME, AUTHORITY_DESC, ENABLED, ISSYS, MODULE)
values
(
'
AUTH_NODE_MGR3
'
,
'
AUTH_NODE_MGR
'
,
'
節點管理、縱向查詢
'
,
1
,
0
,
'
01
'
);
commit
;
prompt
6
records loaded
prompt Loading SYS_RESOURCES![](http://static.javashuo.com/static/loading.gif)
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
1303909883031
'
,
'
ff
'
,
'
ff
'
,
'
action
'
,
'
b.jsp
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
1303909847687
'
,
'
ff1
'
,
'
ff1
'
,
'
action
'
,
'
b.jsp
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
node_mgr3
'
,
'
node_mgr
'
,
'
節點管理
'
,
'
url
'
,
'
/*/*/Tree.jsp
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
login4
'
,
'
login
'
,
'
登陸
'
,
'
url
'
,
'
/login.jsp
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
index5
'
,
'
index
'
,
'
登陸後歡迎頁面
'
,
'
url
'
,
'
/index.jsp
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
resources_mgr
'
,
'
resources_mgr
'
,
'
資源管理
'
,
'
action
'
,
'
/managerResource
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
horizontal_qry6
'
,
'
horizontal_qry
'
,
'
橫向查詢
'
,
'
action
'
,
'
/horizontalQuery
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
vertical_qry7
'
,
'
vertical_qry
'
,
'
縱向查詢
'
,
'
action
'
,
'
/verticalQuery
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
dep_mgr1
'
,
'
dep_mgr
'
,
'
單位管理
'
,
'
action
'
,
'
/UnitsManager
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
user_mgr2
'
,
'
user_mgr
'
,
'
用戶管理
'
,
'
action
'
,
'
/managerUser
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
authority_mgr
'
,
'
authority_mgr
'
,
'
權限管理
'
,
'
action
'
,
'
/managerAuthority
'
,
null
,
1
,
0
,
null
);
insert
into
SYS_RESOURCES (RESOURCE_ID, RESOURCE_NAME, RESOURCE_DESC, RESOURCE_TYPE, RESOURCE_STRING, PRIORITY, ENABLED, ISSYS, MODULE)
values
(
'
role_mgr
'
,
'
role_mgr
'
,
'
角色管理
'
,
'
action
'
,
'
/managerRole
'
,
null
,
null
,
null
,
null
);
commit
;
prompt
12
records loaded
prompt Loading SYS_AUTHORITIES_RESOURCES![](http://static.javashuo.com/static/loading.gif)
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
1
,
'
AUTH_AFTERLOGINWELCOME5
'
,
'
index5
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
2
,
'
AUTH_LOGIN4
'
,
'
login4
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
3
,
'
AUTH_NODE_MGR3
'
,
'
node_mgr3
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
4
,
'
AUTH_XTSZ_DEPT1
'
,
'
dep_mgr1
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
5
,
'
AUTH_XTSZ_USER2
'
,
'
user_mgr2
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
7
,
'
AUTH_XTSZ_USER2
'
,
'
horizontal_qry6
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
8
,
'
AUTH_XTSZ_DEPT1
'
,
'
vertical_qry7
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
12
,
'
AUTH_XTSZ_USER2
'
,
'
role_mgr
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
10
,
'
AUTH_XTSZ_USER2
'
,
'
resources_mgr
'
,
1
);
insert
into
SYS_AUTHORITIES_RESOURCES (ID, AUTHORITY_ID, RESOURCE_ID, ENABLED)
values
(
11
,
'
AUTH_XTSZ_USER2
'
,
'
authority_mgr
'
,
1
);
commit
;
prompt
10
records loaded
prompt Loading SYS_ROLES![](http://static.javashuo.com/static/loading.gif)
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
1303463518765
'
,
'
ROLE_dd1
'
,
'
dd1
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
1303463949640
'
,
'
ROLE_rr1
'
,
'
rr1
'
,
1
,
0
,
'
02
'
);
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
ROLE_PLATFORMADMIN1
'
,
'
ROLE_PLATFORMADMIN
'
,
'
可管理整個平臺的用戶、單位設置。
'
,
1
,
1
,
'
01
'
);
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
ROLE_USER2
'
,
'
ROLE_USER
'
,
'
普通用戶
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
ROLE_LOGINTOWELCOME4
'
,
'
ROLE_LOGINTOWELCOME
'
,
'
僅登陸到歡迎界面!
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
ROLE_SYSADMIN3
'
,
'
ROLE_SYSADMIN
'
,
'
可管理本系統的用戶、單位設置。
'
,
1
,
0
,
'
01
'
);
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
ROLE_WORK
'
,
'
ROLE_WORK
'
,
'
做業子系統的角色(試驗)
'
,
1
,
0
,
'
02
'
);
insert
into
SYS_ROLES (ROLE_ID, ROLE_NAME, ROLE_DESC, ENABLED, ISSYS, MODULE)
values
(
'
ROLE_LOGIN
'
,
'
ROLE_LOGIN
'
,
'
系統登陸
'
,
1
,
0
,
'
01
'
);
commit
;
prompt
8
records loaded
prompt Loading SYS_ROLES_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1
,
'
ROLE_LOGINTOWELCOME4
'
,
'
AUTH_AFTERLOGINWELCOME5
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
2
,
'
ROLE_PLATFORMADMIN1
'
,
'
AUTH_AFTERLOGINWELCOME5
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
3
,
'
ROLE_PLATFORMADMIN1
'
,
'
AUTH_LOGIN4
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
4
,
'
ROLE_PLATFORMADMIN1
'
,
'
AUTH_NODE_MGR3
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
5
,
'
ROLE_PLATFORMADMIN1
'
,
'
AUTH_XTSZ_DEPT1
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
6
,
'
ROLE_PLATFORMADMIN1
'
,
'
AUTH_XTSZ_USER2
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
7
,
'
ROLE_SYSADMIN3
'
,
'
AUTH_XTSZ_DEPT1
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
8
,
'
ROLE_SYSADMIN3
'
,
'
AUTH_XTSZ_USER2
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
9
,
'
ROLE_USER2
'
,
'
AUTH_LOGIN4
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
10
,
'
ROLE_LOGINTOWELCOME4
'
,
'
AUTH_LOGIN4
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
11
,
'
ROLE_USER2
'
,
'
AUTH_AFTERLOGINWELCOME5
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1303463962718
,
'
1303463949640
'
,
'
AUTH_LOGIN4
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1303463972234
,
'
ROLE_WORK
'
,
'
AUTH_LOGIN4
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1303463972235
,
'
ROLE_WORK
'
,
'
AUTH_AFTERLOGINWELCOME5
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1303463972250
,
'
ROLE_WORK
'
,
'
AUTH_XTSZ_DEPT1
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1303463972251
,
'
ROLE_WORK
'
,
'
AUTH_XTSZ_USER2
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1303463972265
,
'
ROLE_WORK
'
,
'
AUTH_NODE_MGR3
'
,
1
);
insert
into
SYS_ROLES_AUTHORITIES (ID, ROLE_ID, AUTHORITY_ID, ENABLED)
values
(
1303287600015
,
'
ROLE_LOGIN
'
,
'
AUTH_LOGIN4
'
,
1
);
commit
;
prompt
18
records loaded
prompt Loading SYS_USERS![](http://static.javashuo.com/static/loading.gif)
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
1304494573750
'
,
'
lxb
'
,
'
lxb
'
,
'
c7d3f4c857bc8c145d6e5d40c1bf23d9
'
,
null
,
1
,
0
,
'
10011001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
1304490737406
'
,
'
lxb
'
,
'
lxb
'
,
'
c7d3f4c857bc8c145d6e5d40c1bf23d9
'
,
null
,
1
,
0
,
'
10011001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
1304574079546
'
,
'
ddd
'
,
'
ddd
'
,
'
0a4f6a961276619f7f91356bcba5a746
'
,
null
,
0
,
0
,
null
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
1304573363921
'
,
'
lxb
'
,
'
盧小兵
'
,
'
09eb37d219cfa835db40e5ab587f7082
'
,
'
普通僅登陸到歡迎界面!
'
,
0
,
0
,
'
1001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
1304573484515
'
,
'
lll
'
,
'
lll
'
,
'
47acedc22cef8c3762c21a435e262d67
'
,
null
,
1
,
0
,
'
1001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
admin1
'
,
'
admin
'
,
'
系統管理員
'
,
'
ceb4f32325eda6142bd65215f4c0f371
'
,
'
超級系統管理員
'
,
1
,
1
,
'
1001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
user2
'
,
'
user
'
,
'
普通用戶
'
,
'
47a733d60998c719cf3526ae7d106d13
'
,
'
普通用戶
'
,
1
,
0
,
'
1001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
sysUser3
'
,
'
sysUser
'
,
'
系統設置維護
'
,
'
8f0295328c34f8eedc2362e9f4a10b7e
'
,
'
系統設置用戶
'
,
1
,
0
,
'
1001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
lxb4
'
,
'
lxb
'
,
'
盧小兵
'
,
'
c7d3f4c857bc8c145d6e5d40c1bf23d9
'
,
'
普通僅登陸到歡迎界面!
'
,
1
,
0
,
'
1001
'
,
null
,
'
01
'
);
insert
into
SYS_USERS (
USER_ID
, USER_ACCOUNT,
USER_NAME
, USER_PASSWORD, USER_DESC, ENABLED, ISSYS, USER_DEPT, USER_DUTY, SUB_SYSTEM)
values
(
'
1304566319625
'
,
'
lxb5
'
,
'
lx5
'
,
'
1abe40ed6d0da1c834586e8ecef61fe7
'
,
null
,
0
,
0
,
'
10011001
'
,
null
,
'
01
'
);
commit
;
prompt
10
records loaded
prompt Loading SYS_USERS_ROLES![](http://static.javashuo.com/static/loading.gif)
insert
into
SYS_USERS_ROLES (ID,
USER_ID
, ROLE_ID, ENABLED)
values
(
1
,
'
admin1
'
,
'
ROLE_PLATFORMADMIN1
'
,
1
);
insert
into
SYS_USERS_ROLES (ID,
USER_ID
, ROLE_ID, ENABLED)
values
(
2
,
'
sysUser3
'
,
'
ROLE_SYSADMIN3
'
,
1
);
insert
into
SYS_USERS_ROLES (ID,
USER_ID
, ROLE_ID, ENABLED)
values
(
3
,
'
user2
'
,
'
ROLE_USER2
'
,
1
);
insert
into
SYS_USERS_ROLES (ID,
USER_ID
, ROLE_ID, ENABLED)
values
(
4
,
'
lxb4
'
,
'
ROLE_LOGINTOWELCOME4
'
,
1
);
insert
into
SYS_USERS_ROLES (ID,
USER_ID
, ROLE_ID, ENABLED)
values
(
5
,
'
1304573484515
'
,
'
1303463518765
'
,
null
);
commit
;
prompt
5
records loaded
prompt Enabling
foreign
key
constraints
for
SYS_AUTHORITIES_RESOURCES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_AUTHORITIES_RESOURCES enable
constraint
FK_PUB_AUTHORITIES_RE_AU;
alter
table
SYS_AUTHORITIES_RESOURCES enable
constraint
FK_PUB_AUTHORITIES_RE_RE;
prompt Enabling
foreign
key
constraints
for
SYS_ROLES_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_ROLES_AUTHORITIES enable
constraint
FK_PUB_ROLES_AUTHORITIES_AU;
alter
table
SYS_ROLES_AUTHORITIES enable
constraint
FK_PUB_ROLES_AUTHORITIES_ROLES;
prompt Enabling
foreign
key
constraints
for
SYS_USERS_ROLES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_USERS_ROLES enable
constraint
FK_USERS_ROLES_ROLES;
alter
table
SYS_USERS_ROLES enable
constraint
FK_USERS_ROLES_USERS;
prompt Enabling triggers
for
SYS_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_AUTHORITIES enable
all
triggers;
prompt Enabling triggers
for
SYS_RESOURCES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_RESOURCES enable
all
triggers;
prompt Enabling triggers
for
SYS_AUTHORITIES_RESOURCES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_AUTHORITIES_RESOURCES enable
all
triggers;
prompt Enabling triggers
for
SYS_ROLES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_ROLES enable
all
triggers;
prompt Enabling triggers
for
SYS_ROLES_AUTHORITIES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_ROLES_AUTHORITIES enable
all
triggers;
prompt Enabling triggers
for
SYS_USERS![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_USERS enable
all
triggers;
prompt Enabling triggers
for
SYS_USERS_ROLES![](http://static.javashuo.com/static/loading.gif)
alter
table
SYS_USERS_ROLES enable
all
triggers;
set
feedback
on
set
define
on
prompt Done.
相關配置文件:
web.xml與第一種方法同。
applicationContext-security.xml:
<?
xml version="1.0" encoding="UTF-8"
?>
![](http://static.javashuo.com/static/loading.gif)
<
b:beans
xmlns
="http://www.springframework.org/schema/security"
xmlns:b
="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-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd"
>
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
<
http
auto-config
="true"
access-denied-page
="/accessDenied.jsp"
>
<!--
不要過濾圖片等靜態資源
-->
<
intercept-url
pattern
="/**/*.jpg"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.png"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.gif"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.css"
filters
="none"
/>
<
intercept-url
pattern
="/**/*.js"
filters
="none"
/>
<!--
登陸頁面和忘記密碼頁面不過濾
-->
<
intercept-url
pattern
="/login.jsp"
filters
="none"
/>
<
intercept-url
pattern
="/jsp/forgotpassword.jsp"
filters
="none"
/>
<
form-login
login-page
="/login.jsp"
authentication-failure-url
="/login.jsp?error=true"
default-target-url
="/index.jsp"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
"記住我"功能,採用持久化策略(將用戶的登陸信息存放在數據庫表中)
-->
<
remember-me
data-source-ref
="dataSource"
/>
<!--
檢測失效的sessionId,超時時定位到另一個URL
-->
<
session-management
invalid-session-url
="/sessionTimeout.jsp"
/>
<!--
增長一個自定義的filter,放在FILTER_SECURITY_INTERCEPTOR以前,
實現用戶、角色、權限、資源的數據庫管理。
-->
<
custom-filter
ref
="myFilter"
before
="FILTER_SECURITY_INTERCEPTOR"
/>
</
http
>
<!--
一個自定義的filter,必須包含authenticationManager,
accessDecisionManager,securityMetadataSource三個屬性。
-->
<
b:bean
id
="myFilter"
class
="avatar.base.security.MyFilterSecurityInterceptor"
>
<
b:property
name
="authenticationManager"
ref
="authenticationManager"
/>
<
b:property
name
="accessDecisionManager"
ref
="myAccessDecisionManager"
/>
<
b:property
name
="securityMetadataSource"
ref
="mySecurityMetadataSource"
/>
</
b:bean
>
![](http://static.javashuo.com/static/loading.gif)
<!--
注意可以爲authentication-manager 設置alias別名
-->
<
authentication-manager
alias
="authenticationManager"
>
<
authentication-provider
user-service-ref
="userDetailsManager"
>
<
password-encoder
ref
="passwordEncoder"
>
<
salt-source
user-property
="username"
/>
</
password-encoder
>
</
authentication-provider
>
</
authentication-manager
>
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
<!--
訪問決策器,決定某個用戶具備的角色,是否有足夠的權限去訪問某個資源。
-->
<
b:bean
id
="myAccessDecisionManager"
class
="avatar.base.security.MyAccessDecisionManager"
>
</
b:bean
>
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
<!--
資源源數據定義,將全部的資源和權限對應關係創建起來,即定義某一資源能夠被哪些角色去訪問。
-->
<
b:bean
id
="mySecurityMetadataSource"
class
="avatar.base.security.MyInvocationSecurityMetadataSourceService"
>
</
b:bean
>
![](http://static.javashuo.com/static/loading.gif)
</
b:beans
>
applicationContext-service.xml:
<?
xml version="1.0" encoding="UTF-8"
?>
![](http://static.javashuo.com/static/loading.gif)
<
beans
xmlns
="http://www.springframework.org/schema/beans"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util
="http://www.springframework.org/schema/util"
xmlns:jee
="http://www.springframework.org/schema/jee"
xmlns:aop
="http://www.springframework.org/schema/aop"
xmlns:tx
="http://www.springframework.org/schema/tx"
xmlns:context
="http://www.springframework.org/schema/context"
xsi:schemaLocation
="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd"
>
![](http://static.javashuo.com/static/loading.gif)
<!--
定義上下文返回的消息的國際化。
-->
<
bean
id
="messageSource"
class
="org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<
property
name
="basename"
value
="classpath:org/springframework/security/messages_zh_CN"
/>
</
bean
>
![](http://static.javashuo.com/static/loading.gif)
<!--
事件監聽:實現了 ApplicationListener監聽接口,
包括AuthenticationCredentialsNotFoundEvent 事件,
AuthorizationFailureEvent事件,AuthorizedEvent事件, PublicInvocationEvent事
件。
-->
<
bean
class
="org.springframework.security.authentication.event.LoggerListener"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
用戶的密碼加密或解密
-->
<
bean
id
="passwordEncoder"
class
="org.springframework.security.authentication.encoding.Md5PasswordEncoder"
/>
![](http://static.javashuo.com/static/loading.gif)
<!--
用戶詳細信息管理:數據源、用戶緩存(經過數據庫管理用戶、角色、權限、資源)。
-->
<
bean
id
="userDetailsManager"
class
="avatar.base.security.MyUserDetailsService"
>
<
property
name
="pubUsersHome"
ref
="pubUsersHome"
/>
<
property
name
="pubAuthoritiesResourcesHome"
ref
="pubAuthoritiesResourcesHome"
/>
<
property
name
="dataSource"
ref
="dataSource"
/>
<
property
name
="userCache"
ref
="userCache"
/>
</
bean
>
<!--
啓用用戶的緩存功能
-->
<
bean
id
="userCache"
class
="org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache"
>
<
property
name
="cache"
ref
="userEhCache"
/>
</
bean
>
<
bean
id
="userEhCache"
class
="org.springframework.cache.ehcache.EhCacheFactoryBean"
>
<
property
name
="cacheName"
value
="userCache"
/>
<
property
name
="cacheManager"
ref
="cacheManager"
/>
</
bean
>
<
bean
id
="cacheManager"
class
="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
/>
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
<!--
spring security自帶的與權限有關的數據讀寫Jdbc模板
-->
<
bean
id
="jdbcTemplate"
class
="org.springframework.jdbc.core.JdbcTemplate"
>
<
property
name
="dataSource"
ref
="dataSource"
/>
</
bean
>
![](http://static.javashuo.com/static/loading.gif)
</
beans
>
第三種方法擴展後Spring Security3.0.2的驗證和受權方法
爲了敘述的嚴謹性,這裏說的是Spring Security3.0.2,而非其餘版本,這是由於我只讀過Spring Security3.0.2的代碼,而且在該版本上面擴展自定義的 動態管理用戶、角色、權限和資源成功。 估計其餘版本的驗證和受權方法是差不太多的,由於沒有接觸過,也不敢大膽猜想。
在擴展後的Spring Security3.0.2中,驗證及受權的過程以下: 一、當Web服務器啓動時,經過Web.xml中對於Spring Security的配置,加載過濾器鏈,那麼在加載MyFilterSecurityInterceptor類時,會注入MyInvocationSecurityMetadataSourceService、MyUserDetailsService、MyAccessDecisionManager類。
二、該MyInvocationSecurityMetadataSourceService類在執行時會提取數據庫中全部的用戶權限,造成權限列表; 並循環該權限列表,經過每一個權限再從數據庫中提取出該權限所對應的資源列表,並將資源(URL)做爲key,權限列表做爲value,造成Map結構的數據。
三、當用戶登陸時,AuthenticationManager進行響應,經過用戶輸入的用戶名和密碼,而後再根據用戶定義的密碼算法和鹽值等進行計算並和數據庫比對, 當正確時經過驗證。此時MyUserDetailsService進行響應,根據用戶名從數據庫中提取該用戶的權限列表,組合成UserDetails供Spring Security使用。
四、當用戶點擊某個功能時,觸發MyAccessDecisionManager類,該類經過decide方法對用戶的資源訪問進行攔截。 用戶點擊某個功能時,其實是請求某個URL或Action, 不管.jsp也好,.action或.do也好,在請求時無一例外的表現爲URL。 還記得第2步時那個Map結構的數據嗎? 若用戶點擊了"login.action"這個URL以後,那麼這個URL就跟那個Map結構的數據中的key對比,若二者相同, 則根據該url提取出Map結構的數據中的value來,這說明:若要請求這個URL,必須具備跟這個URL相對應的權限值。這個權限有多是一個單獨的權限, 也有多是一個權限列表,也就是說,一個URL有可能被多種權限訪問。
那好,咱們在MyAccessDecisionManager類的decide這個方法裏,將經過URL取得的權限列表進行循環,而後跟第3步中登陸的用戶所具備的權限進行比對,若相同,則代表該用戶具備訪問該資源的權利。 不大明白吧? 簡單地說, 在數據庫中咱們定義了訪問「LOGIN」這個URL必須是具備ROLE_ADMIN權限的人來訪問,那麼,登陸用戶偏偏具備該ROLE_ADMIN權限,二者的比對過程當中,就可以返回TRUE,能夠容許該用戶進行訪問。就這麼簡單!
不過在第2步的時候,必定要注意,MyInvocationSecurityMetadataSoruceService類的loadResourceDefine()方法中,造成以URL爲key,權限列表爲value的Map時, 要注意key和Value的對應性,避免Value的不正確對應造成重複,這樣會致使沒有權限的人也能訪問到不應訪問到的資源。 還有getAttributes()方法,要有 url.indexOf("?")這樣的判斷,要經過判斷對URL特別是Action問號以前的部分進行匹配,防止用戶請求的帶參數的URL與你數據庫中定義的URL不匹配,形成訪問拒絕!
第三種方法BTW
固然,你在設計了7張表以後,那麼對於這些之間相互關聯的關係內容及信息內容,就得由你來進行維護了,大約有用戶、角色、權限、資源的增刪改查,並還須要設置用戶和角色、角色和權限、權限和資源之間的關係。可考慮分爲三個菜單進行維護,用戶設置、角色設置、資源設置。 在用戶設置裏分別管理用戶、用戶與角色的關係;在角色設置裏管理角色、角色與權限的關係; 在資源設置裏分別管理權限、權限與資源的關係等。
第四種方法
第四種方法就是直接修改源碼以達到第三種方法的效果。
原本準備是直接從源碼修改來的, 可是始終認爲修改源碼並不是終極解決之道,有違OO的精神本質,再者因爲時間關係,只是對代碼進行了研究,但並無進行實現或驗證。只待之後時間稍稍寬鬆時再作爲興趣進行研究,在次不過多的講解。但據我從代碼上來看,一是將從配置文件中獲取用戶及權限的功能修改成從數據庫中提取出來;二是將從配置文件中獲取權限和資源的對應關係修改成從數據庫中提取;三是修改User增長相關信息等。
始終仍是圍繞着JdbcDaoImpl和DefaultFilterInvocationSecurityMetadataSource還有User這3個類進行修改。 以實現從數據庫提取用戶、角色、權限和資源信息。
有興趣的就先試試吧,等試好了告訴我一聲哈。
Spring Security的優缺點
不能否認,Spring Security依賴於Spring的Ioc、AOP等機制,橫切開系統的業務組件,將通用的權限功能注入到業務組件內部,實現了通用功能和業務功能的無縫整合,但又保證了通用功能和業務功能的實現上的分離,省卻了一部分工做量,這是其存在的最重要意義。
但又不能否認,Spring Security所具備的缺少動態資源管理的硬傷(如果可以提供用戶、角色、權限和資源的數據庫管理,而且提供管理界面那實在是太完美了,惋惜這兩樣同樣都不能實現),又令國人用戶愛恨交加。
該何去何從,就請本身作個選擇吧!
完整例子源碼下載 /Files/SpartaYew/framework.rar 例子中使用到的lib包太大了,傳了幾回網絡中斷沒法上傳,請朋友們自行下載或經過加個人QQ或郵箱進行下載吧。:)
-東營 sparta-紫杉 原創,轉載請註明出處 :) http://www.blogjava.net/SpartaYew/ SpartaYew@163.com
QQ:2
20
86526
|
評論
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
大神!能發我一份DEMO嗎?。QQ77509028# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
能給我發一份第三種方法的例子嗎,我是初學者,光照着文章根本寫不出來,謝謝,個人郵箱是: c8679724@163.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
我是初學spring security,看了些許相關資料,我所要實現的是樓主的第三種方法,可是錯誤連連,求助啊樓主,郵箱:564643499@qq.comqq:564643499 但願樓主能加我QQ
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
大神樓主,能發我一份demo給我參考下麼。謝謝。郵箱:542419098@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主啊,很是感謝你!能不能給我發份demo啊? 謝謝!1370098@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
寫的很不錯啊!很是感謝!# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主啊,能不能給我發一份完整的jar包啊,我都找崩潰了,求助啊樓主,郵箱:ylw758@126.com 先謝謝了!# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
老闆,能不能給我發一個hibernate+spring+struts2 + Spring security3.1的例子啊,謝謝啊# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
很差意思,忘記留郵箱了,jql850405@gmail.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
尊敬偉大的樓主,也給我一份吧hellofreckles@gmail.com
感激涕零啦
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主V5 樓主能傳我一份嗎? 724324522@qq.com 謝謝了# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
給我也發一份吧,bingfengfzl@163.com.謝謝樓主了# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
尊敬偉大的樓主,也給我一份吧yong458@126.com
感激涕零啊
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
給發一份吧,s_bobo_2002@163.com.謝謝樓主了# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
尊敬偉大的樓主,請發一份給我吧強力拜託
獻上鄙人郵箱一枚···
124001623@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
看了樓主的東西受益不淺,但願樓主發份demo, 謝謝,郵箱:912672215@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主啊,求demo啊,尤爲是第二個方案啊,我十分十分的迫切啊,樓主好人啊。個人郵箱啊:56071912@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
請問,若是須要結合cas sso,應該如何調整配置?org.springframework.security.cas.web.CasAuthenticationFilter也是須要配置成custom-filter# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
您好,正在學習中,看您寫的比較詳細!不知可否發份完整的!syyxlhj@126.com!多謝!# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
能發我一份帶jar包的嗎。很是感謝!13791296@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
能發我一份帶jar包的嗎。很是感謝!1130399615@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
本人不得不專門上樓主這裏一趟,感謝樓主的偉大。# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主能不能發份lib包給我呀,我正在研究這個安全框架啊。跪求!!!萬分感謝!!!,616606266@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
if (urlMatcher.pathMatchesUrl(url, resURL)) ,url和resURL的位置寫反了吧??# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
求源碼 謝謝690651174@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
看來我來的有點晚了,不過我最着急,最近的項目spring mvc的,權限弄得頭都大了LZ,能不能發到我郵箱1083261887@qq.com,很是感謝# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
156436756@qq.com能夠發一份完整的源碼給我嗎??謝謝了 最近也在學習這個東西
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
149423669@qq.com能夠發一份完整的源碼給我嗎??謝謝了 .JAR包太難找了
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
謝謝 a52071453@126.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
最近項目急需spring security ,找了好久就你這點寫得最好,可否發一份完整代碼給我看看,郵箱598820200@qq.com,萬分感謝# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
特別想看看你的第四種方法,研究一下發一份給我吧。感激涕零。315920386@qq.com萬分感激# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
最近項目急需spring security ,找了好久感受你的例子應該能用,可否發一份工程jar包,郵箱317923230@qq.com。萬分感謝。# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
.classpath這個文件裏有jar包信息
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
很好# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
很好 www.qinqinbu.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
能給我發一個完整的實例嗎?392342084@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
能給我發一個完整的實例嗎?smilefengyun@163.com 謝謝# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主您好,可否把你的Struts2+spring3+hibernate3+security3例子發一份給我,郵箱fristflayone@yeah.net# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主。你好!麻煩您發一下你的源碼。
郵箱:479195110@qq.com
thank you
# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
樓主,這個demo的jar包實在找不全,麻煩你能發份完整版到我郵箱,謝謝,好人一輩子平安QQ郵箱: 1131041776@qq.com
謝了。
# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
你的表作得可真夠亂的//平臺中的子系統
private String module;
private Set<SysUsersRoles> sysUsersRoles = new HashSet<SysUsersRoles>(0);
private Set<SysRolesAuthorities> sysRolesAuthorities = new HashSet<SysRolesAuthorities>(0);
角色認證,認證什麼?不就是角色能有的模塊嗎?給個module不就好了,還給sysUsersRoles幹嘛?再給個sysRolesAuthorities幹嘛,很少餘嗎?不要說是spring security的邏輯.這樣的問題真的亂多,該有的映射沒有,不應的一堆,你是否是也想繞你們一下啊,讓你們也好好學習一下是嗎?
基礎表:模塊,角色,用戶;擴展表:角色模塊(url,也能夠說是角色權限),用戶角色
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主好強大啊,能把Struts2+spring3+hibernate3+security3例子發份給我嗎?最近在學習springSecurity,謝謝!萬分感謝!郵箱地址:306963591@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
很感謝樓主,分析得深刻,有功底!但願可以把代碼拿下來研究一下。。謝謝啊maidou7788@126.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
感謝樓主,正在學習security,請給我發一demo的源碼(最好能帶jar)。個人郵箱是c8679724@163.com,
謝謝
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
牛人吶,我正在學習security,能發一demo的源碼(最好能帶jar)給我學習嗎。個人郵箱是282217489@qq.com,
伏地拜謝中。。。
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主你好,能發一份第三種的demo給我嗎?我是這個框架的初學者,網上資料難找,謝謝你了!個人郵箱是defsakl123@126.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
感謝樓主的分享,可否發下完整的Demo .謝謝了。jackylt_lu@163.com
QQ:86922668
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
可否發下完整的Demo ,萬分感謝樓主,菜鳥學習中~~499699448@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
@xlplwjy最近也在學習這個,看了樓主的帖子精心收藏,可是想問問樓主能不能把整個工程發來,跑起來體驗一下。很是感謝,郵箱 706830094@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
最近也在學習這個,看了樓主的帖子精心收藏,可是想問問樓主能不能把整個工程發來,跑起來體驗一下。很是感謝,郵箱 706830094@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
能否發一份完整代碼過來運行下??很是感謝10786989@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
看了一下樓主的例子,感受說的挺全面的,但願樓主給發一份完整的demo,讓我運行下,學習學習,萬分感謝!120748096@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
很是好的文章,說了不少容易出錯的細節但願樓主能把完整的例子發一份
278293262@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主寫的很是好,能給我發個demo學習下嗎,個人郵箱是147799824@qq.com,謝謝了啊。# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主能發份完整demo學習下麼?郵箱511098425@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
樓主能發份完整的代碼不?郵箱53873039o@sina.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
有沒有最新版本的,發我一份。我郵箱:qq280206735@163.com
# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
樓主是好人哪,也發我一份唄。 78787398@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
膜拜lz!小弟郵箱chming198809@163.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
感謝樓主了,衷心感謝,象樓主這樣既分享,並且很是的仔細,真的是學到很多東西,很是感謝了啊# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
第三種方式中,修改了或添加了資源必需要重啓服務嗎?有沒有解決方法?# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
我以爲頗有學習的價值, lz能發一份完整的例子給鄙人學習學習嗎?568624640@qq.com 萬分感謝!!
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
寫的很是好麻煩發一個例子給我
182448356@qq.com,萬分感謝
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主,你好,能把相關jar 傳我一份嗎 ,搞了很久一直調不出來!郵箱:526630938@qq.com
謝謝了!
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
安安# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
你好,能不能把完整的項目以及數據庫發給我一份,謝謝 729612262@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
寫得不錯,我如今是新手,剛學,能不能發個源碼給我研究一下,謝謝!zggitemail@163.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
麻煩這位大哥發一份給我,謝謝了,寫得很好,應該有不少年的開發的經驗了吧?個人郵箱402854377@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
果斷收藏,,頂樓主# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
能不能發lib的包給我,謝謝啦郵箱:90yuetian@163.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
您好,我也正在研究權限這一塊,你否給我一份源碼,萬分感謝。471839345@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
我也很是想要Demo,謝謝樓主,個人郵箱:237135053@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
樓主,能也發一份demo給我不,謝謝924629736@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
能夠把lib的包給我,很是感謝郵箱:xy709900456@163.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主的文章寫得很精彩,可否也發我一份demo,很是感謝472579211@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
如今正在學習springsecurity。。但願樓主能給我發一份demo、很是感謝!!!zqcynthia1003@sina.cn
# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
急切須要一份demo,文章深受大益,謝謝794090871@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
公司正在作這一塊,之前沒接觸過,能把代碼發我份麼# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
求代碼和lib包 278668155@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
若是要定義某模塊有幾種操做權限,是否是要在資源表中也定義對應某模塊的幾種操做資源路徑呢?# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
樓主若是能夠的話,發一份/Files/SpartaYew/framework.rar 的lib包給我,很是感謝!howard.hangxm@qq.com總以爲這個資源表定義非常麻煩,一個模塊有N中操做權限,或者說有N種訪問路徑,就要都要在資源表中定義,不知道我有沒有理解錯,若是是這樣,那我以爲維護配置太麻煩
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主,麻煩您給我發一個份整合的jar包吧,我本身整合的jar包總是衝突,SpringSurity和Struts2衝突,謝謝了# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
對了個人Email:dabing69221@163.com,忘了寫,很差意思啊# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
lz精神可嘉, 可是寫出來的東西通常, 仍是謝謝了, 起到一個指路的做用.# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
看到第二種方法,有點困惑,沒有本身寫代碼,怎樣去load用戶的權限呢。只有配置文件的話,怎樣去找到數據庫對應的哪張權限表!另求代碼904033152@qq.com,謝謝
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主,能否給我一份spring+security的demo包含lib包,或者就截個lib包的圖片給我 謝謝 1622581010@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
尊敬偉大的樓主,也給我一份吧1242550103@qq.com
感激涕零啊
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
樓主永生 QQ郵箱707208280@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
給我發一份源碼吧郵箱76162111@qq.com
謝謝
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
請您給我一份源碼吧,謝謝郵箱2448318433@qq.com
# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
給我發一份源碼,謝謝.79772264@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
http://j2eeedu.taobao.com,能夠找到完整的spring security3系列視頻# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
請您給我一份源碼吧,謝謝郵箱1151767736@qq.com
# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
樓主V5,我最近在用這個,能發一份源碼嗎,502353141@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
330498266@qq.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
感謝樓主的分享 求代碼一份 icafe152@163.com# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
真心佩服樓主 可否求得源碼一份 pf1987@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
麻煩樓主發我一份源碼,感謝!446077685@qq.com# re: 春天的故事-Spring Security3十五日研究[未登陸] 回覆 更多評論
樓主,您好,我根據您上述所述我本身搭了一個環境,可是MyAccessDecisionManager這個類只在我登錄後的請求進行攔截,登錄完以後的界面裏的請求就進不去該類裏面,我不知道爲何,您能根據您的經驗判斷大概是什麼緣由麼,感謝!我用的是spingmvc+spring+mybaits框架# re: 春天的故事-Spring Security3十五日研究 回覆 更多評論
@Servicepublic class MyInvocationSecurityMetadataSourceService implements
FilterInvocationSecurityMetadataSource {
@Autowired
private PubAuthoritiesResourcesHome pubAuthoritiesResourcesHome;
pubAuthoritiesResourcesHome能注入進去嗎?不是null??