mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-04 09:42:29 +00:00
Separate InMemoryResource class for use in Acegifier web application.
This commit is contained in:
parent
0a742ce62a
commit
22a28f3b39
@ -0,0 +1,40 @@
|
|||||||
|
package net.sf.acegisecurity.util;
|
||||||
|
|
||||||
|
import org.springframework.core.io.AbstractResource;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An in memory implementation of Spring's {@link org.springframework.core.io.Resource} interface.
|
||||||
|
* <p>
|
||||||
|
* Used by the "Acegifier" web application to create a
|
||||||
|
* bean factory from an XML string, rather than a file.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Luke Taylor
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class InMemoryResource extends AbstractResource {
|
||||||
|
|
||||||
|
ByteArrayInputStream in;
|
||||||
|
String description;
|
||||||
|
|
||||||
|
public InMemoryResource(String source) {
|
||||||
|
this(source, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InMemoryResource(String source, String description) {
|
||||||
|
in = new ByteArrayInputStream(source.getBytes());
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description == null ? in.toString() : description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
}
|
@ -39,7 +39,7 @@ public class WebXmlToAcegiSecurityConverter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the spring-beans file which the beans will be stored in.
|
* The name of the spring-beans file which the beans will be stored in.
|
||||||
* This is required when writing the new web.xml file.
|
* This is required when writing the new web.xml content.
|
||||||
*/
|
*/
|
||||||
private String acegiOutputFileName = "applicationContext-acegi-security.xml";
|
private String acegiOutputFileName = "applicationContext-acegi-security.xml";
|
||||||
|
|
||||||
@ -70,12 +70,12 @@ public class WebXmlToAcegiSecurityConverter {
|
|||||||
|
|
||||||
// Create the modified web.xml file
|
// Create the modified web.xml file
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
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));
|
newWebXmlTransformer.transform(xmlSource, new StreamResult(output));
|
||||||
newWebXml = output.toString();
|
newWebXml = output.toString();
|
||||||
output.reset();
|
output.reset();
|
||||||
|
|
||||||
// acegiSecurityTransformer.setParameter("cas-proxy-url", "http://localhost:8433/cas/proxy");
|
|
||||||
acegiSecurityTransformer.setParameter("acegi-security-context-file", acegiOutputFileName);
|
|
||||||
acegiSecurityTransformer.transform(xmlSource, new StreamResult(output));
|
acegiSecurityTransformer.transform(xmlSource, new StreamResult(output));
|
||||||
acegiBeansXml = output.toString();
|
acegiBeansXml = output.toString();
|
||||||
}
|
}
|
||||||
|
@ -29,17 +29,16 @@ import java.io.IOException;
|
|||||||
public class WebXmlToAcegiSecurityConverterTests extends TestCase {
|
public class WebXmlToAcegiSecurityConverterTests extends TestCase {
|
||||||
|
|
||||||
public void testFileConversion() throws Exception {
|
public void testFileConversion() throws Exception {
|
||||||
WebXmlToAcegiSecurityConverter t = new WebXmlToAcegiSecurityConverter();
|
WebXmlToAcegiSecurityConverter converter = new WebXmlToAcegiSecurityConverter();
|
||||||
|
|
||||||
Resource r = new ClassPathResource("test-web.xml");
|
Resource r = new ClassPathResource("test-web.xml");
|
||||||
t.setInput(r.getInputStream());
|
converter.setInput(r.getInputStream());
|
||||||
t.doConversion();
|
converter.doConversion();
|
||||||
|
|
||||||
|
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(bf);
|
XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(bf);
|
||||||
|
|
||||||
int nBeans = beanReader.loadBeanDefinitions(new InMemoryResource(t.getAcegiBeansXml()));
|
int nBeans = beanReader.loadBeanDefinitions(new InMemoryResource(converter.getAcegiBeansXml()));
|
||||||
assertNotNull(bf.getBean("filterChainProxy"));
|
assertNotNull(bf.getBean("filterChainProxy"));
|
||||||
|
|
||||||
ProviderManager pm = (ProviderManager) bf.getBean("authenticationManager");
|
ProviderManager pm = (ProviderManager) bf.getBean("authenticationManager");
|
||||||
@ -67,24 +66,4 @@ public class WebXmlToAcegiSecurityConverterTests extends TestCase {
|
|||||||
FilterSecurityInterceptor fsi = sef.getFilterSecurityInterceptor();
|
FilterSecurityInterceptor fsi = sef.getFilterSecurityInterceptor();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class InMemoryResource extends AbstractResource {
|
|
||||||
ByteArrayInputStream in;
|
|
||||||
|
|
||||||
public InMemoryResource(ByteArrayInputStream in) {
|
|
||||||
this.in = in;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InMemoryResource(String source) {
|
|
||||||
in = new ByteArrayInputStream(source.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return in.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
<web-app>
|
<web-app>
|
||||||
<display-name>login-xml</display-name>
|
<display-name>login-xml</display-name>
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>contextConfigLocation</param-name>
|
||||||
|
<param-value>
|
||||||
|
/WEB-INF/applicationContext-business.xml
|
||||||
|
/WEB-INF/applicationContext-dao.xml
|
||||||
|
</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<welcome-file-list>
|
<welcome-file-list>
|
||||||
<welcome-file>index.jsp</welcome-file>
|
<welcome-file>index.jsp</welcome-file>
|
||||||
<welcome-file>index.html</welcome-file>
|
<welcome-file>index.html</welcome-file>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user