spring - 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");
}
}
我找不到如何解决我的问题。
解决方案
推荐阅读
- .net - 两个应用程序使用同一个 Firebird 数据库
- ios - 这里 Maps API - iPad EXC_BAD_ACCESS 错误
- sql - 在 WHERE 子句上使用临时日期时导致无效日期错误
- karate - 如何使用空手道在 xml 中声明一个值
- php - 使用 FPDF 下载特定目录中的文件
- css - 使用 ::before 创建项目符号后缩进整个列表项
- google-maps - 如何更改角度谷歌地图中先前单击的标记的图标
- sql-server - 在视图中找出有问题的字段名称
- c# - 如何在 Resharper 单元测试会话查看器中获取输出以“流式传输”其输出,而不是在测试结束时转储它?
- sql - Oracle SQL - 如何在选择中将多行合并为一个