首页 > 解决方案 > Spring Security + Primefaces - 无法处理 viewexpiredeception

问题描述

我在 spring security 和 primefaces 配置方面遇到问题。对于我的项目,我需要能够登录,因此决定添加 Spring Security。在我添加 Spring Security 之前,它是这样的:如果用户打开页面并空闲半小时,则会话终止,页面上的按钮停止工作,当按下按钮时,我在 IDE 的控制台中得到 viewexpiredexception . 然后我更改了 web.xml 和 faces-config.xml 文件:

网页.xml:

<!-- File(s) appended to a request for a URL that is not mapped to a web component -->
<welcome-file-list>
    <welcome-file>mypage.xhtml</welcome-file>
</welcome-file-list>

<error-page>
    <exception-type>
        javax.faces.application.ViewExpiredException
    </exception-type>
    <location>/login.xhtml</location> <!-- type whatever suits your environment and requirements -->
</error-page>

<!-- Define the JSF servlet (manages the request processing life cycle for JavaServer Faces) -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map following files to the JSF servlet -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>

面孔-config.xml

<application>
    <el-resolver>
        org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
    </el-resolver>
</application>
<factory>
    <exception-handler-factory>
        org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
    </exception-handler-factory>
</factory>

之后,如果会话终止并且用户按下任何按钮,他将收到一条消息,说明会话已终止并将被重定向到页面。

问题:在我添加了弹簧安全之后,一切都停止了。半小时不活动后,当我没有viewexpiredexception的处理程序时,按钮像以前一样停止工作,但是控制台中没有异常并且没有重定向,用户必须自己刷新页面。这是我的配置:

安全配置.java

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter { 
@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().antMatchers("/javax.faces.resource/**")
            .permitAll().anyRequest().authenticated();
    // login
    http.formLogin().loginPage("/login.xhtml").permitAll()
            .failureUrl("/login.xhtml?error=true");
    http.sessionManagement()
            .maximumSessions(1)
            .expiredUrl("/login.xhtml")
            .and()
            .invalidSessionUrl("/login.xhtml");

    // logout
    http.logout().logoutSuccessUrl("/login.xhtml");
    // not needed as JSF 2.2 is implicitly protected against CSRF
    http.csrf().disable();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
        throws Exception {
    auth.inMemoryAuthentication().withUser("john.doe")
            .password("{noop}1234").roles("USER").and()
            .withUser("jane.doe").password("{noop}5678").roles("ADMIN");
}

}

我找不到如何解决我的问题。

标签: springjsfspring-securityprimefaces

解决方案


推荐阅读