熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

淺談Acegi配置-Spring-Java[5]

2022-06-13   來源: Java開源技術 

import orgliacegiTestAcegi;
import orgspringframeworkcontextApplicationContext;
import orgspringframeworkwebcontextsupportWebApplicationContextUtils;

public class TestServlet extends HttpServlet
{
    private static final long serialVersionUID = L;

    public void doGet(HttpServletRequest request HttpServletResponse response)
            throws ServletException IOException
    {
        responsesetContentType(text/html;charset=GBK);
        PrintWriter out = responsegetWriter();
        ApplicationContext ctx =
            WebApplicationContextUtilsgetRequiredWebApplicationContext(requestgetSession()getServletContext());
        TestAcegi test = (TestAcegi)ctxgetBean(testAcegi);
        testRole();//訪問TestAcegi類的Role方法
        outprintln(調用成功);
    }

    public void doPost(HttpServletRequest request HttpServletResponse response)
            throws ServletException IOException
    {
        doGet(requestresponse);
    }

}

       准備工作做好了開始配置Acegi

  先在Spring裡給Acegi做個代理

<bean id=autoProxyCreator class=orgspringframeworkaopframeworkautoproxyBeanNameAutoProxyCreator>
        <property name=beanNames>
            <list>
                <value>testAcegi</value><! 要代理的Bean的id >
            </list>
        </property>
        <property name=interceptorNames>
            <list>
                <value>methodSecurityInterceptor</value><! 代理為 >
            </list>
        </property>
    </bean>

  裡面的methodSecurityInterceptor呢配置為

<bean id=methodSecurityInterceptor class=orgacegisecurityinterceptmethodaopallianceMethodSecurityInterceptor>
        <property name=authenticationManager>
            <ref bean=authenticationManager/>
        </property>
        <property name=accessDecisionManager>
            <ref bean=accessDecisionManager/>
        </property>
        <property name=objectDefinitionSource><! 對代理的類的方法開始配置權限 >
            <value>orgliacegiTestAcegiRole=ROLE_USER</value>
        </property>
    </bean>

[]  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28996.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.