2015-10-14 86 views
2

我遇到了未被Spring Security调用的Primefaces CommandButton操作的问题。没有Spring安全性就没问题。 我不明白为什么。你可以帮我吗?CommandButton操作未被Spring Security调用

我使用Primefaces 5.2。和Spring Security 4.0.2。

我有一个托管bean

@Getter 
@Setter 
@ManagedBean 
@ViewScoped 
public class LoginController implements Serializable { 

private static final long serialVersionUID = 1L; 

private String userName = "admin"; 
private String password = "123"; 

public void doLogin() { 
    System.out.println("test"); 
} 
} 

而且随着

<p:commandButton value="Войти в систему" action="#{loginController.doLogin()}" /> 

我的春季安全配置

@Configuration 
@EnableWebSecurity 
public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter { 

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
    http 
      .authorizeRequests() 
      .antMatchers("/javax.faces.resource/**").permitAll() 
      .antMatchers("/**").access("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')") 
      .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')") 
      .and() 
      .formLogin() 
      .loginPage("/pages/security/login.xhtml") 
      .permitAll() 
      .and() 
      .logout() 
      .logoutSuccessUrl("/pages/security/login.xhtml?logout") 
      .permitAll(); 
} 

} 
+0

您是否找到任何解决方案?如果是这样,请分享作为答案。 – tylerdurden

回答

0

登录页面,在外出流动有可能是没有重定向的URL中响应。只有更新。如果请求是ajax请求,Web浏览器不会转换XMLHttpRequest上的重定向。你需要自己创建这个可选的响应。您也可以尝试这些实际操作:

<p:commandButton value="Войти в систему" action="#{loginController.doLogin()}" ajax="false" />