说明:“一餐三碗”提供的数据库表中的root用户口令为root。
3.2 登录后进入index.jsp
在web应用根目录下建立一个secure目录,此目录下件一个index.jsp文件:
〈html〉
〈body〉
〈h1〉Secure Page〈/h1〉
This is a protected page. You can get to me if you've been remembered,
or if you've authenticated this session.
〈p〉〈a href="../testacegi.jsp"〉Home〈/a〉
〈p〉〈a href="../j_acegi_logout"〉Logout〈/a〉
〈/body〉
〈/html〉
3.3 调用业务方法的页面
在web应用的根目录下建立一个testacegi.jsp文件:
〈%@ page import="org.acegisecurity.context.SecurityContextHolder" %〉
〈%@ page import="org.acegisecurity.Authentication" %〉
〈%@ page import="org.acegisecurity.ui.AccessDeniedHandlerImpl" %〉
〈%@ page import="org.springframework.aop.framework.ProxyFactoryBean"%〉
〈%@ page import="org.springframework.context.ApplicationContext"%〉
〈%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext"%〉
〈%@ page import="com.mysoft.pmi.testcase.aop.TestAOPInterface"%〉
〈%
System.out.println("_______"+SecurityContextHolder.getContext().getAuthentication().toString());
ApplicationContext context1 = new ClassPathXmlApplicationContext("com/mysoft/pmi/resource/aoptest.xml");
TestAOPInterface bean1 = (TestAOPInterface)context1.getBean("aopProxyFactoryBean");
bean1.test("aa1a","ccc");
bean1.testAAA("dd1d","dwdwsd");
%〉
〈% Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) { %〉
Authentication object as a String: 〈%= auth.toString() %〉〈BR〉〈BR〉
〈% } %〉
说明:本文的例子是在Bea Weblogic8.1下测试通过。
jsp测试流程:在登录页面输入正确的用户名和口令(如果口令错误,控制台会报bad credentials的错误),登录成功后,浏览器打开了secure/index.jsp页面,点此页面的home连接,此连接调用了testacegi.jsp,此jsp调用了TestAOPInterface的接口方法,可以看到后台显示了当前的userId(见WelcomeAdvice.Java)。如果需要将口令进行md5加密,然后与数据库中加密的口令进行比较,可参考applicationContext-acegi-security.xml。





