⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第一個acegi 程式 - 表單網頁.htm

📁 acegi+spring最新的分析
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0072)http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/FirstAcegConfig.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>首先请先至<A 
href="http://www.acegisecurity.org/">Acegi官方网站</A>,下载Acegi程式库,在撰写这份教学文件之时,所使用的版本是1.0.3。<BR><BR>Acegi相关类别之间的依赖关系,可以藉由IoC容器来协助建立,在这边您可以使用 
<A 
href="http://caterpillar.onlyfun.net/GossipCN/SpringGossip/SpringGossip.html">Spring</A> 
的IoC容器功能,您可以在下载的Acegi档案中,找到acegi-security-sample-tutorial.war,将之使用解压缩软体解开,可以在WEB-INF\lib下,找到所需的Spring程式库,在Acegi 
1.0.3中的acegi-security-sample-tutorial.war所搭配的是Spring 
1.2.8。<BR><BR>要完成您第一个Acegi程式,您需要以下的程式库:<BR>
<UL>
  <LI>acegi-security-1.0.3.jar 
  <LI>spring-1.2.8.jar 
</LI></UL><BR>为了在Web应用程式中,使用Acegi搭配Spring的Context资讯,来完成Acegi的依赖关系配置,您要在web.xml中设定 
org.springframework.web.context.ContextLoaderListener,并在Context参数中,指定设定档案位置与名称,而Acegi主要透过Filter 
Chain来达到请求的检查、验证、授权、登出等动作,您可以在web.xml中如下设定:<BR>
<UL>
  <LI>web.xml </LI></UL><PRE>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR><BR>&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee"<BR>	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<BR>	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"<BR>	 version="2.4"&gt;<BR><BR>    &lt;display-name&gt;Acegi 范例&lt;/display-name&gt;<BR>    <BR>    &lt;!-- 指定Acegi资讯的设定档--&gt;<BR>    &lt;context-param&gt;<BR>        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<BR>        &lt;param-value&gt;<SPAN style="FONT-WEIGHT: bold">/WEB-INF/acegi-config.xml</SPAN>&lt;/param-value&gt;<BR>    &lt;/context-param&gt;<BR>    <BR>    &lt;!-- Acegi 的 Filter Chain 代理 --&gt;<BR>    &lt;filter&gt;<BR>        &lt;filter-name&gt;Acegi Filter Chain Proxy&lt;/filter-name&gt;<BR>        &lt;filter-class&gt;<BR>            org.acegisecurity.util.FilterToBeanProxy<BR>        &lt;/filter-class&gt;<BR>        &lt;init-param&gt;<BR>            &lt;param-name&gt;targetClass&lt;/param-name&gt;<BR>                &lt;param-value&gt;<BR>                    org.acegisecurity.util.FilterChainProxy<BR>                &lt;/param-value&gt;<BR>        &lt;/init-param&gt;<BR>    &lt;/filter&gt;<BR><BR>    &lt;filter-mapping&gt;<BR>        &lt;filter-name&gt;Acegi Filter Chain Proxy&lt;/filter-name&gt;<BR>        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<BR>     &lt;/filter-mapping&gt;<BR><BR>     &lt;!-- 取得Spring的Context --&gt;<BR>     &lt;listener&gt;<BR>         &lt;listener-class&gt;<BR>             org.springframework.web.context.ContextLoaderListener<BR>         &lt;/listener-class&gt;<BR>     &lt;/listener&gt;<BR>&lt;/web-app&gt;</PRE><BR>org.acegisecurity.util.FilterToBeanProxy建立 
org.acegisecurity.util.FilterChainProxy实例,并将请求转交给FilterChainProxy来处理,接下来就是配置acegi-config.xml的内容,在这边先假设一个需求情境,您想要对Web应用程式中的/protected/下所有资源进行保护,如果使用者试图存取/protected/下的资源,就先将其送至/acegilogin.jsp进行登入,登入成功后显示使用者所请求的资源,使用者也可以直接连接/acegilogin.jsp,登入成功后,预设显示/loginsuccess.jsp,您可以在acegi-config.xml中加入以下的设定:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&lt;!-- 
验证处理,使用表单 --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;bean id="authenticationProcessingFilter" <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp;&nbsp;class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"&gt;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;!-- 验证管理员,处理验证资讯提供者&nbsp; --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="authenticationManager" ref="authenticationManager"/&gt;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;!-- 验证失败URL --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="authenticationFailureUrl" value="/acegilogin.jsp"/&gt;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;!-- 验证成功预设URL --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="defaultTargetUrl" 
value="/protected/loginsuccess.jsp"/&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;!-- 验证处理的提交位址 --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="filterProcessesUrl" value="<SPAN 
style="COLOR: rgb(255,0,0)">/j_acegi_security_check</SPAN>"/&gt;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;/bean&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN><BR></DIV><BR>可以看到在这边使用了AuthenticationProcessingFilter来处理验证,实际对使用者的验证是交给验证管理员,也就是authenticationManager属性中所设定的实例,可以在acegi-config.xml中加入:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;!-- 验证管理员,管理验证资讯提供者 --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;bean id="authenticationManager" 
class="org.acegisecurity.providers.ProviderManager"&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="providers"&gt;&lt;!-- 可有多个提供者,其中一个验证通过即可以了 --&gt;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;list&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;ref local="daoAuthenticationProvider"/&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/list&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/property&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;/bean&gt;</SPAN></DIV><BR><BR>验证管理员管理验证提供者,也就是实际提供使用者名称、密码、角色资讯的物件,来源可以是资料库或设定文件中的讯息,基于来源的不同,您可以使用 
org.acegisecurity.providers.dao.DaoAuthenticationProvider,并指定其 
userDetailsService属性,设定验证讯息来源:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;!-- 验证提供者,指定使用记忆体来源中的验证资讯 --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;bean id="daoAuthenticationProvider" 
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="userDetailsService" ref="inMemoryDaoImpl"/&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -