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 :

Spring Security avec Dynamic Web Project


Sujet :

Spring Java

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2014
    Messages : 16
    Points : 1
    Points
    1
    Par défaut Spring Security avec Dynamic Web Project
    bonjour,
    est t'il possible d'integrer spring security dans un projet java (n'est pas maven project ),
    j'utilise spring, hibernate et jsf,
    en fait l'authentification dans mon projet doit etre donnée selon le role de chaque utilisateur . (authentif+accés selon role)
    tous les documents que j'ai trouvé sont fait avec maven
    Toute aide est appréciée.
    Merci

  2. #2
    Membre chevronné 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
    Points : 2 120
    Points
    2 120
    Par défaut
    Salut,
    si ce que tu veux se fait avec maven, alors tu peux le faire sans maven, et les fichiers de dependaces tu les ajoutes manuellement
    dans ta classpath.

    Eric

  3. #3
    Membre régulier
    Homme Profil pro
    Inscrit en
    Novembre 2009
    Messages
    80
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 80
    Points : 74
    Points
    74
    Par défaut
    Bonjour.
    Oui, bien sur que tu peux le faire.
    Seulement, la syntaxe du fichier de configuration de Spring Security pour récupérer les rôles depuis la BDD est différente à celle utilisée pour les récupérer depuis LDap.
    Je te conseille vivement d'aller sur le site de Spring Security pour voir les syntaxes.

    Cdlt.

  4. #4
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2014
    Messages : 16
    Points : 1
    Points
    1
    Par défaut
    Salut,
    apres plusieurs recherche j'ai trouvé un lien qui m'a aidé pour se mettre sur la bonne route mais il ya quelques erreur que j'arrive pas a les corriger surtout que c'est mon premier projet avec spring security
    en fait je travaille avec spring3+ hibernate4+JSF2(primefaces)
    j'espere que vous pouvez me corriger et j'apprécie votre effort

    voici l'erreur que j'aiobtenu que je run page login.xhtml

    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
    GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/application-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Role, for columns: [org.hibernate.mapping.Column(userRoles)]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Role, for columns: [org.hibernate.mapping.Column(userRoles)]
    	at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314)
    	at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292)
    	at org.hibernate.mapping.Property.isValid(Property.java:239)
    	at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:469)
    	at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
    	at org.hibernate.cfg.Configuration.validate(Configuration.java:1283)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1734)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1780)
    	at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
    	at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
    	at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
    	... 19 more
     
    sept. 09, 2014 11:20:18 AM com.sun.faces.config.ConfigureListener contextInitialized
    INFOS: Initialisation de Mojarra 2.1.7 (SNAPSHOT 20120206) pour le contexte «/Gestion_formation»
    sept. 09, 2014 11:20:19 AM com.sun.faces.spi.InjectionProviderFactory createInstance
    INFOS: JSF1048 : Présence d’annotations PostConstruct/PreDestroy  Les méthodes de beans gérés marquées avec ces annotations auront des annotations dites traitées.
    sept. 09, 2014 11:20:20 AM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
    INFOS: Running on PrimeFaces 3.4.2
    sept. 09, 2014 11:20:20 AM org.primefaces.extensions.application.PostConstructApplicationEventListener processEvent
    INFOS: Running on PrimeFaces Extensions 0.7.1
    sept. 09, 2014 11:20:20 AM org.apache.catalina.core.StandardContext startInternal
    GRAVE: Error listenerStart
    sept. 09, 2014 11:20:20 AM org.apache.catalina.core.StandardContext startInternal
    GRAVE: Erreur de démarrage du contexte [/Gestion_formation] suite aux erreurs précédentes
    sept. 09, 2014 11:20:20 AM org.apache.catalina.core.ApplicationContext log
    INFOS: Closing Spring root WebApplicationContext
    sept. 09, 2014 11:20:20 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    GRAVE: The web application [/Gestion_formation] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    sept. 09, 2014 11:20:20 AM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["http-bio-8080"]
    sept. 09, 2014 11:20:20 AM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["ajp-bio-8009"]
    sept. 09, 2014 11:20:20 AM org.apache.catalina.startup.Catalina start
    INFOS: Server startup in 6547 ms

    application-context.xml

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
     
       <!-- Data Source Declaration -->
    <bean id="dataSource"	class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    	<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    	<property name="url" value="jdbc:mysql://localhost/pfess" />
    	<property name="username" value="root" />
    	<property name="password" value="" />
    </bean>
     
     
     
        <!-- Session Factory Declaration -->  
    <bean id="sessionFactory"  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
     
      		<property name="annotatedClasses">
      		<list>
     
                <value>rnu.isamm.pfe.model.Absence</value>
                <value>rnu.isamm.pfe.model.Affectation</value>
                <value>rnu.isamm.pfe.model.Administrateur</value>
                <value>rnu.isamm.pfe.model.Classe</value>
                <value>rnu.isamm.pfe.model.Enseignant</value>
    			<value>rnu.isamm.pfe.model.Formation</value>
        	  	<value>rnu.isamm.pfe.model.Matiere</value>
        	  	<value>rnu.isamm.pfe.model.Semestre</value>
        	  	<value>rnu.isamm.pfe.model.UniteEnseignement</value>
        	  	<value>rnu.isamm.pfe.model.Utilisateur</value>
        	  	<value>rnu.isamm.pfe.model.Salle</value>
        	  	<value>rnu.isamm.pfe.model.Horaire</value>
        	  	<value>rnu.isamm.pfe.model.Planning</value>
        	  	<value>rnu.isamm.pfe.model.Universite</value>
        	  	<value>rnu.isamm.pfe.model.Role</value>
      		</list>
    	</property>
     
    	<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    	  <property name="hibernateProperties">
                     <value>
                    		hibernate.connection.driver_class=org.gjt.mm.mysql.Driver
    						hibernate.dialect=org.hibernate.dialect.MySQLDialect
    						hibernate.connection.username=root
    						hibernate.connection.url=jdbc:mysql://localhost:3306/pfess
    						hibernate.hbm2ddl.auto=update
    						hibernate.connection.password=
    						hibernate.c3p0.min_size=2
    						hibernate.c3p0.max_size=10
    						hibernate.c3p0.timeout=300
    						hibernate.c3p0.max_statements=0
    						hibernate.c3p0.idle_test_period=1800
    						hibernate.c3p0.acquire_increment=2
                     </value>
                </property>
    </bean>
     
        <!-- Transaction Manager is defined -->
     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
           <property name="sessionFactory" ref="sessionFactory"/>
     </bean>
        <!-- Enable the configuration of transactional behavior based on annotations -->
       	 <tx:annotation-driven transaction-manager="transactionManager"/>
     
         <!-- Package needed to be scanned for annotation -->
          <context:component-scan base-package="rnu.isamm"/>
     
         <!-- Use annotation for configuration-->
            <context:annotation-config/>
            <context:spring-configured/>
     
     
     
     
    </beans>
    security-context.xml

    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
    <?xml version="1.0" encoding="UTF-8"?>
        <beans:beans
            xmlns:sec="http://www.springframework.org/schema/security"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:beans="http://www.springframework.org/schema/beans"
            xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring-security-3.1.xsd">
     
            <!-- Enable method level Spring Security by annotations  -->
            <sec:global-method-security pre-post-annotations="enabled" />  
            <sec:http auto-config="true" use-expressions="true">
     
                <!-- Page level Spring Security : Intercept access to resources in /pages/secure/** -->
                <sec:intercept-url pattern="/WebContent/**" access="hasRole('ROLE_DES')" />
     
                <!-- Page level Spring Security : Permit access to resources in /pages/unsecure/** -->
                <sec:intercept-url pattern="/pages/unsecure/**" access="permitAll"/>
     
                <!-- Page level Spring Security : Intercept access to resources in /** -->
                <sec:intercept-url pattern="/**" access="hasRole('ROLE_DES')"/>
     
                <!-- Page level Spring Security : Enable Primefaces -->
                <sec:intercept-url pattern="/javax.faces.resource/**" access="permitAll"/>
          
                <!-- Define login page for Spring Security -->      
                <sec:form-login login-page="/pages/unsecure/login.xhtml"/>
     
                <!-- Define logout properties for Spring Security -->
                <sec:logout invalidate-session="true" delete-cookies="true" logout-success-url="/"></sec:logout>
            </sec:http>
           
            <!-- Set customUserDetailsService class as the authentication Manager for Spring Security-->
            <sec:authentication-manager alias="authenticationManager">
                <sec:authentication-provider user-service-ref="customUserDetailsService">
                    <sec:password-encoder hash="plaintext"></sec:password-encoder>
                </sec:authentication-provider>
            </sec:authentication-manager>
     
             <!-- Inject authentication Manager to our LoginBean -->
            <beans:bean id="loginBean" name="loginBean" class="net.javabeat.managedController.LoginBean" scope="prototype">
                <beans:property name="authenticationManager" ref="authenticationManager"></beans:property>
            </beans:bean>
        </beans:beans>

    faces-config.xml

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config 
    	xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
                  version="2.0">
     
        <application>
        	<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
        </application>
     
     
          <!-- navigation-rule for login.xhtml -->
            <navigation-rule>
                <from-view-id>/pages/unsecure/login.xhtml</from-view-id>
                <!-- navigation-case for method login() -->
                <navigation-case>
                    <from-outcome>correct</from-outcome>
                    <to-view-id>/layout_admin.xhtml</to-view-id>
                </navigation-case>
                <!-- navigation-case for method login() -->
                <navigation-case>
                    <from-outcome>incorrect</from-outcome>
                    <to-view-id>/pages/unsecure/login.xhtml</to-view-id>
                </navigation-case>
            </navigation-rule>
     
     
    </faces-config>
    web.xml


    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
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     id="WebApp_ID" version="2.5">
      <display-name>jsf2Hibernate3Tomahowk</display-name>
     
     
     
    <welcome-file-list>
    <welcome-file>login.jsf</welcome-file>
    </welcome-file-list>
     
     <!-- Fichiers XML de configuration, servlet	-->
     <servlet>
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
     </servlet>
     
     <!-- config servlet mapping -->
     <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
     </servlet-mapping>
      <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.xhtml</url-pattern>
     </servlet-mapping>
     
    	<!-- le context du theme de l'application -->
    	<context-param>  
        <param-name>primefaces.THEME</param-name>  
        <param-value>start</param-value>  
    	</context-param> 
     
    	<!-- the spring configuration file -->
            <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                     /WEB-INF/application-context.xml
                    /WEB-INF/security-context.xml
                </param-value>
            </context-param>
     
    	<!-- add the listener classes -->
     		<listener>
      		<listener-class> org.springframework.web.context.ContextLoaderListener</listener-class>
       		</listener>
       		<listener>
     		<listener-class> org.springframework.web.context.request.RequestContextListener</listener-class>
       		</listener>
     
      		 <listener>
    		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    		</listener>
     
     
     
      <!-- ============== Filters ajax============= -->
     
     
     <!-- detecter le timeZone de systeme -->
    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>
     
     
     
      <!-- Spring Security -->
            <filter>
                <filter-name>springSecurityFilterChain</filter-name>
                <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
            </filter>
            <filter-mapping>
                <filter-name>springSecurityFilterChain</filter-name>
                <url-pattern>/*</url-pattern>
            </filter-mapping>
     
     
     
     
    </web-app>
    merci

  5. #5
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2014
    Messages : 16
    Points : 1
    Points
    1
    Par défaut
    voila la structure de mon projet
    Nom : navig.png
Affichages : 808
Taille : 21,9 Ko

  6. #6
    Membre chevronné 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
    Points : 2 120
    Points
    2 120
    Par défaut
    voici ce que l´erreur dit:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Could not determine type for: java.util.Set, at table: Role, for columns: [org.hibernate.mapping.Column(userRoles)]
    peux-tu nous montrer l´entite Role ?

    Eric

  7. #7
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2014
    Messages : 16
    Points : 1
    Points
    1
    Par défaut
    salut Eric,

    voila la classe Role.java

    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
    package rnu.isamm.pfe.model;
     
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
     
    import org.hibernate.annotations.Proxy;
     
    @Entity
    @Proxy(lazy=false)
    @Table(name="Role")
    public class Role {
     
    	private int idRole;
    	private String nomRole;
     
     
     
    	@Id
    	@GeneratedValue(strategy=GenerationType.IDENTITY)  
    	public int getIdRole() {
    		return idRole;
    	}
    	public void setIdRole(int idRole) {
    		this.idRole = idRole;
    	}
    	public String getNomRole() {
    		return nomRole;
    	}
    	public void setNomRole(String nomRole) {
    		this.nomRole = nomRole;
    	}
     
    	public Role() {
    		super();
    		// TODO Auto-generated constructor stub
    	}
     
     
     
     
    	public Role(int idRole, String nomRole, Set<Utilisateur> userRoles) {
    		super();
    		this.idRole = idRole;
    		this.nomRole = nomRole;
    		this.userRoles=userRoles;
    	}
     
    	@OneToMany(cascade=CascadeType.ALL)
        @JoinTable(name="USER_ROLES",
            joinColumns = {@JoinColumn(name="role_id", referencedColumnName="idRole")},
            inverseJoinColumns = {@JoinColumn(name="user_id", referencedColumnName="idUser")}
        )
        private Set<Utilisateur> userRoles=new HashSet<Utilisateur>() ;
     
     
     
    	public Set<Utilisateur> getUserRoles() {
    		return userRoles;
    	}
    	public void setUserRoles(Set<Utilisateur> userRoles) {
    		this.userRoles = userRoles;
    	}
     
     
     
    	/*Set<Utilisateur> users=new HashSet<Utilisateur>();
    	@OneToMany(mappedBy="role", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    	public Set<Utilisateur> getUsers() {
    		return users;
    	}
    	public void setUsers(Set<Utilisateur> users) {
    		this.users = users;
    	}*/
     
     
     
     
     
    }
    la classe Utilisateur.java

    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
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    package rnu.isamm.pfe.model;
     
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
     
    import javax.faces.application.FacesMessage;
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.validator.ValidatorException;
    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
     
    import org.hibernate.annotations.Proxy;
     
    @Entity
    @Proxy(lazy=false)
    @Table(name="Utilisateur")
    public class Utilisateur {
     
    	private int idUser;
    	private String nom;
    	private String prenom;
    	private String mail;
    	private String poste;
    	private String cin;
    	private String login;
    	private String pwd; 
    	//private int idRole;
     
     
    	private Administrateur administrateur ;
     
    	  @OneToOne(cascade=CascadeType.ALL)
    	   @JoinTable(name="USER_ROLES",
    	        joinColumns = {@JoinColumn(name="user_id", referencedColumnName="idUser")},
    	        inverseJoinColumns = {@JoinColumn(name="role_id", referencedColumnName="idRole")}
    	    )
    	private Role role;
     
     
    	@Id
    	@GeneratedValue(strategy=GenerationType.IDENTITY)  
    	public int getIdUser() {
    		return idUser;
    	}
    	public void setIdUser(int idUser) {
    		this.idUser = idUser;
    	}
    	public String getNom() {
    		return nom;
    	}
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
    	public String getPrenom() {
    		return prenom;
    	}
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
    	public String getMail() {
    		return mail;
    	}
    	public void setMail(String mail) {
    		this.mail = mail;
    	}
    	public String getPoste() {
    		return poste;
    	}
    	public void setPoste(String poste) {
    		this.poste = poste;
    	}
    	public String getCin() {
    		return cin;
    	}
    	public void setCin(String cin) {
    		this.cin = cin;
    	}
     
     
    /*public int getIdRole() {
     
    		return idRole;
    	}
    	public void setIdRole(int idRole) {
    		this.idRole = idRole;
    	}*/
     
     
    	public String getLogin() {
    		return login;
    	}
    	public void setLogin(String login) {
    		this.login = login;
    	}
    	public String getPwd() {
    		return pwd;
    	}
    	public void setPwd(String pwd) {
    		this.pwd = pwd;
    	}
     
     
    	Set<Affectation> ls_affectation=new HashSet<Affectation>();
     
     
    	@OneToMany(mappedBy="user" , cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    	public Set<Affectation> getLs_affectation() {
    		return ls_affectation;
    	}
    	public void setLs_affectation(Set<Affectation> ls_affectation) {
    		this.ls_affectation = ls_affectation;
    	}
     
     
    	Set<Formation> formations=new HashSet<Formation>();
     
    	@OneToMany(mappedBy="user", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    	public Set<Formation> getFormations() {
    		return formations;
    	}
    	public void setFormations(Set<Formation> formations) {
    		this.formations = formations;
    	}
     
    	@ManyToOne(targetEntity=rnu.isamm.pfe.model.Administrateur.class)
    	@JoinColumn(name="idAdminstrateur", nullable=true)
    	public Administrateur getAdministrateur() {
    		return administrateur;
    	}
    	public void setAdministrateur(Administrateur administrateur) {
    		this.administrateur = administrateur;
    	}
     
     
     
    	public Role getRole() {
    		return role;
    	}
    	public void setRole(Role role) {
    		this.role = role;
    	}
     
     
     
    	public void validateEmail(FacesContext arg0, UIComponent arg1, Object arg2) throws ValidatorException {
    		String email=(String)arg2;
    		Pattern p=Pattern.compile("[a-z]+[.,-_]*[a-z]*@[a-z]+.[a-z]+");;
    		Matcher m=p.matcher(email);
    		boolean verif=m.matches();
     
    		if(!verif){
    			//on utilise lorsque on traveille avec une seule languge 
    			throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,"Email invalid", "mail doit etre sous la forme xxx@xx.xx"));
     
     
    		}
     
    	}
     
     
     
     
     
    }

  8. #8
    Membre chevronné 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
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    tu ne peux pas avoir dans la classe
    Role.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    @OneToMany(cascade=CascadeType.ALL)
        @JoinTable(name="USER_ROLES",
            joinColumns = {@JoinColumn(name="role_id", referencedColumnName="idRole")},
            inverseJoinColumns = {@JoinColumn(name="user_id", referencedColumnName="idUser")}
        )
        private Set<Utilisateur> userRoles=new HashSet<Utilisateur>() ;
    et dans la classe
    Utilisateur.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    @OneToOne(cascade=CascadeType.ALL)
    	   @JoinTable(name="USER_ROLES",
    	        joinColumns = {@JoinColumn(name="user_id", referencedColumnName="idUser")},
    	        inverseJoinColumns = {@JoinColumn(name="role_id", referencedColumnName="idRole")}
    	    )
    	private Role role;
    Eric

  9. #9
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2014
    Messages : 16
    Points : 1
    Points
    1
    Par défaut
    salut,

    j'ai modifie les annotations des tables et le mapping c'est fait mais j'ai d'autre problemes qui apparaissent,
    voila l'erreur
    meme si je met en commentaire la administrateurServiceImpl alors alle passe a la classe au dessous je sais pas pourquoi
    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
    sept. 10, 2014 1:52:55 PM org.apache.catalina.core.AprLifecycleListener init
    INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\sts-3.4.0.RELEASE;;.
    sept. 10, 2014 1:52:55 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
    AVERTISSEMENT: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Gestion_administratif v 14_08' did not find a matching property.
    sept. 10, 2014 1:52:55 PM org.apache.coyote.AbstractProtocol init
    INFOS: Initializing ProtocolHandler ["http-bio-8080"]
    sept. 10, 2014 1:52:55 PM org.apache.coyote.AbstractProtocol init
    INFOS: Initializing ProtocolHandler ["ajp-bio-8009"]
    sept. 10, 2014 1:52:55 PM org.apache.catalina.startup.Catalina load
    INFOS: Initialization processed in 582 ms
    sept. 10, 2014 1:52:55 PM org.apache.catalina.core.StandardService startInternal
    INFOS: Démarrage du service Catalina
    sept. 10, 2014 1:52:55 PM org.apache.catalina.core.StandardEngine startInternal
    INFOS: Starting Servlet Engine: Apache Tomcat/7.0.21
    sept. 10, 2014 1:52:56 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
    INFOS: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [950] milliseconds.
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://www.springframework.org/security/tags is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.startup.TaglibUriRule body
    INFOS: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
    sept. 10, 2014 1:52:57 PM org.apache.catalina.core.ApplicationContext log
    INFOS: Initializing Spring root WebApplicationContext
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    sept. 10, 2014 1:52:59 PM org.apache.catalina.core.StandardContext listenerStart
    GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'administrateurService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory rnu.isamm.pfe.ImplService.AdministrateurServiceImpl.sessionFactory; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [rnu.isamm.pfe.managedBean.loginBean] for bean with name 'loginBean' defined in ServletContext resource [/WEB-INF/security-context.xml]; nested exception is java.lang.ClassNotFoundException: rnu.isamm.pfe.managedBean.loginBean
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory rnu.isamm.pfe.ImplService.AdministrateurServiceImpl.sessionFactory; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [rnu.isamm.pfe.managedBean.loginBean] for bean with name 'loginBean' defined in ServletContext resource [/WEB-INF/security-context.xml]; nested exception is java.lang.ClassNotFoundException: rnu.isamm.pfe.managedBean.loginBean
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    	... 20 more
    Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [rnu.isamm.pfe.managedBean.loginBean] for bean with name 'loginBean' defined in ServletContext resource [/WEB-INF/security-context.xml]; nested exception is java.lang.ClassNotFoundException: rnu.isamm.pfe.managedBean.loginBean
    	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1269)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:578)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1338)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:356)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:335)
    	at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:895)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
    	... 22 more
    Caused by: java.lang.ClassNotFoundException: rnu.isamm.pfe.managedBean.loginBean
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    	at org.springframework.util.ClassUtils.forName(ClassUtils.java:260)
    	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1290)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1261)
    	... 31 more
     
    sept. 10, 2014 1:52:59 PM com.sun.faces.config.ConfigureListener contextInitialized
    INFOS: Initialisation de Mojarra 2.1.7 (SNAPSHOT 20120206) pour le contexte «/Gestion_formation»
    sept. 10, 2014 1:53:00 PM com.sun.faces.spi.InjectionProviderFactory createInstance
    INFOS: JSF1048 : Présence d’annotations PostConstruct/PreDestroy  Les méthodes de beans gérés marquées avec ces annotations auront des annotations dites traitées.
    sept. 10, 2014 1:53:01 PM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
    INFOS: Running on PrimeFaces 3.4.2
    sept. 10, 2014 1:53:01 PM org.primefaces.extensions.application.PostConstructApplicationEventListener processEvent
    INFOS: Running on PrimeFaces Extensions 0.7.1
    sept. 10, 2014 1:53:01 PM org.apache.catalina.core.StandardContext startInternal
    GRAVE: Error listenerStart
    sept. 10, 2014 1:53:01 PM org.apache.catalina.core.StandardContext startInternal
    GRAVE: Erreur de démarrage du contexte [/Gestion_formation] suite aux erreurs précédentes
    sept. 10, 2014 1:53:01 PM org.apache.catalina.core.ApplicationContext log
    INFOS: Closing Spring root WebApplicationContext
    sept. 10, 2014 1:53:01 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    GRAVE: The web application [/Gestion_formation] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    sept. 10, 2014 1:53:01 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    GRAVE: The web application [/Gestion_formation] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.
    sept. 10, 2014 1:53:01 PM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["http-bio-8080"]
    sept. 10, 2014 1:53:01 PM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["ajp-bio-8009"]
    sept. 10, 2014 1:53:01 PM org.apache.catalina.startup.Catalina start
    INFOS: Server startup in 5975 ms
    /**
    voici la page loginBean
    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
    package rnu.isamm.pfe.managedBean;
     
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import javax.faces.bean.SessionScoped;
    import javax.faces.bean.ManagedBean;
     
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Scope;
    import org.springframework.security.Authentication;
    import org.springframework.security.AuthenticationException;
    import org.springframework.security.AuthenticationManager;
    import org.springframework.security.context.SecurityContextHolder;
    import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
    import org.springframework.stereotype.Component;
     
     
     
     
    import rnu.isamm.pfe.model.Administrateur;
    import rnu.isamm.pfe.model.Enseignant;
    import rnu.isamm.pfe.model.Role;
    import rnu.isamm.pfe.model.Utilisateur;
    import rnu.isamm.pfe.service.AdministrateurService;
    import rnu.isamm.pfe.service.EnseignantService;
    import rnu.isamm.pfe.service.RoleService;
    import rnu.isamm.pfe.service.UtilisateurService;
     
    @Component("loginBean")
    @Scope
    @ManagedBean(name="loginBean")
    public class LoginBean {
     
     
    	@Autowired()
    	private transient AdministrateurService administrateurService;
     
    	@Autowired()
    	private transient UtilisateurService userService;
    	private Utilisateur user;
     
     
    	@Autowired()
    	private transient EnseignantService enseignantService;
     
    	@Autowired()
    	private UserBean userBean;
     
     
     
    	private String userName = null; 
        private String password = null;
     
        @ManagedProperty(value="#{authenticationManager}")
        private AuthenticationManager authenticationManager = null;
     
        public String login() {
            try {
                Authentication request = new UsernamePasswordAuthenticationToken(this.getUserName(), this.getPassword());
                Authentication result = authenticationManager.authenticate(request);
                SecurityContextHolder.getContext().setAuthentication(result);
            } catch (AuthenticationException e) {
                e.printStackTrace();
                return "incorrect";
            }
            return "correct";
        }
     
        public String cancel() {
            return null;
        }
     
        public String logout(){
            SecurityContextHolder.clearContext();
            return "loggedout";
        }
     
        public AuthenticationManager getAuthenticationManager() {
            return authenticationManager;
        }
     
        public void setAuthenticationManager(AuthenticationManager authenticationManager) {
            this.authenticationManager = authenticationManager;
        }
     
        public String getUserName() {
            return userName;
        }
     
        public void setUserName(String userName) {
            this.userName = userName;
        }
     
        public String getPassword() {
            return password;
        }
     
        public void setPassword(String password) {
            this.password = password;
        }
     
    }
    et la page security-context modifié

    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
    <?xml version="1.0" encoding="UTF-8"?>
        <beans:beans
            xmlns:sec="http://www.springframework.org/schema/security"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:beans="http://www.springframework.org/schema/beans"
            xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring-security-3.1.xsd">
     
            <!-- Enable method level Spring Security by annotations  -->
            <sec:global-method-security pre-post-annotations="enabled" />  
            <sec:http auto-config="true" use-expressions="true">
     
                <!-- Page level Spring Security : Intercept access to resources in /pages/secure/** -->
                <sec:intercept-url pattern="/WebContent/**" access="hasRole('ROLE_ADMIN')" />
     
                <!-- Page level Spring Security : Permit access to resources in /pages/unsecure/** -->
                <sec:intercept-url pattern="/WebContent/**" access="permitAll"/>
     
                <!-- Page level Spring Security : Intercept access to resources in /** -->
                <sec:intercept-url pattern="/**" access="hasRole('ROLE_DES')"/>
     
                <!-- Page level Spring Security : Enable Primefaces -->
                <sec:intercept-url pattern="/javax.faces.resource/**" access="permitAll"/>
          
                <!-- Define login page for Spring Security -->      
                <sec:form-login login-page="/pages/unsecure/login.xhtml"/>
     
                <!-- Define logout properties for Spring Security -->
                <sec:logout invalidate-session="true" delete-cookies="true" logout-success-url="/"></sec:logout>
            </sec:http>
           
            <!-- Set customUserDetailsService class as the authentication Manager for Spring Security-->
            <sec:authentication-manager alias="authenticationManager">
                <sec:authentication-provider user-service-ref="customUserDetailsService">
                    <sec:password-encoder hash="plaintext"></sec:password-encoder>
                </sec:authentication-provider>
            </sec:authentication-manager>
     
             <!-- Inject authentication Manager to our LoginBean -->
            <beans:bean id="loginBean" name="loginBean" class="rnu.isamm.pfe.managedBean.loginBean" scope="prototype">
                <beans:property name="authenticationManager" ref="authenticationManager"></beans:property>
            </beans:bean>
        </beans:beans>
    et la page application-context

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
     
       <!-- Data Source Declaration -->
    <bean id="dataSource"	class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    	<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    	<property name="url" value="jdbc:mysql://localhost/pfess" />
    	<property name="username" value="root" />
    	<property name="password" value="" />
    </bean>
     
     
     
        <!-- Session Factory Declaration -->  
    <bean id="sessionFactory"  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
     
     
     
    	<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    	  <property name="hibernateProperties">
                     <value>
                    		hibernate.connection.driver_class=org.gjt.mm.mysql.Driver
    						hibernate.dialect=org.hibernate.dialect.MySQLDialect
    						hibernate.connection.username=root
    						hibernate.connection.url=jdbc:mysql://localhost:3306/pfess
    						hibernate.hbm2ddl.auto=update
    						hibernate.connection.password=
    						hibernate.c3p0.min_size=2
    						hibernate.c3p0.max_size=10
    						hibernate.c3p0.timeout=300
    						hibernate.c3p0.max_statements=0
    						hibernate.c3p0.idle_test_period=1800
    						hibernate.c3p0.acquire_increment=2
                     </value>
                </property>
    </bean>
     
        <!-- Transaction Manager is defined -->
     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
           <property name="sessionFactory" ref="sessionFactory"/>
     </bean>
        <!-- Enable the configuration of transactional behavior based on annotations -->
       	 <tx:annotation-driven transaction-manager="transactionManager"/>
     
         <!-- Package needed to be scanned for annotation -->
          <context:component-scan base-package="rnu.isamm"/>
     
         <!-- Use annotation for configuration-->
            <context:annotation-config/>
            <context:spring-configured/>
     
     
     
     
    </beans>
    maintennat je veux poster les classe Role et utilisateur des entites modifie

    Role.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     private Set<Utilisateur> userRoles=new HashSet<Utilisateur>() ;
     
     
    	  @OneToMany(mappedBy="role", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    	  	public Set<Utilisateur> getUserRoles() {
    		return userRoles;
    	}
    	public void setUserRoles(Set<Utilisateur> userRoles) {
    		this.userRoles = userRoles;
    	}
    Utilisateur.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    @ManyToOne(targetEntity=rnu.isamm.pfe.model.Role.class)
    	@JoinColumn(name="idRole", nullable=true)
    	public Role getRole() {
    		return role;
    	}
    	public void setRole(Role role) {
    		this.role = role;
    	}
    merci je souhaite vraiment votre aide c'est vraiment urgent !!

  10. #10
    Candidat au Club
    Homme Profil pro
    Architecte technique
    Inscrit en
    Mars 2013
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Architecte technique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2013
    Messages : 3
    Points : 4
    Points
    4
    Par défaut keylesson.com
    Bonjour,

    Ton application-context n'est pas bon, tu utilise deux datasource tu doit plutôt faire un truc du genre :
    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
    	<beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    		http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/context
     		http://www.springframework.org/schema/context/spring-context.xsd
    		http://www.springframework.org/schema/tx
    		http://www.springframework.org/schema/tx/spring-tx.xsd">
     
     
    	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    		destroy-method="close" p:driverClass="com.mysql.jdbc.Driver"
    		p:acquireIncrement="2" p:minPoolSize="2"
    		p:maxPoolSize="10" p:jdbcUrl="jdbc:mysql://localhost/pfess"
    		p:user="root" p:password="">
    	</bean>
     
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="configLocation">
    			<value>classpath:hibernate.cfg.xml</value>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    				<prop key="hibernate.show_sql">true</prop>
    			</props>
    		</property>
    	</bean>
     
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
     
    	    <!-- Enable the configuration of transactional behavior based on annotations -->
       	 <tx:annotation-driven transaction-manager="transactionManager"/>
     
         <!-- Package needed to be scanned for annotation -->
          <context:component-scan base-package="rnu.isamm"/>
     
         <!-- Use annotation for configuration-->
            <context:annotation-config/>
            <context:spring-configured/>
     
     
    	</beans>
    Sinon pour ton managedBean, l'utilisation de l'injection de dépendances avec JSF n'est pas évidente. je te conseille d'utiliser JSR-330
    Ainsi, au lieu de @Component tu utilise @Named et au lieu de @Autowired tu utilise @Inject

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    @ManagedBean
    @Named
    @Scope("request")
    public class LoginBean {
     
    	@Inject
    	private transient AdministrateurService administrateurService;
    .....
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    @Named
    public class AdministrateurService {
    ....
    Pour l'utilisation de @ManagedProperty; à ma connaissance on l'utilise pour injecter un managedBean dans un autre managedBean
    donc tu a qu'à faire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    @Inject
    private AuthenticationManager authenticationManager;
    Et pas besoin de ça dans le security-context
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <beans:bean id="loginBean" name="loginBean" class="rnu.isamm.pfe.managedBean.loginBean" scope="prototype">
                <beans:property name="authenticationManager" ref="authenticationManager"></beans:property>
            </beans:bean>

Discussions similaires

  1. Dynamic Web Project - checkout de SVN et projet non reconnu
    Par nicolas_isi dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 26/06/2009, 12h09
  2. Réponses: 9
    Dernier message: 28/05/2009, 23h29
  3. Executé un Dynamic Web project
    Par subzero82 dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 23/06/2006, 22h22
  4. [WTP] Dynamic web project Eclipse 3.1 Apache5.5
    Par mschoum dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 22/02/2006, 19h52
  5. [j2ee] Eclipse + Dynamic Web Project
    Par Jorus dans le forum Eclipse Java
    Réponses: 9
    Dernier message: 10/10/2005, 11h06

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