spring mvc security tiles redirect

时间:2016-07-10 15:50:27

标签: spring redirect spring-security tiles

我遇到了一个重定向图块页面的问题。我不确定这是否与弹簧安全性相结合是一个问题。

问题

我想提交表单,做一些事情并将参数重定向到表单的页面。什么都不令人兴奋,但它没有运行...... 使用此配置,我只获得一个空白页面。没有任何错误。如果我使用浏览器记录网络流量,我得到以下响应 - 标题:

Cache-Control   
no-cache, no-store, max-age=0, must-revalidate
Content-Language    
de
Content-Length  
0
Date    
Sun, 10 Jul 2016 14:04:58 GMT
Expires 
0
Location:    FileAdmin/csvFileImport_form?totalTime=test
Pragma  
no-cache
Server  
Apache-Coyote/1.1
X-Frame-Options :    DENY
X-XSS-Protection    
1; mode=block
x-content-type-options  
nosniff

所以似乎重定向正在运行。有人知道我的错误和问题吗?

我google了很多,所以这里是当前的文件:

MvcConfig:

 public class MvcConfig extends WebMvcConfigurerAdapter {

    private static final Logger l = LoggerFactory.getLogger(MvcConfig.class);

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LocaleInterceptor());
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("main/home");
        registry.addViewController("/403").setViewName("main/403");
    }

    @Bean(name = "dataSource")
    public DriverManagerDataSource dataSource() {
        DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
        driverManagerDataSource.setDriverClassName("net.sourceforge.jtds.jdbc.Driver");
        driverManagerDataSource.setUrl("jdbc:jtds:sqlserver://localhost:1433/AID");
        driverManagerDataSource.setUsername("");
        driverManagerDataSource.setPassword("");
        return driverManagerDataSource;
    }

 // --------------------------------------------------
 // Hybernate-Configurations
 // --------------------------------------------------

    @Bean
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(dataSource());
        sessionFactory.setPackagesToScan(new String[] { "aid.main.model" });
        sessionFactory.setHibernateProperties(hibernateProperties());
        return sessionFactory;
     }


    private Properties hibernateProperties() {
        Properties properties = new Properties();
        // org.hibernate.dialect.Dialect -> mssql!?
        // "org.hibernate.dialect.MySQLDialect" -> mysql
        properties.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
        properties.put("hibernate.show_sql", true);
        properties.put("hibernate.format_sql", true);
        return properties;        
    }

    @Bean
    public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
       return new PersistenceExceptionTranslationPostProcessor();
    }

    @Bean
    @Autowired
    public HibernateTransactionManager transactionManager(SessionFactory s) {
       HibernateTransactionManager txManager = new HibernateTransactionManager();
       txManager.setSessionFactory(s);
       return txManager;
    }

// --------------------------------------------------
// Tiles, JSP, VIEW-Configurations
// --------------------------------------------------
    /**
     * Configure ViewResolvers to deliver preferred views.
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        l.info(this.getClass().getName() + ".configureViewResolvers");
        TilesViewResolver viewResolver = new TilesViewResolver();
        registry.viewResolver(viewResolver);
    }

    /**
     * Configure ResourceHandlers to serve static resources like CSS/ Javascript etc...
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        l.info(this.getClass().getName() + ".addResourceHandlers");
        registry.addResourceHandler("/resources/static/**").addResourceLocations("/resources/static/");
    }

    @Bean
    public TilesConfigurer tilesConfigurer() {
        l.info(this.getClass().getName() + ".tilesConfigurer");
        TilesConfigurer tilesConfigurer = new TilesConfigurer();
        tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/tiles-defs.xml" });
        tilesConfigurer.setPreparerFactoryClass(org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory.class);
        tilesConfigurer.setCheckRefresh(true);
        return tilesConfigurer;
    }

    /*
     * Configure ContentNegotiatingViewResolver
     */
    @Bean
    public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager) {
        ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
        resolver.setContentNegotiationManager(manager);
        resolver.setOrder(1);
        TilesViewResolver viewResolver = new TilesViewResolver();
        // Define all possible view resolvers
        List<ViewResolver> resolvers = new ArrayList<ViewResolver>();

        resolvers.add(jsonViewResolver());
        resolvers.add(viewResolver);

        resolver.setViewResolvers(resolvers);
        return resolver;
    }

    /*
     * Configure View resolver to provide JSON output using JACKSON library to
     * convert object in JSON format.
     */
    @Bean
    public ViewResolver jsonViewResolver() {
        return new JsonViewResolver();
    }

    public class JsonViewResolver implements ViewResolver{

        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            MappingJackson2JsonView view = new MappingJackson2JsonView();
            view.setPrettyPrint(true);       
            return view;
          }

    }


}

tiles.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>

    <definition name="defaultTemplate" template="/WEB-INF/main/layout.jsp">
        <put-attribute name="header" value="/WEB-INF/main/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/main/main_menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/main/footer.jsp" />
    </definition>
  <!-- Login -->
  <definition name="/login" extends="defaultTemplate">  
       <put-attribute name="title" value="Welcome" />  
       <put-attribute name="body" value="/WEB-INF/main/login.jsp" />  
   </definition>
   <definition name="/home" extends="defaultTemplate">  
       <put-attribute name="title" value="Welcome" />  
       <put-attribute name="body" value="/WEB-INF/main/home.jsp" />  
   </definition>
   <definition name="/hello" extends="defaultTemplate">  
       <put-attribute name="title" value="Welcome" />  
       <put-attribute name="body" value="/WEB-INF/main/hello.jsp" />  
   </definition>
  <!-- CSV-Change / Import -->
   <definition name="FileAdmin/csvChange_form" extends="defaultTemplate">  
       <put-attribute name="title" value="Welcome" />  
       <put-attribute name="body" value="/WEB-INF/FileAdmin/csvChange_form.jsp" />  
   </definition>  
   <definition name="FileAdmin/csvFileImport_form" extends="defaultTemplate">  
       <put-attribute name="title" value="Welcome" />  
       <put-attribute name="body" value="/WEB-INF/FileAdmin/csvFileImport_form.jsp" />  
   </definition>  
    <definition name="FileAdmin/importCsvFiles" extends="defaultTemplate">  
       <put-attribute name="title" value="Welcome" />  
       <put-attribute name="body" value="/WEB-INF/FileAdmin/csvFileImport_results.jsp" />  
   </definition>  

     <!-- App-Install -->
   <definition name="main/appinstall_loginform" extends="defaultTemplate">  
       <put-attribute name="title" value="App-Install" />  
       <put-attribute name="body" value="/WEB-INF/main/appinstall_loginform.jsp" />  
   </definition> 
    <definition name="main/appinstall_verify" extends="defaultTemplate">  
       <put-attribute name="title" value="Verify" />  
       <put-attribute name="body" value="/WEB-INF/main/appinstall_verify.jsp" />  
   </definition> 
   <definition name="main/appinstall_init" extends="defaultTemplate">  
       <put-attribute name="title" value="Init" />  
       <put-attribute name="body" value="/WEB-INF/main/appinstall_init.jsp" />  
   </definition> 

     <!-- ProjectAdmin -->
   <definition name="projectAdmin/listAll" extends="defaultTemplate">  
       <put-attribute name="title" value="App-Install" />  
       <put-attribute name="body" value="/WEB-INF/projectAdmin/list.jsp" />  
   </definition> 
    <definition name="projectAdmin/addEdit_form" extends="defaultTemplate">  
       <put-attribute name="title" value="Verify" />  
       <put-attribute name="body" value="/WEB-INF/projectAdmin/addEdit_form.jsp" />  
   </definition> 

</tiles-definitions>

控制器:

    public class CsvFileImporterController {
    private static final Logger l = LoggerFactory.getLogger(CsvFileImporterController.class);

    @Autowired
    ProcessStatusServiceIF pStatService;

    @RequestMapping(value = "/FileAdmin/csvFileImport_form", method={RequestMethod.GET,RequestMethod.POST})
    public String csvFileImport_form(HttpServletRequest request
                        , HttpServletResponse response
                        , HttpSession session) {
        l.info(this.getClass().getName() + ".csvFileImport_form");
        l.info(request.getParameter("status"));
        ModelAndView model = new ModelAndView();
        model.setViewName("FileAdmin/csvFileImport_form");
        return "FileAdmin/csvFileImport_form";
    }

    @RequestMapping(value = "/FileAdmin/importCsvFiles", method=RequestMethod.POST)
    @ResponseStatus(value=HttpStatus.OK)
    public String importCsvFiles(   @RequestParam(required=false, value="firstrowHeaders") Boolean firstrowHeaders
                                        , @RequestParam(required=false, value="recursivly") Boolean recursivly
                                        , @RequestParam(required=false, value="header_oneFile") Boolean header_oneFile
                                        , HttpServletRequest request
                                        , HttpServletResponse response
                                        ) throws ServletException, IOException {

        //ModelAndView rView = new ModelAndView("FileAdmin/csvFileImport_results");
        return "redirect:FileAdmin/csvFileImport_form";
    }

}

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>aid.main</groupId>
    <artifactId>AID</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AID</name>
    <description>Automated intelligent Dataanalytics</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <springframework.version>4.2.5.RELEASE</springframework.version>
        <springsecurity.version>4.0.4.RELEASE</springsecurity.version>
        <hibernate.version>5.0.0.CR2</hibernate.version>
        <mysql.connector.version>5.1.31</mysql.connector.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-java8</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
         <!-- JDBC Drivers -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>


        <dependency>
            <groupId>com.univocity</groupId>
            <artifactId>univocity-parsers</artifactId>
            <version>2.1.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.0</version>
        </dependency>

        <!-- Apache Tiles -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId>
            <version>3.0.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>3.0.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>3.0.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId>
            <version>3.0.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-template</artifactId>
            <version>3.0.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-el</artifactId>
            <version>3.0.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-cypher-compiler-2.1</artifactId>
            <version>2.1.8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

非常感谢你的帮助!

0 个答案:

没有答案