2012-01-13 173 views
1

我正在尝试实现自定义登录页面以在我的JSF 2.0应用程序中使用。我正在使用spring security 3.0.5,并且在用户登录后,页面没有正确重定向。而不是去请求的页面(本地主机:8080/ERP的Web),它是将这样的:无法从登录页面重定向

http://localhost:8080/erp-web/javax.faces.resource/forms/forms.js.xhtml?ln=primefaces&v=2.2.1

这是我的JSF页面:

<h:form prependId="false"> 
    <h:panelGroup layout="block" class="hrgi-dialog-content hrgi-div-form clearfix"> 
     <p:focus/>    
     <h:outputLabel for="j_username"/> 
     <p:inputText id="j_username" value="#{loginBean.usuario}" required="true"/> 
     <h:outputLabel for="j_password"/> 
     <h:inputSecret id="j_password" value="#{loginBean.senha}" required="true"/> 
     <h:commandButton id="submit" type="submit" value="OK" action="#{loginBean.submit}"/> 
    </h:panelGroup> 
</h:form> 

这是用绿豆:

public class LoginBean { 

    private String usuario; 
    private String senha; 

    public String submit() throws IOException, ServletException { 
     ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); 
     RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/j_spring_security_check"); 
     dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse()); 
     FacesContext.getCurrentInstance().responseComplete(); 
     return null; 
    } 

/*getters and setters here*/ 

} 

最后,这是我的春天安全配置文件:

<http auto-config="true"> 
    <intercept-url pattern="/login.xhtml*" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
    <intercept-url pattern="/**" access="ROLE_CADASTRADOR,ROLE_ADMINISTRADOR,ROLE_VENDEDOR,ROLE_BANCO"/> 
    <form-login login-page="/login.xhtml"/> 
    <session-management> 
     <concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/> 
    </session-management> 
</http> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider ref="daoAuthenticationProvider"/> 
</authentication-manager> 

<bean:bean id="daoAuthenticationProvider" 
      class="org.springframework.security.authentication.dao.DaoAuthenticationProvider" 
      scope="singleton"> 
    <bean:property name="userDetailsService" ref="detalhadorDeUsuarios"/> 
    <bean:property name="passwordEncoder" ref="passwordEncoder"/> 
</bean:bean> 

<bean:bean id="detalhadorDeUsuarios" class="com.hrgi.web.seguranca.DetalhadorDeUsuarios" 
      scope="singleton"> 
    <bean:property name="recuperador" ref="funcionarioDao"/> 
</bean:bean> 

<bean:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder" 
      scope="singleton"> 
    <bean:constructor-arg name="strength" value="256"/> 
</bean:bean> 

<bean:bean id="loginBean" class="com.hrgi.web.seguranca.LoginBean" scope="request"/> 


<bean:bean id="loggerListener" 
     class="org.springframework.security.authentication.event.LoggerListener" /> 

这是我收到的回应: after login app is redirecting to wrong place

+1

我不会做Spring,但我敢打赌它是Spring方面的一个bug。看起来好像没有考虑到'/ javax.faces.resource'请求,同时检查最后一个请求的URL,它与'FacesServlet'相匹配。 – BalusC 2012-01-13 04:50:54

回答

2

您应该添加JS/CSS资源不受限制,像

<intercept-url pattern="/**/*.css*" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
<intercept-url pattern="/**/*.js*" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 

问题是春季安全截获您的JS要求登录页面所需的文件并强制进行身份验证。完成后,它会重定向到最近的受限制网址,JavaScript就是您的情况。