java

位置:IT落伍者 >> java >> 浏览文章

浅谈Acegi配置-Spring-Java[5]


发布日期:2020年07月06日
 
浅谈Acegi配置-Spring-Java[5]

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>

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

               

上一篇:浅谈Acegi配置-Spring-Java[1]

下一篇:浅谈Acegi配置-Spring-Java[4]