【问题标题】:CommandButton action not being invoked with Spring Security未使用 Spring Security 调用 CommandButton 操作
【发布时间】:2016-01-12 06:21:42
【问题描述】:

我遇到了一个问题,即没有使用 Spring Security 调用 Primefaces 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()}" />

我的 Spring Security 配置

@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();
}

}

【问题讨论】:

  • 您找到解决方案了吗?如果是这样,请分享作为答案。

标签: spring jsf primefaces spring-security


【解决方案1】:

在传出流中,响应中可能没有重定向 URL。只有更新。如果请求是 ajax 请求,Web 浏览器不会翻译 XMLHttpRequest 上的重定向。您需要自己创建此可选响应。您也可以实际尝试这些:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 2013-05-03
    • 1970-01-01
    相关资源
    最近更新 更多