package com.aemreunal.config;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.DispatcherServlet;

/*
 **************************
 * Copyright (c) 2014     *
 *                        *
 * This code belongs to:  *
 *                        *
 * Ahmet Emre Ünal        *
 * S001974                *
 *                        *
 * aemreunal@gmail.com    *
 * emre.unal@ozu.edu.tr   *
 *                        *
 * aemreunal.com          *
 **************************
 */

public class WebAppInitializer implements WebApplicationInitializer {
    // TODO find out what this class is used for

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext();
//        webAppContext.register(CoreConfig.class, MVCConfig.class, SecurityConfig.class);
        webAppContext.register(CoreConfig.class, MVCConfig.class);
        servletContext.addListener(new ContextLoaderListener(webAppContext));
//        servletContext.setInitParameter("defaultHtmlEscape", "true");

        AnnotationConfigWebApplicationContext dispatchCtx = new AnnotationConfigWebApplicationContext();
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatchCtx));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");

//        configureSpringSecurity(servletContext, webAppContext);
    }

    private void configureSpringSecurity(ServletContext servletContext, WebApplicationContext rootContext) {
        FilterRegistration.Dynamic springSecurity = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain", rootContext));
        springSecurity.addMappingForUrlPatterns(null, true, "/*");
    }

}

@@ -28,49 +28,8 @@
 g;%0A%0A
-import javax.servlet.FilterRegistration;%0A
 impo
@@ -266,70 +266,8 @@
 er;%0A
-import org.springframework.web.context.WebApplicationContext;%0A
 impo
@@ -352,69 +352,8 @@
 xt;%0A
-import org.springframework.web.filter.DelegatingFilterProxy;%0A
 impo
@@ -1107,99 +1107,8 @@
 ();%0A
-//        webAppContext.register(CoreConfig.class, MVCConfig.class, SecurityConfig.class);%0A
     
@@ -1167,16 +1167,38 @@
 ig.class
+, SecurityConfig.class
 );%0A     
@@ -1273,80 +1273,8 @@
 t));
-%0A//        servletContext.setInitParameter(%22defaultHtmlEscape%22, %22true%22);
 %0A%0A  
@@ -1498,24 +1498,25 @@
 patchCtx));%0A
+%0A
         disp
@@ -1582,440 +1582,14 @@
 /%22);
-%0A%0A//        configureSpringSecurity(servletContext, webAppContext);%0A    %7D%0A%0A    private void configureSpringSecurity(ServletContext servletContext, WebApplicationContext rootContext) %7B%0A        FilterRegistration.Dynamic springSecurity = servletContext.addFilter(%22springSecurityFilterChain%22, new DelegatingFilterProxy(%22springSecurityFilterChain%22, rootContext));%0A        springSecurity.addMappingForUrlPatterns(null, true, %22/*%22);
 %0A    %7D%0A%0A
 %7D%0A
@@ -1586,10 +1586,11 @@
 %0A    %7D%0A%0A
+%0A
 %7D%0A

Remove clutter