melinate
Jan 28th, 2005, 03:29 PM
I'm adding Method Invocation security to my AppFuse project [Acegi authentication + Struts + Spring + Hibernate]. I've gotten pretty far, but I can't find an example that helps me to set up the SecureContext for use in my testing.
The application runs when in the servlet container [Tomcat 5.0.30], but I seem to have not gotten the configuration quite right, because I can still access methods I should not be able to.
The existing test setup method is included below. I need to add a SecureContext to this somehow so I can test the normal webapp stuff as well as testing my authorization rules.
I'm fairly new to Acegi and actually Spring in general so if this is fairly obvious to someone else feel free to bop me on the head ;)
Thanks for any help,
Nathan Anderson
-----
protected void setUp() throws Exception {
super.setUp();
// initialize Spring
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_ PARAM,
"/WEB-INF/applicationContext*.xml");
ServletContextListener contextListener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
contextListener.contextInitialized(event);
// magic bridge to make StrutsTestCase aware of Spring's Context
getSession().getServletContext().setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT _ATTRIBUTE,
sc.getAttribute(WebApplicationContext.ROOT_WEB_APP LICATION_CONTEXT_ATTRIBUTE));
ctx = WebApplicationContextUtils.getRequiredWebApplicati onContext(
getSession().getServletContext());
// populate the userForm and place into session
UserManager userMgr = (UserManager) ctx.getBean("userManager");
user = userMgr.getUser("tomcat");
getSession().setAttribute(Constants.USER_KEY, user);
}
The application runs when in the servlet container [Tomcat 5.0.30], but I seem to have not gotten the configuration quite right, because I can still access methods I should not be able to.
The existing test setup method is included below. I need to add a SecureContext to this somehow so I can test the normal webapp stuff as well as testing my authorization rules.
I'm fairly new to Acegi and actually Spring in general so if this is fairly obvious to someone else feel free to bop me on the head ;)
Thanks for any help,
Nathan Anderson
-----
protected void setUp() throws Exception {
super.setUp();
// initialize Spring
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_ PARAM,
"/WEB-INF/applicationContext*.xml");
ServletContextListener contextListener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
contextListener.contextInitialized(event);
// magic bridge to make StrutsTestCase aware of Spring's Context
getSession().getServletContext().setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT _ATTRIBUTE,
sc.getAttribute(WebApplicationContext.ROOT_WEB_APP LICATION_CONTEXT_ATTRIBUTE));
ctx = WebApplicationContextUtils.getRequiredWebApplicati onContext(
getSession().getServletContext());
// populate the userForm and place into session
UserManager userMgr = (UserManager) ctx.getBean("userManager");
user = userMgr.getUser("tomcat");
getSession().setAttribute(Constants.USER_KEY, user);
}