First version of web.xml to acegi translator
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package net.sf.acegisecurity.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
import net.sf.acegisecurity.providers.ProviderManager;
|
||||
import net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider;
|
||||
import net.sf.acegisecurity.providers.dao.memory.InMemoryDaoImpl;
|
||||
import net.sf.acegisecurity.UserDetails;
|
||||
import net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter;
|
||||
|
||||
import net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor;
|
||||
|
||||
/**
|
||||
* Tests the WebXmlSecurityToSpringBeansTranslator by applying it
|
||||
* to a test sample web.xml file.
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class WebXmlSecurityToSpringBeansTranslatorTests extends TestCase {
|
||||
|
||||
public void testFileTranslation() throws Exception {
|
||||
WebXmlSecurityToSpringBeansTranslator t = new WebXmlSecurityToSpringBeansTranslator();
|
||||
|
||||
Resource r = new ClassPathResource("test-web.xml");
|
||||
t.translate(r.getInputStream());
|
||||
|
||||
BeanFactory bf = t.getBeanFactory();
|
||||
assertNotNull(bf.getBean("filterChainProxy"));
|
||||
|
||||
ProviderManager pm = (ProviderManager) bf.getBean("authenticationManager");
|
||||
assertNotNull(pm);
|
||||
assertEquals(3, pm.getProviders().size());
|
||||
|
||||
DaoAuthenticationProvider dap =
|
||||
(DaoAuthenticationProvider) bf.getBean("daoAuthenticationProvider");
|
||||
assertNotNull(dap);
|
||||
|
||||
InMemoryDaoImpl dao = (InMemoryDaoImpl) dap.getAuthenticationDao();
|
||||
UserDetails user = dao.loadUserByUsername("superuser");
|
||||
assertEquals("password",user.getPassword());
|
||||
assertEquals(2, user.getAuthorities().length);
|
||||
assertNotNull(bf.getBean("anonymousProcessingFilter"));
|
||||
assertNotNull(bf.getBean("anonymousAuthenticationProvider"));
|
||||
assertNotNull(bf.getBean("httpSessionContextIntegrationFilter"));
|
||||
assertNotNull(bf.getBean("rememberMeProcessingFilter"));
|
||||
assertNotNull(bf.getBean("rememberMeAuthenticationProvider"));
|
||||
|
||||
SecurityEnforcementFilter sef =
|
||||
(SecurityEnforcementFilter) bf.getBean("securityEnforcementFilter");
|
||||
assertNotNull(sef);
|
||||
assertNotNull(sef.getAuthenticationEntryPoint());
|
||||
FilterSecurityInterceptor fsi = sef.getFilterSecurityInterceptor();
|
||||
|
||||
}
|
||||
}
|
||||
54
core/src/test/resources/test-web.xml
Normal file
54
core/src/test/resources/test-web.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<web-app>
|
||||
<display-name>login-xml</display-name>
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>index.jsp</welcome-file>
|
||||
<welcome-file>index.html</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<url-pattern>/home.jsp</url-pattern>
|
||||
</web-resource-collection>
|
||||
<auth-constraint>
|
||||
<role-name>*</role-name>
|
||||
</auth-constraint>
|
||||
</security-constraint>
|
||||
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<url-pattern>/admin/*</url-pattern>
|
||||
</web-resource-collection>
|
||||
<auth-constraint>
|
||||
<role-name>admin</role-name>
|
||||
</auth-constraint>
|
||||
</security-constraint>
|
||||
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<url-pattern>/user/*</url-pattern>
|
||||
</web-resource-collection>
|
||||
<auth-constraint>
|
||||
<role-name>user</role-name>
|
||||
<role-name>admin</role-name>
|
||||
</auth-constraint>
|
||||
</security-constraint>
|
||||
|
||||
<login-config>
|
||||
<auth-method>form</auth-method>
|
||||
<form-login-config>
|
||||
<form-login-page>/login.jsp</form-login-page>
|
||||
<form-error-page>/login.jsp?login_error=1</form-error-page>
|
||||
</form-login-config>
|
||||
|
||||
</login-config>
|
||||
|
||||
<security-role>
|
||||
<role-name>user</role-name>
|
||||
</security-role>
|
||||
|
||||
<security-role>
|
||||
<role-name>admin</role-name>
|
||||
</security-role>
|
||||
|
||||
</web-app>
|
||||
Reference in New Issue
Block a user