📄 acegi 元件.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0071)http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/AcegiComponent.html -->
<HTML><HEAD><TITLE>Acegi 元件</TITLE><LINK href="Acegi 元件.files/stdlayout.css"
type=text/css rel=stylesheet><LINK href="Acegi 元件.files/print.css" type=text/css
rel=stylesheet>
<META http-equiv=content-type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY>
<H3><A
href="http://caterpillar.onlyfun.net/GossipCN/index.html">http://caterpillar.onlyfun.net/GossipCN/index.html</A></H3>
<H1><A
href="http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/AcegiGossip.html">Acegi
Gossip: Acegi
元件</A></H1>入门Acegi最重要的是了解基本架构,如此就不会被一堆设定档案搞的混头转向,从先前“第一个Acegi程式”,可以看到Acegi系统包括的四个主要类型元件:Filter、Manager、Provider与Handler。<BR>
<UL>
<LI>Filter </LI></UL>
<DIV
style="MARGIN-LEFT: 40px">当一个请求到来时,在安全处理上最高层的元件,像是会话处理、验证、登出等,并呼叫对应的物件进行处理。</DIV>
<UL>
<LI>Manager </LI></UL>
<DIV
style="MARGIN-LEFT: 40px">真正处理验证、登出等安全服务之元件,Manager管理Provider所提供的安全相关资讯。</DIV>
<UL>
<LI>Provider </LI></UL>
<DIV
style="MARGIN-LEFT: 40px">提供安全相关资讯给Manager,安全资讯来源可能是记忆体中的物件、档案、资料库等储存媒介,安全资讯包括了使用者名称、密码、角色等讯息。</DIV>
<UL>
<LI>Handler </LI></UL>
<DIV
style="MARGIN-LEFT: 40px">有时会将一个安全服务分作数个小任务来进行,每个小任务由一个Handler来进行处理,如此在处理安全服务或设定Acegi时可以更有弹性,例如依需求处理登出时Session的失效与Cookie的失效。</DIV><BR>Acegi使用Filter来对请求进行验证与授权等安全服务:<BR><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<!-- Filter Chain --></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<bean id="filterChainProxy"
class="org.acegisecurity.util.FilterChainProxy"> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<property name="filterInvocationDefinitionSource"> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<value> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
PATTERN_TYPE_APACHE_ANT </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
/**=</SPAN><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">httpSessionContextIntegrationFilter,</SPAN><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">authenticationProcessingFilter,<BR>
exceptionTranslationFilter,filterSecurityInterceptor</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</value> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</property> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</bean></SPAN><BR><BR>以下介绍主要的几个Filter:<BR>
<UL>
<LI>Session Integration Filter </LI></UL>
<DIV style="MARGIN-LEFT: 40px">通常是Filter Chain中第一个Filter,会建立Security Context
物件用以储存安全相关资讯,后续的Filter若有需要储存或取得安全相关资讯,即可利用Security Context 物件,如果Security
Context物件中的资讯有所变动,Session Integration Filter会将变动储存至Session物件之中,否则将Security
Context物件弃置,例如“第一个Acegi程式”中所使用的Authentication Processing Filter,即利用Security
Context物件来储存使用者名称、密码等使用者资讯。</DIV><BR>
<UL>
<LI>Authentication Processing Filter </LI></UL>
<DIV style="MARGIN-LEFT: 40px">当使用者存取受保护资源而需要登入时,Authentication Processing
Filter可提供表单来源给使用者,之后从使用者的请求(物件)中取得名称、密码并建立authentication
token以储存资讯,接着将之交给验证管理员(authentication manager)进行以进行使用者的比对,所以基本上,Authentication
Processing Filter需要设定以下的资讯:</DIV>
<DIV style="MARGIN-LEFT: 40px"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><!--
验证处理,使用表单 --></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<bean id="authenticationProcessingFilter" </SPAN><BR><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<!-- 验证管理员,处理验证资讯提供者 --></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<property name="authenticationManager" ref="authenticationManager"/>
</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<!-- 验证失败URL --></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<property name="authenticationFailureUrl" value="/acegilogin.jsp"/>
</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<!-- 验证成功预设URL --></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<property name="defaultTargetUrl" value="/protected/userinfo.jsp"/>
</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<!-- 验证处理的提交位址 --></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<property name="filterProcessesUrl" value="<SPAN
style="COLOR: rgb(0,0,0)">/j_acegi_security_check</SPAN>"/> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</bean></SPAN><BR></DIV><BR>
<DIV style="MARGIN-LEFT: 40px">当验证管理员进行使用者的比对、取得细节资讯并返回Authentication Processing
Filter后,Authentication Processing Filter会建立Authentication并将取得的使用者资讯储存在Security
Context物件中,然后交给下一个Filter继续进行处理。</DIV><BR>
<UL>
<LI>Exception Translation Filter </LI></UL>
<DIV style="MARGIN-LEFT: 40px">当验证或授权过程中发生例外时,Exception Translation
Filter处理例外。<BR><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<!-- 发生验证错误或权限错误时的处理 --></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<bean id="exceptionTranslationFilter"
class="org.acegisecurity.ui.ExceptionTranslationFilter"> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -