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 :

Configuration avec LDAP


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 13
    Par défaut Configuration avec LDAP
    Bonjour,

    J'essaie d'intégrer Spring Security 3.0.1 sous LDAP

    Mon fichier de configuration est le suivant :
    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    <beans
            xmlns="http://www.springframework.org/schema/beans"
            xmlns:security="http://www.springframework.org/schema/security"
            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">
     
        <bean id="contextSource" class="org.springframework.security.ldap.DefaultSp ringSecurityContextSource">
            <constructor-arg value="ldap://192.168.198.131:389/dc=xtensus,dc=com"/>
            <property name="userDn" value="cn=admin,dc=xtensus,dc=com"/>
            <property name="password" value="ikhlass"/>
        </bean>
     
        <bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentic ation.LdapAuthenticationProvider">
            <constructor-arg>
                <bean class="org.springframework.security.ldap.authentic ation.BindAuthenticator">
                    <constructor-arg ref="contextSource"/>
                    <property name="userDnPatterns">
                        <list><value>uid={0},ou=people</value></list>
                    </property>
                </bean>
            </constructor-arg>
            <constructor-arg>
                <bean class="org.springframework.security.ldap.userdetai ls.DefaultLdapAuthoritiesPopulator">
                    <constructor-arg ref="contextSource"/>
                    <constructor-arg value="ou=Groups"/>
                    <property name="groupRoleAttribute" value="ou"/>
                </bean>
            </constructor-arg>
        </bean>
     
        <bean class="org.springframework.security.ldap.userdetai ls.DefaultLdapAuthoritiesPopulator">
            <constructor-arg ref="contextSource"/>
            <constructor-arg value="ou=groups"/>
            <property name="groupRoleAttribute" value="ou"/>
        </bean>
     
        <bean id="userSearch" class="org.springframework.security.ldap.search.Fi lterBasedLdapUserSearch">
            <constructor-arg index="0" value=""/>
            <constructor-arg index="1" value="(uid={0})"/>
            <constructor-arg index="2" ref="contextSource" />
        </bean>
     
    </beans>
    et j'obtiens cette erreur :
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd schema with Spring Security 3.1. Please update your schema declarations to the 3.1 schema.
    Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?

    Merci d'avance pour votre aide.

  2. #2
    Membre chevronné
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2011
    Messages : 251
    Par défaut
    Si tu essaies d'intégrer spring security 3.0.1, la xsd déclarée n'est pas la bonne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://www.springframework.org/schema/security/spring-security-3.1.xsd
    C'est du 3.0.1 ou du 3.1 ?

  3. #3
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,

    Je ne sais pas si c'est du à une mauvaise copier/coller mais tu as des espaces qui trainent par tout.
    <bean id="contextSource" class="org.springframework.security.ldap.DefaultSp ringSecurityContextSource">
    <bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentic ation.LdapAuthenticationProvider">
    ...

    A+.

  4. #4
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 13
    Par défaut
    Pour les espaces c'était dû à un mauvais copier/coller...

    J'ai résolu le problème de la version du schéma avec cette configuration mais maintenant c'est au niveau de l'authentification que ça bloque. C'est-à-dire que lorsque je m'authentifie avec un utilisateur qui se trouve dans la base de données ça passe mais avec un utilisateur créé au niveau de l'annuaire LDAP, ça ne passe pas et il ne peut pas s'authentifier.

    Le fichier security-ldap.xml est le suivant:
    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans
        xmlns="http://www.springframework.org/schema/security"
        xmlns:security="http://www.springframework.org/schema/security"
        xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:lang="http://www.springframework.org/schema/lang"
     
        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.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
     
        <!-- ******************************************************************** -->
        <!-- This context file was generated and is not intended to be changed manually. -->
        <!-- ******************************************************************** -->
     
        <!-- Déclaration de la DATASOURCE -->
        <beans:bean
            id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <beans:property
                name="driverClassName"
                value="com.mysql.jdbc.Driver" />
            <beans:property
                name="url"
                value="jdbc:mysql://localhost:3306/xtensusgmp2" />
            <beans:property
                name="username"
                value="gmp" />
            <beans:property
                name="password"
                value="gmp" />
        </beans:bean>
     
        <!-- Stratégie de Sécurité : ressources et Remember me -->
        <security:http
            auto-config="true"
            access-denied-page="/viewsGMP2/accessDenied.jsf">
            <security:intercept-url
                pattern="/viewsGMP2/login2.jsf*"
                filters="none" />
            <security:intercept-url
                pattern="../framGraphique/xte-style-gmp.css"
                filters="none" />
            <security:intercept-url
                pattern="../framGraphique/images/**"
                filters="none" />
            <security:intercept-url
                pattern="/viewsGMP2/login.jsf*"
                filters="none" />
            <security:form-login
                login-processing-url="/j_spring_security_check"
                login-page="/viewsGMP2/login.jsf"
                default-target-url="/viewsGMP2/Ajout-groupe1.jsf"
                authentication-failure-url="/viewsGMP2/login2.jsf" />
            <security:logout logout-success-url="/viewsGMP2/login.jsf" />
     
            <security:intercept-url
                pattern="/viewsGMP2/**"
                access="ROLE_PARTICIPANT,ROLE_ADMIN,ROLE_COMMERCIAL,ROLE_FORMATEUR,ROLE_MAINTENANCE,ROLE_FORMATEUR" />
     
        </security:http>
        <!-- injection du provider au gestionnaire de securite de l application -->
     
        <!-- Authentification via base de données -->
        <beans:bean
            id="myUserDetailsService"
            class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
            <beans:property
                name="dataSource"
                ref="dataSource" />
     
            <!-- <beans:property name="usersByUsernameQuery" value="SELECT utilisateursLogin as username, utilisateursMotDePasse ,enabled , utilisateursNom , utilisateursPrenom FROM utilisateurs WHERE utilisateursLogin = ?" /> <beans:property name="authoritiesByUsernameQuery" value="SELECT utilisateursLogin as username, role FROM roles WHERE utilisateursLogin = ?" /> -->
        </beans:bean>
     
        <!-- authenticate the user with ldapAuthenticator using userSearch -->
     
        <!--<beans:bean id = "contextSource" class = "org.springframework.security.ldap.DefaultSpringSecurityContextSource"> <beans:constructor-arg value="ldap://192.168.198.131:389/dc=xtensus,dc=com"/> <beans:property name="userDn" value="cn=admin,dc=xtensus,dc=com"/> <beans:property name="password" value="ikhlass"/> </beans:bean> -->
     
        <ldap-server
            id="contextSource"
            url="ldap://192.168.198.131:389"
            manager-dn="cn=admin,dc=xtensus,dc=com"
            manager-password="ikhlass"></ldap-server>
     
        <beans:bean
            id="userSearch"
            class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
            <beans:constructor-arg
                index="0"
                value="ou=people" />
            <beans:constructor-arg
                index="1"
                value="(uid={0})" />
            <beans:constructor-arg
                index="2"
                ref="contextSource" />
     
        </beans:bean>
     
        <beans:bean
            id="ldapAuthProvider"
            class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
            <beans:constructor-arg>
                <beans:bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
                    <beans:constructor-arg ref="contextSource" />
                    <beans:property
                        name="userSearch"
                        ref="userSearch" />
                </beans:bean>
            </beans:constructor-arg>
            <beans:constructor-arg>
                <beans:bean
                    id="userDetailsService"
                    class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
                    <beans:constructor-arg ref="contextSource" />
                    <beans:constructor-arg value="ou=Groups" />
                    <beans:property
                        name="groupRoleAttribute"
                        value="ou" />
                </beans:bean>
            </beans:constructor-arg>
     
        </beans:bean>
        <!-- <security:authentication-manager> <security:ldap-authentication-provider user-search-filter="(uid={0})" user-search-base="ou=people" group-search-filter="(uniqueMember={0})" group-search-base="ou=Groups" group-role-attribute="cn" role-prefix="ROLE_"> </security:ldap-authentication-provider> </security:authentication-manager> -->
        <!-- <security:authentication-manager> <security:authentication-provider ref="ldapAuthProvider"/> </security:authentication-manager> -->
     
        <security:authentication-manager alias="authentificationManager">
            <!-- reference provider LDAP -->
            <security:authentication-provider ref="ldapAuthProvider">
            </security:authentication-provider>
            <!-- reference provider BD JDBC -->
            <security:authentication-provider>
                <jdbc-user-service
                    data-source-ref="dataSource"
                    users-by-username-query="SELECT utilisateursLogin as username, utilisateursMotDePasse, enabled, utilisateursNom, utilisateursPrenom FROM utilisateurs WHERE utilisateursLogin = ?"
                    authorities-by-username-query="SELECT utilisateursLogin as username, role FROM roles WHERE utilisateursLogin = ?" />
     
            </security:authentication-provider>
        </security:authentication-manager>
     
    </beans:beans>
    Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?

    Merci d'avance pour votre aide.

  5. #5
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 13
    Par défaut Gestion des droits d'accès aux menus avec Spring Security3
    Bonjour,

    pour le problème des utilisateurs,je l'ai résolu en ajoutant table rôle dans la base de données,c'est à dire,mon utilisateur se trouve dans LDAP et mysql au même temps,et s'il ne possède pas de rôle dans la BD,je peux pas s'y authentifié.
    pour le moment,j'ai un autre problème:
    voici mon fichier spring security:
    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/security" 
        xmlns:security="http://www.springframework.org/schema/security"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:context="http://www.springframework.org/schema/context" 
    	xmlns:lang="http://www.springframework.org/schema/lang"
    	xmlns:sec="http://www.springframework.org/security/tags"
    	
    	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.0.xsd
          	http://www.springframework.org/schema/context 
          	http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    	<!-- ******************************************************************** -->
    	<!-- This context file was generated and is not intended to be changed manually. -->
    	<!-- ******************************************************************** -->
    
        <!-- Déclaration de la DATASOURCE -->
    
    	  <beans:bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<beans:property name="url" value="jdbc:mysql://localhost:3306/xtensusgmp2" />
    		<beans:property name="username" value="gmp" />
    		<beans:property name="password" value="gmp" />
    	</beans:bean>
    	
    	
        <!-- Stratégie de Sécurité : ressources et Remember me -->
     <global-method-security secured-annotations="enabled" />
     
     <security:http auto-config="true" access-denied-page="/viewsGMP2/accessDenied.jsf">
      <security:intercept-url pattern="/viewsGMP2/login2.jsf*"
       filters="none" />
      <security:intercept-url pattern="../framGraphique/xte-style-gmp.css"
       filters="none" />
       <security:intercept-url pattern="../framGraphique/images/**"
       filters="none" />
       <security:intercept-url pattern="/viewsGMP2/login.jsf*"
       filters="none" />
       <security:form-login  login-processing-url="/j_spring_security_check"
                login-page="/viewsGMP2/login.jsf"
                default-target-url="/viewsGMP2/Ajout-groupe1.jsf"
       authentication-failure-url="/viewsGMP2/login2.jsf" />
      <security:logout logout-success-url="/viewsGMP2/login.jsf" />
      
      <security:intercept-url pattern="/viewsGMP2/**"
       access="ROLE_PARTICIPANT,ROLE_ADMIN,ROLE_COMMERCIAL,ROLE_FORMATEUR,ROLE_MAINTENANCE,ROLE_FORMATEUR" />
     
    <!-- <sec:authorize ifAnyGranted="ROLE_PARTICIPANT">
     <security:intercept-url patterrn ="/viewsGMP2/accessDenied.jsf"></security:intercept-url>
     </sec:authorize>-->
     
     
     <security:intercept-url pattern="/viewsGMP2/Ajout-groupe1.jsf" access="ROLE_PARTICIAPANT" />
      <security:intercept-url pattern="/viewsGMP2/Test1.jsf" access="ROLE_PARTICIAPANT" />
      <!--<security:intercept-url pattern="/viewsGMP2/Test2.jsf" access="ROLE_PARTICIAPANT,ROLE_ADMIN"/>-->
      <!--<security:access-denied-handler error-page="/viewsGMP2/Test2.jsf"/>-->
      <!--<security:intercept-url pattern="/viewGMP2/Test2.jsf" access="hasRole('ROLE_ADMIN')"/>-->
     </security:http>
     
     
         <!--  injection du provider au gestionnaire  de securite de l'application -->
     
                     <!-- Authentification via base de données -->
             
    	 
    	
    		       
     
      <!-- authenticate the user with ldapAuthenticator using userSearch -->
     
       <!--<beans:bean id = "contextSource"
             class = "org.springframework.security.ldap.DefaultSpringSecurityContextSource">
       <beans:constructor-arg value="ldap://192.168.198.131:389/dc=xtensus,dc=com"/>
       <beans:property name="userDn" value="cn=admin,dc=xtensus,dc=com"/>
       <beans:property name="password" value="ikhlass"/>
     </beans:bean>-->
     
     <ldap-server id="contextSource" url="ldap://192.168.198.131:389"
     manager-dn="cn=admin,dc=xtensus,dc=com" manager-password="ikhlass"></ldap-server>
     
     <beans:bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
      <beans:constructor-arg index="0" value="ou=people"/>
      <beans:constructor-arg index="1" value="(uid={0})"/>
      <beans:constructor-arg index="2" ref="contextSource" />
      
    </beans:bean>
    
     <beans:bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
      <beans:constructor-arg>
      <beans:bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
      <beans:constructor-arg ref="contextSource"/>
      <beans:property name="userSearch" ref="userSearch"/>
      </beans:bean>
      </beans:constructor-arg>
       <beans:constructor-arg>
    <beans:bean id="userDetailsService" class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
      <beans:constructor-arg ref="contextSource"/>
      <beans:constructor-arg value="ou=Groups"/>
      <beans:property name="groupRoleAttribute" value="ou"/>
      </beans:bean>
      </beans:constructor-arg>
     
     </beans:bean>
      
     
    <security:authentication-manager alias="authentificationManager"> 
            <!-- reference provider LDAP -->   
         <security:ldap-authentication-provider 
             
               user-search-filter="(uid={0})"
               user-search-base="ou=people"
               group-search-filter="(uniqueMember={0})"
               group-search-base="ou=Groups"
               group-role-attribute="busniessCategory"
               role-prefix="ROLE_">
               </security:ldap-authentication-provider>
            <!-- reference provider BD JDBC-->
         <security:authentication-provider
      user-service-ref='myUserDetailsService' />
          <!-- <jdbc-user-service data-source-ref="dataSource" 
        users-by-username-query="SELECT utilisateursLogin as username, utilisateursMotDePasse ,enabled ,
    	utilisateursNom , utilisateursPrenom FROM utilisateurs WHERE utilisateursLogin = ?" 
        authorities-by-username-query="SELECT utilisateursLogin as username, role FROM roles WHERE utilisateursLogin = ?" />-->
        
       
       </security:authentication-manager> 
       
      <beans:bean id="myUserDetailsService"
      class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
      <beans:property name="dataSource" ref="dataSource" />
    
      <beans:property name="usersByUsernameQuery"
       value="SELECT utilisateursLogin as username, utilisateursMotDePasse ,enabled ,
    	utilisateursNom , utilisateursPrenom FROM utilisateurs WHERE utilisateursLogin = ?" ></beans:property>
      <beans:property name="authoritiesByUsernameQuery"
       value="SELECT utilisateursLogin as username, role FROM roles WHERE utilisateursLogin = ?" />
     </beans:bean>
      
     </beans:beans>
    je veux donner des privilèges d'accès à chaque utilisateur pour interdire et autoriser quelques menus pour qu'il puisse y accéder.
    j'ai pas trouvé de solution à ce problème.
    je suis preneur à vos propositions.
    Merci d'avance.

Discussions similaires

  1. Réponses: 3
    Dernier message: 29/09/2009, 17h27
  2. [debutant] probleme avec la configuration de LDAP
    Par pierrot10 dans le forum Administration système
    Réponses: 5
    Dernier message: 12/12/2008, 23h41
  3. [Datasource]Configuration avec SQL
    Par ennadi dans le forum JDBC
    Réponses: 15
    Dernier message: 06/06/2007, 10h52
  4. Configuration PostFix-LDAP
    Par xamxeladog dans le forum Réseau
    Réponses: 2
    Dernier message: 27/05/2005, 14h40
  5. Validation User/Mdp avec LDAP
    Par Katyucha dans le forum Réseau
    Réponses: 2
    Dernier message: 02/12/2004, 13h51

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