這兩天嘗試整合一下Acegi、Spring和Struts。配置文件如下:
web.xml文件內容詳細:
?
?
?
??
??
???/WEB-INF/applicationContext.xml
???/WEB-INF/applicationContext-acegi.xml
??
?
?
??
??
?
?
?
??
??
???net.sf.acegisecurity.util.FilterToBeanProxy
??
??
???
???
????net.sf.acegisecurity.util.FilterChainProxy
???
??
?
?
??
??
?
?
?
??
???org.springframework.web.context.ContextLoaderListener
??
?
?
??
???org.springframework.web.util.Log4jConfigListener
??
?
?
?
?
??
??
???org.apache.struts.action.ActionServlet
??
??
???
???
??
??
???
???
??
??
???
???
??
??
?
?
??
??
?
spring的配置文件我分為兩個:
一個是applicationContext.xml,配置了spring整合Hibernate的部分,包括Datasource和DAO部分,內容如下:
??class="org.apache.commons.dbcp.BasicDataSource"
??destroy-method="close">
??
???
??
??
???
??
??
???
??
??
???
??
?
?
??
???
????
???
??
??
???
????
?????org.hibernate.dialect.MySQLDialect
????
????
????
?????true
????
???
??
?
??
???
??
?
?
??
???
??
??
???
??
??
???
????
?????PROPAGATION_REQUIRED,readOnly,-BusinessException
????
????
?????PROPAGATION_REQUIRED,-BusinessException
????
????
?????PROPAGATION_REQUIRED,-BusinessException
????
????
?????PROPAGATION_REQUIRED,-BusinessException
????
???
??
?
?
??
???
??
?
另外一個.xml,配置了Acegi相關內容:
??of "httpSessionContextIntegrationFilter" in the list below -->
?
??
???
????CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
????PATTERN_TYPE_APACHE_ANT
????/**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,?securityEnforcementFilter
???
??
?
?
??
???
??
??
???
??
??
???
??
??
???
??
?
?
??
???
??
?
?
??
???
??
??
???
??
??
?
?
??
???
??
?
?
?
??
???
??
??
???
??
?
?
??
???
??
?
?
?
?
??
???
??
??
???
??
?
?
??
???
??
?
?
??
???
????net.sf.acegisecurity.context.security.SecureContextImpl
???
??
?
?
?
??
???
??
??
???
??
?
?
?
??
???
??
??
???
??
?
?
?
??
???
??
??
???
??
??
???
????CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
????PATTERN_TYPE_APACHE_ANT
????/index.jsp=ROLE_SUPERVISOR
????/hello.jsp=ROLE_TELLER
????/*.do=ROLE_TELLER
???
??
?
?
??
???
??
??
???
??
?
注意兩處顏色不同的部分配置,是Acegi需要配合struts的內容。
Spring的配置我這里就不詳細描述,這里主要談談對Acegi的看法。
我用的是Acegi0.8.3,目前是最新版。可以到項目主頁下載:http://acegisecurity.sourceforge.net/?
各位也看到了,Acegi的配置還是比較復雜,要了解幾個主要的類,如下圖:
如果嫌麻煩,就直接拷貝過去使用就可以了。只要修改objectDefinitionSource部分的權限配置就行。
再附上登錄頁面login.jsp的片斷:
???
??? ?
??? ??
??? ???User:
??? ??
??? ?
??? ?
??? ??
??? ???Password:
??? ??
??? ?
??? ?
??? ??
??? ???
??? ??
??? ?
???
???
粗淺研究,首次涂鴉,希望有些可以供人參考之處,上面內容有很多寫的不夠詳盡,各位看官可以留言,或發郵件共同探討。