2015-10-14 33 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" />