From 74588c8e534c2138b7cf9c764f844702fdd9043f Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 16 Jul 2005 19:35:30 +0000 Subject: [PATCH] Move acegifier code from core. --- .../acegisecurity/util/InMemoryResource.java | 6 +- .../util/WebXmlToAcegiSecurityConverter.java | 115 -------- core/src/main/resources/acegi-web.xsl | 109 ------- core/src/main/resources/web-to-spring.xsl | 273 ------------------ .../WebXmlToAcegiSecurityConverterTests.java | 69 ----- core/src/test/resources/test-web.xml | 65 ----- 6 files changed, 3 insertions(+), 634 deletions(-) delete mode 100644 core/src/main/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverter.java delete mode 100644 core/src/main/resources/acegi-web.xsl delete mode 100644 core/src/main/resources/web-to-spring.xsl delete mode 100644 core/src/test/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverterTests.java delete mode 100644 core/src/test/resources/test-web.xml diff --git a/core/src/main/java/org/acegisecurity/util/InMemoryResource.java b/core/src/main/java/org/acegisecurity/util/InMemoryResource.java index 305e919ec2..2446b9eedf 100644 --- a/core/src/main/java/org/acegisecurity/util/InMemoryResource.java +++ b/core/src/main/java/org/acegisecurity/util/InMemoryResource.java @@ -21,12 +21,12 @@ public class InMemoryResource extends AbstractResource { ByteArrayInputStream in; String description; - public InMemoryResource(String source) { + public InMemoryResource(byte[] source) { this(source, null); } - public InMemoryResource(String source, String description) { - in = new ByteArrayInputStream(source.getBytes()); + public InMemoryResource(byte[] source, String description) { + in = new ByteArrayInputStream(source); this.description = description; } diff --git a/core/src/main/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverter.java b/core/src/main/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverter.java deleted file mode 100644 index f45c561796..0000000000 --- a/core/src/main/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverter.java +++ /dev/null @@ -1,115 +0,0 @@ -package net.sf.acegisecurity.util; - -import org.springframework.core.io.ClassPathResource; -import org.springframework.util.Assert; -import org.w3c.dom.Node; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * A utility to translate a web.xml file into a set of acegi security spring beans. - * - * Also produces a new "acegified" web.xml file with the necessary filters installed - * and the security elements defined by the servlet DTD removed. - * - *

- * This class wraps the XSL transform which actually does most of the work. - *

- * - * @author Luke Taylor - * @version $Id$ - */ -public class WebXmlToAcegiSecurityConverter { - private static final String WEB_TO_SPRING_XSL_FILE = "web-to-spring.xsl"; - private static final String NEW_WEB_XSLT_FILE = "acegi-web.xsl"; - - private Transformer acegiSecurityTransformer, newWebXmlTransformer; - private DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - - /** - * The name of the spring-beans file which the beans will be stored in. - * This is required when writing the new web.xml content. - */ - private String acegiOutputFileName = "applicationContext-acegi-security.xml"; - - /** The web.xml content to be converted */ - private DOMSource xmlSource; - /** The results of the conversion */ - private String newWebXml, acegiBeansXml; - - public WebXmlToAcegiSecurityConverter() throws Exception { - TransformerFactory tf = TransformerFactory.newInstance(); - - acegiSecurityTransformer = tf.newTransformer(createTransformerSource(WEB_TO_SPRING_XSL_FILE)); - newWebXmlTransformer = tf.newTransformer(createTransformerSource(NEW_WEB_XSLT_FILE)); - } - - private Source createTransformerSource(String fileName) throws IOException { - ClassPathResource resource = new ClassPathResource(fileName); - return new StreamSource(resource.getInputStream()); - } - - /** - * Performs the transformations on the input source. - * Creates new web.xml content and a set of acegi-security Spring beans which can be - * accessed through the appropriate getter methods. - */ - public void doConversion() throws IOException, TransformerException { - Assert.notNull(xmlSource, "The XML input must be set, either as a Node or an InputStream"); - - // Create the modified web.xml file - ByteArrayOutputStream output = new ByteArrayOutputStream(); - newWebXmlTransformer.setParameter("acegi-security-context-file", acegiOutputFileName); -// newWebXmlTransformer.setParameter("cas-proxy-url", "http://localhost:8433/cas/proxy"); - newWebXmlTransformer.transform(xmlSource, new StreamResult(output)); - newWebXml = output.toString(); - output.reset(); - - acegiSecurityTransformer.transform(xmlSource, new StreamResult(output)); - acegiBeansXml = output.toString(); - } - - /** set the input as an InputStream */ - public void setInput(InputStream xmlIn) throws Exception { - DocumentBuilder db = dbf.newDocumentBuilder(); - setInput(db.parse(xmlIn)); - } - - /** set the input as an XML node */ - public void setInput(Node webXml) { - this.xmlSource = new DOMSource(webXml); - } - - public String getAcegiOutputFileName() { - return acegiOutputFileName; - } - - public void setAcegiOutputFileName(String acegiOutputFileName) { - this.acegiOutputFileName = acegiOutputFileName; - } - - /** Returns the converted web.xml content */ - public String getNewWebXml() { - return newWebXml; - } - - /** - * Returns the created spring-beans xml content which should be used in - * the application context file. - */ - public String getAcegiBeansXml() { - return acegiBeansXml; - } - -} diff --git a/core/src/main/resources/acegi-web.xsl b/core/src/main/resources/acegi-web.xsl deleted file mode 100644 index 7a9b0b8c41..0000000000 --- a/core/src/main/resources/acegi-web.xsl +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - edu.yale.its.tp.cas.proxyUrl - - - - - - Acegi Filter Chain Proxy - net.sf.acegisecurity.util.FilterToBeanProxy - - targetClass - net.sf.acegisecurity.util.FilterChainProxy - - - - - - - Acegi Filter Chain Proxy - /* - - - - - - org.springframework.web.context.ContextLoaderListener - - - - - - - - - - - - - - - - contextConfigLocation - - - - - - - - - - - - - - - - - contextConfigLocation - - - - - - - - diff --git a/core/src/main/resources/web-to-spring.xsl b/core/src/main/resources/web-to-spring.xsl deleted file mode 100644 index f5bdac9416..0000000000 --- a/core/src/main/resources/web-to-spring.xsl +++ /dev/null @@ -1,273 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - ROLE_ - - , - - - - - -/**=httpSessionContextIntegrationFilter - - - ,authenticationProcessingFilter - - - ,basicProcessingFilter - - - Unsupported auth-method in web.xml, must be FORM or BASIC - - -,rememberMeProcessingFilter,anonymousProcessingFilter,securityEnforcementFilter - - - - - - - - - - - - - - - - - ======================== AUTHENTICATION ======================= - - - - - - - - - - - - - - - - - - - - superuser=password, - - - - - - - foobar - anonymousUser,ROLE_ANONYMOUS - - - - foobar - - - - - - - - - - - - springRocks - - - - springRocks - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Your Realm - - - - - - - - - Processing form login configuration - Remember to switch your login form action from "j_security_check" to "j_acegi_security_check" - - - - - - /j_acegi_security_check - - - - - - false - - - - - - - ======================== FILTER CHAIN ======================= - - if you wish to use channel security, add "channelProcessingFilter," in front - of "httpSessionContextIntegrationFilter" in the list below - - - - CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON - PATTERN_TYPE_APACHE_ANT - - - - - - - - - - false - - - - - - - - An access decision voter that reads ROLE_* configuration settings - - - - - Note the order that entries are placed against the objectDefinitionSource is critical. - The FilterSecurityInterceptor will work from the top of the list down to the FIRST pattern that matches the request URL. - Accordingly, you should place MOST SPECIFIC (ie a/b/c/d.*) expressions first, with LEAST SPECIFIC (ie a/.*) expressions last - - - - - - - CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON - PATTERN_TYPE_APACHE_ANT - - - - - - - - - - - * - = - - - - - - - ROLE_ - - - - , - - - - - diff --git a/core/src/test/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverterTests.java b/core/src/test/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverterTests.java deleted file mode 100644 index 50a3166dae..0000000000 --- a/core/src/test/java/org/acegisecurity/util/WebXmlToAcegiSecurityConverterTests.java +++ /dev/null @@ -1,69 +0,0 @@ -package net.sf.acegisecurity.util; - -import junit.framework.TestCase; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.core.io.AbstractResource; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.w3c.dom.Node; - -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; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.IOException; - -/** - * Tests the WebXmlToAcegiSecurityConverter by applying it to a sample web.xml file. - * - * @author Luke Taylor - * @version $Id$ - */ -public class WebXmlToAcegiSecurityConverterTests extends TestCase { - - public void testFileConversion() throws Exception { - WebXmlToAcegiSecurityConverter converter = new WebXmlToAcegiSecurityConverter(); - - Resource r = new ClassPathResource("test-web.xml"); - converter.setInput(r.getInputStream()); - converter.doConversion(); - - DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(bf); - - int nBeans = beanReader.loadBeanDefinitions(new InMemoryResource(converter.getAcegiBeansXml())); - 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(); - - } -} diff --git a/core/src/test/resources/test-web.xml b/core/src/test/resources/test-web.xml deleted file mode 100644 index 641b6b330e..0000000000 --- a/core/src/test/resources/test-web.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - login-xml - - - contextConfigLocation - - /WEB-INF/applicationContext-business.xml - /WEB-INF/applicationContext-dao.xml - - - - - index.jsp - index.html - - - - - /home.jsp - - - * - - - - - - /admin/* - - - admin - - - - - - /user/* - - - user - admin - - - - - form - - /login.jsp - /login.jsp?login_error=1 - - - - - - user - - - - admin - - - \ No newline at end of file