Spring Security,JSF - loadUserByUsername用户名为null

时间:2014-06-15 02:09:03

标签: java spring security jsf

我在loadUserByUsername()Spring Security中遇到一个问题,因为转到loadUserByUsername()时的用户名是空的。我检查了其他帖子,但问题仍然存在。 继续我的进步......

1- security.xml:

<form-login 
login-page="/login.xhtml" 
login-processing-url="/j_spring_security_check" 
username-parameter="usuario" 
password-parameter="password"    
/>
...
<authentication-manager>
 <authentication-provider user-service-ref="springSecurityUserContext" /> 
</authentication-manager>

2- SpringSecurityUserContext.java

@Component
public class SpringSecurityUserContext implements UserDetailsService{
 @Override
 public UserDetails loadUserByUsername(String arg0) 
  throws UsernameNotFoundException {
    // arg0 is empty
     ...
}

3- LoginManagedBean.java

@Component
public class LoginManagedBean {

    private String usuario;
    private String password;

    public String login() throws ServletException, IOException{
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

        RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
                .getRequestDispatcher("/j_spring_security_check");

// attributes username y password arrive well
        dispatcher.forward((ServletRequest) context.getRequest(),
                (ServletResponse) context.getResponse());

        FacesContext.getCurrentInstance().responseComplete();

        return null;
    }

4- login.xhtml

    <h:form id="loginForm" prependId="false" method="post" >
      usuario: <p:inputText id="username" name="username" 
value="#{loginManagedBean.usuario}"/>
      password: <p:inputText id="password" name="password" 
        value="#{loginManagedBean.password}"/>
      <p:commandButton type="submit" ajax="false" value="ingresar"  
        action="#{loginManagedBean.login}" />
美好的一天! :)

0 个答案:

没有答案