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

JSF Java Discussion :

jsf et authentification


Sujet :

JSF Java

  1. #1
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Sénégal

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

    Informations forums :
    Inscription : Avril 2013
    Messages : 21
    Points : 17
    Points
    17
    Par défaut jsf et authentification
    Bonjour,
    j'essaye de gerer l'authentification avec jsf. J'utilise glassfish et JPA. Lorsque l'application est lancé, ya l'interface de connexion et si les login et mot de passe saisis par l'utilisateur existent bien dans mla base, il est redirigé vers la page d'accueil. Là ya un problème avec mon code je ne sais pas lequel vu que je suis nouvelle en jsf. si vous pouvez me donner un coup de main ça serai bien. voici les codes respectifs de mon bean, de mon fichier faces-config.xml et de ma vue .

    loginBean.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
     
    package com.sirhbimao.beans;
     
    import com.sirhbimao.dao.AgentDao;
    import com.sirhbimao.entities.Agent;
    import javax.ejb.EJB;
    import javax.faces.application.FacesMessage;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.faces.context.FacesContext;
     
    @SessionScoped
    @ManagedBean
    public class LoginBean extends AbstractBaseBean{
    	private static final long serialVersionUID = -8639967661520563148L;
       private Agent agent;
     
           // Injection de notre EJB (Session Bean Stateless)
        @EJB
        private AgentDao    agentDao;
     
        // Initialisation de l'entité agent
        public LoginBean() {
            agent = new Agent();
        }
    //Mise en place d'un getter pour l'agent 
        public Agent getAgent() {
            return agent;
        }
     
        // Méthode d'action appelée lors du clic sur le bouton du formulaire
        // de connexion
        public String Logon() throws Exception{
           Agent ag;
            try{
                 ag= agentDao.trouver(agent.getLogin(),agent.getPassword());
                 if(ag!=null){
     
                 getSession().setAttribute(ACCESS_ALLOWED, true);
    			getSession().setAttribute("login", agent.getLogin());
                            FacesMessage message = new FacesMessage( "Connexion réussie!" );
            FacesContext.getCurrentInstance().addMessage( null, message );  
    			return SUCCESS;
     
    		}
     
            }catch(Exception e){
     
            }
    			return INPUT;     
        }
    }
    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
    31
    32
     
    <faces-config version="2.2"
                  xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
     
     
    	<navigation-rule>
    		<from-view-id>*</from-view-id>
    		<navigation-case>
    			<from-outcome>input</from-outcome>
    			<to-view-id>/index.xhtml</to-view-id>
    		</navigation-case>
     
    		<navigation-case>
    			<from-outcome>success</from-outcome>
    			<to-view-id>/admin_accueil.xhtml</to-view-id>
    		</navigation-case>
    	</navigation-rule>
        <navigation-rule>
    		<navigation-case>
    			<from-action>#{loginBean.logon}</from-action>
    			<from-outcome>success</from-outcome>
    			<to-view-id>/admin_accueil.xhtml</to-view-id>
    		</navigation-case>
    		<navigation-case>
    			<from-action>#{loginBean.logon}</from-action>
    			<from-outcome>input</from-outcome>
    			<to-view-id>/index.xhtml</to-view-id>
    		</navigation-case>
    	</navigation-rule>
    </faces-config>
    index.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
     
    <h:form id="formulaire">
                         <fieldset>
                <legend>Authentification</legend>
                <pre>
                <h:outputLabel for="login"> Login: <span class="requis"> *     </span></h:outputLabel>
                <h:inputText id="login"   value="#{agentBean.agent.login}"  size="20" maxlength="60" >
                      <f:ajax event="blur" render="loginMessage" />
              </h:inputText>
             <h:message id="loginMessage" for="login" errorClass="erreur" />
                <br />
     
                <h:outputLabel for="motdepasse"> Mot de passe <span class="requis">*</span></h:outputLabel>
                <h:inputSecret id="motdepasse" value="#{agentBean.agent.password}" size="20" maxlength="20" >
                    <f:ajax event="blur" render="motDePasseMessage" />
                </h:inputSecret>
                <h:message id="motDePasseMessage" for="motdepasse" errorClass="erreur" />
                <br />
     
     
                 <h:messages globalOnly="true" infoClass="info" />
     
                 <h:commandButton value="Connexion" action="#{loginBean.logon}" styleClass="sansLabel" >
     
                 </h:commandButton>
    	        <br />
                    </pre>
                         </fieldset>           
                </h:form>

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Et il se traduit comment ce "problème" ? Message d'erreur? Résultat inattendu? ....

  3. #3
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Sénégal

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

    Informations forums :
    Inscription : Avril 2013
    Messages : 21
    Points : 17
    Points
    17
    Par défaut
    là la 1ere que j'ai c'est celle là.
    Nom : error.png
Affichages : 226
Taille : 26,7 Ko

    Mais je precise que j'usqu'à hier le message d'erreur disait qu'il ne trouvai po de chemin de navigation vers le fichier indiqué /admin_accueil. Mais depuis ce matin c'est ce message qui s'affiche et j'ignire ce qui s'est passé entre temps. j'ai bien vérifié la fonction elle est en place.

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    donne nous la stacktrace de ton message d'erreur, et le scoped variables tant qu'on y est.

    Au passage, ta méthode devrait être logon() pas Logon(). Les majuscules ont de l'importance.

  5. #5
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Sénégal

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

    Informations forums :
    Inscription : Avril 2013
    Messages : 21
    Points : 17
    Points
    17
    Par défaut
    voici le statckTrace
    javax.faces.el.MethodNotFoundException: javax.el.MethodNotFoundException: /index.xhtml @49,99 action="#{logBean.logon}": Method not found: com.sirhbimao.beans.LogBean@18b44b5.logon()
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.el.MethodNotFoundException: /index.xhtml @49,99 action="#{logBean.logon}": Method not found: com.sirhbimao.beans.LogBean@18b44b5.logon()
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    ... 36 more


    scopedVariables

    Nom : scopedVar.png
Affichages : 220
Taille : 39,4 Ko

  6. #6
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Sénégal

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

    Informations forums :
    Inscription : Avril 2013
    Messages : 21
    Points : 17
    Points
    17
    Par défaut
    Merci c résolu. C'etait un problème de majuscule. Grand merci sans vous je n'aurai pas prêté attention à ça.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Authentification JSF + Realm tomcat
    Par LukasP. dans le forum JSF
    Réponses: 5
    Dernier message: 27/03/2009, 09h51
  2. richfaces jsf authentification
    Par Jacobian dans le forum JSF
    Réponses: 3
    Dernier message: 28/01/2009, 12h48
  3. authentification (jsf acegi facelets)
    Par j.devinfo dans le forum JSF
    Réponses: 4
    Dernier message: 28/08/2008, 22h48
  4. Réponses: 3
    Dernier message: 18/02/2008, 12h23

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