2

I'm have a problem with Primefaces CommandButton action not being invoked with Spring Security. Without Spring Security is OK. I don't understand why. Can you help me?

I use Primefaces 5.2. and Spring Security 4.0.2.

I have a managed 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"); 
} 
}

And login page with

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

My Spring Security config

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

}
1
  • Did you find any solution? If so, please share as answer.
    – Selcuk
    Sep 22, 2017 at 21:44

1 Answer 1

0

In the outgoing flow probably there is no redirect-url in the response. There is only update. If request is ajax request web browser doesnt translate redirects on XMLHttpRequest. You need to create this optional response yourself. Also you can try these pratically:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.