mardi 14 avril 2015

spring security and Ldap authentication with jsf

I'm creating application with spring security 3 using the protocole Ldap,and JSF 2 the problem is that I have always authentication failure ! this is my configuration :



<http use-expressions="true" >
<intercept-url pattern="/pages/DRH/**" access="hasRole('ROLE_ADM')" />
<intercept-url pattern="/pages/Employe/**" access="hasRole('ROLE_EMP')" />
<!-- Custom login page -->
<form-login login-page="/login.jsf" authentication-success-handler-ref="loginSuccessHandler"
authentication-failure-handler-ref="loginFailureHandler" />

<!-- Custom logout page -->
<logout />
</http>
<beans:bean id="loginSuccessHandler" class="exp.customloginpage.AuthSuccessHandler" />
<beans:bean id="loginFailureHandler" class="exp.customloginpage.AuthFailureHandler" />
<!-- Use authentication provider. -->
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg index="0" value="ldap://192.168.6.42:389/cn=Users,dc=exp,dc=com" />
</beans:bean>
<beans:bean id="ldapUserSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">

<beans:constructor-arg index="0" value=""/>
<beans:constructor-arg index="1" value="(uid={0})"/>
<beans:constructor-arg index="2" ref="contextSource" />
<beans:property name="searchSubtree" value="true" /> <!-- Recherche dans les sous-branches -->
</beans:bean>

<beans:bean id="userDetailsAuthoritiesPopulator" class="exp.customloginpage.UserDetailsAuthoritiesPopulator" />
<beans:bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<beans:constructor-arg index="0">
<beans:bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
<beans:constructor-arg index="0" ref="contextSource" />
<beans:property name="userSearch" ref="ldapUserSearch" />
</beans:bean>
</beans:constructor-arg>
<beans:constructor-arg index="1">
<beans:bean class="exp.customloginpage.UserDetailsAuthoritiesPopulator" />
</beans:constructor-arg>
</beans:bean>

<authentication-manager>
<authentication-provider ref="ldapAuthProvider" />
</authentication-manager>


this is my managedBean



public String doLogin() throws ServletException, IOException {

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;

}


Any Idea ?


Aucun commentaire:

Enregistrer un commentaire