IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Authentification Spring avec LDAP


Sujet :

Spring Java

  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    180
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 180
    Par défaut Authentification Spring avec LDAP
    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

  2. #2
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    salut,
    jettes un coup d´oeil ici pour voir ce cela peux t´aider :
    http://docs.spring.io/spring-securit...ence/ldap.html

    Eric

Discussions similaires

  1. Réponses: 3
    Dernier message: 29/09/2009, 17h27
  2. Squid et authentification "digest" avec LDAP
    Par juju1989 dans le forum Sécurité
    Réponses: 1
    Dernier message: 11/08/2009, 10h25
  3. [Spring Security] Authentification par groupe LDAP
    Par titeuf92 dans le forum Spring Web
    Réponses: 2
    Dernier message: 25/06/2008, 10h28
  4. Authentification avec LDAP / Jboss
    Par otterley dans le forum Wildfly/JBoss
    Réponses: 1
    Dernier message: 11/04/2008, 12h10
  5. [LDAP] authentification domaine avec LDAP
    Par Thylia dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 17/07/2006, 16h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo