Spring Security + Primefaces-无法处理ViewExpireDeception

时间:2019-09-06 14:16:51

标签: spring jsf spring-security primefaces

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

web.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>

faces-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>

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

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

SecurityConfig.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");
}

}

我找不到解决问题的方法。

0 个答案:

没有答案