salut,

dans mon application j'utilise ma base de donnée pour faire l'authentification

dans security-app-context.xml j'ai ce code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                    http://www.springframework.org/schema/security 
                    http://www.springframework.org/schema/security/spring-security-3.1.xsd">
 
    <http auto-config="true" use-expressions="true">
        <intercept-url pattern="/administration/**" access="hasRole('ADMIN')" />
        <intercept-url pattern="/citizen/**" access="hasRole('USER')" />
        <form-login login-page="/index.htm" authentication-success-handler-ref="authenticationSuccessRedirecthandler"
          default-target-url = "/citizen/test.htm"
            authentication-failure-url="/index.htm?error=1"/>
        <logout logout-success-url="/index.htm" />
    </http>
 
    <beans:bean class="com.test.redirect.CustomAuthenticationHandler" id="authenticationSuccessRedirecthandler"></beans:bean>
 
    <authentication-manager>
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource" users-by-username-query="select username, password, enabled from users where username=?" authorities-by-username-query="select u.username, ur.authority from users u, user_roles ur where u.user_id = ur.user_id and u.username =?  " />
        </authentication-provider>
    </authentication-manager>
</beans:beans>
dans CustomAuthenticationHandler.java j'ai ce code :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.IOException;
import java.util.Set;
 
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
 
public class CustomAuthenticationHandler extends SimpleUrlAuthenticationSuccessHandler {
 
 @Override
 public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
 
     String targetUrl = "/test/page.htm";
 
      Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
 
 
      if (roles.contains("ADMIN")) {
 
         getRedirectStrategy().sendRedirect(request, response, targetUrl);
      }  else {
         super.onAuthenticationSuccess(request, response, authentication);
         return;
      }
   }
}
pour le moment je veux faire l'authentification avec ldap et non pas avec base de donnée

voici quelques paramètres de ldap :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Base Provider URL
ldap://192.168.0.88:389
 
Base DN
 
DC=MINISTER,DC=FR
 
Principal
 
CN=LDAP Requester,OU=Users,OU=Technical Accounts,OU=P9 Accounts,DC=MINISTER,DC=FR
 
Credentials
 
minister$9999
 
Users
 
Authentication Search Filter
 
(&(objectClass=person)(mail=@email_address@))
 
Users DN DC=MINISTER,DC=FR
 
Groups DN DC=MINISTER,DC=FR

merci d'avance