mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-23 04:22:17 +00:00
First upload of the "acegifier" web application.
This commit is contained in:
parent
7268c81192
commit
0a742ce62a
@ -0,0 +1,81 @@
|
||||
package acegifier.web;
|
||||
|
||||
import org.springframework.web.servlet.mvc.SimpleFormController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.beans.BeansException;
|
||||
import net.sf.acegisecurity.util.InMemoryResource;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.acegisecurity.util.WebXmlToAcegiSecurityConverter;
|
||||
|
||||
/**
|
||||
* Takes a submitted web.xml, applies the transformer to it and returns the resulting
|
||||
* modified web.xml and acegi-app-context.xml file contents.
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AcegifierController extends SimpleFormController {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
|
||||
public AcegifierController() {
|
||||
dbf.setValidating(false);
|
||||
}
|
||||
|
||||
public ModelAndView onSubmit(
|
||||
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
|
||||
throws Exception {
|
||||
|
||||
AcegifierForm conversion = (AcegifierForm)command;
|
||||
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(conversion.getWebXml().getBytes());
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = null;
|
||||
WebXmlToAcegiSecurityConverter converter = null;
|
||||
int nBeans = 0;
|
||||
|
||||
try {
|
||||
doc = db.parse(in);
|
||||
converter = new WebXmlToAcegiSecurityConverter();
|
||||
converter.setInput(doc);
|
||||
converter.doConversion();
|
||||
nBeans = createBeanFactory(converter.getAcegiBeansXml());
|
||||
} catch (SAXParseException spe) {
|
||||
errors.rejectValue("webXml","parseFailure","Your Web XML Document failed to parse: " + spe.getMessage());
|
||||
} catch (BeansException be) {
|
||||
errors.rejectValue("webXml","invalidBeans","There was a problem validating the Spring beans: " + be.getMessage());
|
||||
}
|
||||
|
||||
if(errors.hasErrors()) {
|
||||
return showForm(request, response, errors);
|
||||
}
|
||||
|
||||
Map model = new HashMap();
|
||||
model.put("webXml", converter.getNewWebXml());
|
||||
model.put("acegiBeansXml", converter.getAcegiBeansXml());
|
||||
model.put("nBeans", new Integer(nBeans));
|
||||
|
||||
return new ModelAndView("acegificationResults", model);
|
||||
}
|
||||
|
||||
/** Creates a BeanFactory from the transformed XML to make sure the results are valid */
|
||||
private int createBeanFactory(String beansXml) {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(bf);
|
||||
|
||||
return beanReader.loadBeanDefinitions(new InMemoryResource(beansXml));
|
||||
}
|
||||
|
||||
}
|
19
samples/acegifier/src/java/acegifier/web/AcegifierForm.java
Normal file
19
samples/acegifier/src/java/acegifier/web/AcegifierForm.java
Normal file
@ -0,0 +1,19 @@
|
||||
package acegifier.web;
|
||||
|
||||
/**
|
||||
* Form backing object for the Acegifier controller.
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AcegifierForm {
|
||||
private String webXml;
|
||||
|
||||
public String getWebXml() {
|
||||
return webXml;
|
||||
}
|
||||
|
||||
public void setWebXml(String webXml) {
|
||||
this.webXml = webXml;
|
||||
}
|
||||
}
|
56
samples/acegifier/src/webapp/WEB-INF/acegifier-servlet.xml
Normal file
56
samples/acegifier/src/webapp/WEB-INF/acegifier-servlet.xml
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<!--
|
||||
| Spring web setup for the acegifier.
|
||||
|
|
||||
| $Id$
|
||||
-->
|
||||
|
||||
<beans>
|
||||
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
|
||||
<property name="basename"><value>messages</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="conversionController" class="acegifier.web.AcegifierController">
|
||||
<property name="formView" value="acegificationForm" />
|
||||
<property name="commandClass" value="acegifier.web.AcegifierForm"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
||||
<property name="mappings">
|
||||
<props>
|
||||
<prop key="/convert.htm">conversionController</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
<!--
|
||||
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix"><value>/WEB-INF/jsp/</value></property>
|
||||
<property name="suffix"><value>.jsp</value></property>
|
||||
</bean>
|
||||
-->
|
||||
<bean
|
||||
id="freemarkerConfig"
|
||||
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
|
||||
<property name="templateLoaderPath"><value>/WEB-INF/freemarker/</value></property>
|
||||
<property name="freemarkerVariables">
|
||||
<map>
|
||||
<entry key="xml_escape"><ref local="fmXmlEscape"/></entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
|
||||
|
||||
<bean
|
||||
id="viewResolver"
|
||||
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
|
||||
<property name="exposeSpringMacroHelpers"><value>true</value></property>
|
||||
<property name="cache"><value>true</value></property>
|
||||
<property name="prefix"><value></value></property>
|
||||
<property name="suffix"><value>.ftl</value></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
|
||||
</beans>
|
@ -0,0 +1,20 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<#import "spring.ftl" as spring />
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Acegi Security Web.xml Converter</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="POST">
|
||||
<@spring.bind "command.webXml" />
|
||||
<textarea name="webXml" rows="40" cols="80">${spring.status.value?default("Paste your web.xml here.")}</textarea>
|
||||
<br />
|
||||
<@spring.showErrors "<br />"/>
|
||||
<input type="submit" value="Convert"/>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Acegi Security Web.xml Converter</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Congratulations! Your web.xml file has been "Acegified" successfully.</p>
|
||||
|
||||
<h2>Web.xml</h2>
|
||||
<p>
|
||||
This is the converted web.xml file which you should use in your Acegi-Secured
|
||||
Spring application. It should contain the mechanism for loading the Spring application
|
||||
context file which defines your security configuration as well as the
|
||||
necessary filters to apply this configuration.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
${webXml?xml}
|
||||
</pre>
|
||||
|
||||
<h2>Acegi Security Beans</h2>
|
||||
<p>
|
||||
This is the file which defines your security configuration (a standard Spring
|
||||
application context file). It should be named "applicationContext-acegi-security.xml"
|
||||
and placed in your WEB-INF directory.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
${acegiBeansXml?xml}
|
||||
</pre>
|
||||
|
||||
<p>Note that these files may require some manual changes before they work as expected and are
|
||||
intended as a guide only :).</p>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
46
samples/acegifier/src/webapp/WEB-INF/web.xml
Normal file
46
samples/acegifier/src/webapp/WEB-INF/web.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<web-app version="2.4"
|
||||
xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
|
||||
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
/WEB-INF/applicationContext.xml
|
||||
</param-value>
|
||||
</context-param>
|
||||
|
||||
<!--
|
||||
<context-param>
|
||||
<param-name>log4jConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/classes/log4j.properties</param-value>
|
||||
</context-param>
|
||||
-->
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
<!--
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
|
||||
</listener>
|
||||
-->
|
||||
|
||||
<servlet>
|
||||
<servlet-name>acegifier</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>acegifier</servlet-name>
|
||||
<url-pattern>*.htm</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
Loading…
x
Reference in New Issue
Block a user