13 Replies Latest reply on Mar 11, 2013 11:57 AM by lucaster

    how to get user's password value after success authenticate?

    shenlanemo

      i want get user's password after authenticate.

       

      in my back class i insert this code.

      =================

      @Inject @SessionScoped Credentials credentials;

      ...

      ...

      ...

      System.out.println(((PasswordCredential) credentials.getCredential()).getValue());

       

      ================

       

      the code run to null pointer Exception.

       

      someone can tell me how to get user's password value after success authenticate?

       

      thanks very much!!

        • 1. Re: how to get user's password value after success authenticate?
          shenlanemo

          this is the Authenticator Class

           

          ==========================

          public class SimpleAuthenticator extends BaseAuthenticator implements Authenticator {

           

              @Inject EntityManager entityManager;

              @Inject Credentials credentials;

              @Override

              public void authenticate() {

                  if ("demo".equals(credentials.getUsername()) &&

                          credentials.getCredential() instanceof PasswordCredential &&

                          "demo".equals(((PasswordCredential) credentials.getCredential()).getValue())) {

                      setStatus(AuthenticationStatus.SUCCESS);

                      setUser(new SimpleUser("demo"));

                      System.out.println(AuthenticationStatus.SUCCESS);

                  } else {                   

                      setStatus(AuthenticationStatus.FAILURE);           

                      System.out.println(AuthenticationStatus.FAILURE);           

                  }

              }

          }

          ====================================

           

          i try to use jsf page to login:

          ==================

          <h:form id="loginForm" rendered="#{not identity.loggedIn}">

              <h:messages/>

              <span>demo demo</span>

              <div class="loginRow">

                  <h:outputLabel for="name" value="Username" styleClass="loginLabel"/>

                  <h:inputText id="name" value="#{credentials.username}"/>

              </div>

              <div class="loginRow">

                  <h:outputLabel for="password" value="Password" styleClass="loginLabel"/>

                  <h:inputSecret id="password" value="#{credentials.password}" redisplay="true"/>

              </div>

           

              <div class="loginRow">

           

              </div>

           

              <div class="buttons">

                  <h:commandButton id="login" value="LOGIN" action="#{identity.login}" styleClass="loginButton"/>

              </div>

          </h:form>

          ===========================

          if input "demo" "demo" and click LOGIN button,the console show SUCCESS.

           

           

          but i want to user username and password in annother Email Class.

           

          public class Email{

              @Inject Credentials credentials;

              @Inject Identity identity;

             

             

              public Email(){

                 

              }

             

              public void receiveMail() throws Exception {

                 

                 

                  System.out.println("i want get username and password here");

                  System.out.println(credentials.getUsername());

                  System.out.println(((PasswordCredential) credentials.getCredential()).getValue());

             

                   /* to connect to email server*/

              }

          }

           

           

          when i call the method below

          ===================

          <h:form>

                  <h3>email test</h3><br/>

                  <h:commandButton value="try" action="#{email.receiveMail}"/>

          </h:form>

          ==================

           

          the conole show Exception below:

          ------------

          14:12:45,043 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http-localhost-127.0.0.1-8080-4) #{email.receiveMail}: java.lang.NullPointerException: javax.faces.FacesException: #{email.receiveMail}: java.lang.NullPointerException

              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

              at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]

          Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException

              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:]

              ... 30 more

          Caused by: java.lang.NullPointerException

              at email.Email.receiveMail(Email.java:26) [classes:]

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_07]

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_07]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_07]

              at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_07]

              at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.13.Final.jar:]

              at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              ... 31 more

           

          14:12:45,061 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/website_step1].[Faces Servlet]] (http-localhost-127.0.0.1-8080-4) Servlet.service() for servlet Faces Servlet threw exception: javax.enterprise.event.ObserverException

              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_07]

              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_07]

              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_07]

              at java.lang.reflect.Constructor.newInstance(Constructor.java:525) [rt.jar:1.7.0_07]

              at java.lang.Class.newInstance0(Class.java:372) [rt.jar:1.7.0_07]

              at java.lang.Class.newInstance(Class.java:325) [rt.jar:1.7.0_07]

              at org.jboss.weld.util.reflection.SecureReflections$16.work(SecureReflections.java:343) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInstantiation(SecureReflectionAccess.java:173) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.util.reflection.SecureReflections.newInstance(SecureReflections.java:340) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:33) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:73) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:162) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:569) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:559) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:554) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:74) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

              at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]

          Caused by: javax.servlet.ServletException: java.lang.NullPointerException

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              ... 17 more

          Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException

              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              ... 23 more

          Caused by: java.lang.NullPointerException

              at email.Email.receiveMail(Email.java:26) [classes:]

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_07]

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_07]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_07]

              at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_07]

              at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.13.Final.jar:]

              at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

              ... 31 more

          -----------------------

          • 2. Re: how to get user's password value after success authenticate?
            nathandennis

            well you know what the problem is... the value isnt there in the bean. says so right there in the stack...

             

            try

             

            <h:commandButton id="login" action="#{identity.login}"   value="Login"

                                     type="submit"  /> 

             

            i doubt its getting there without using the submit option. There are some things that changed in JSF2 might want to take a look at the docs and maybe glance at a migration guide to get you up to speed.

            • 3. Re: how to get user's password value after success authenticate?
              shenlanemo

              thanks nathan dennis !!!!

               

              but  the code still run to exception...

               

              ============================

              System.out.println(credentials.getUsername());

              ============================

              the credentials.getUsername() can be output correctly.

               

               

               

              but the code below still run to Exception.

              ============================

              System.out.println(((PasswordCredential) credentials.getCredential()).getValue());

              ============================

               

              i want to get password from credentials.getCredential()

               

              thanks everyone very much!!!

              • 4. Re: how to get user's password value after success authenticate?
                shenlanemo

                may be credentials was auto set null  after seam-security authenticated???

                • 5. Re: how to get user's password value after success authenticate?
                  nathandennis

                  thats not it.. i just tested it... this works

                   

                  System.out.println( ((PasswordCredential) credentials.getCredential()).getValue());

                   

                  you arent getting the value to the bean.. check the jsf again. something is up with your xhtml

                  • 6. Re: how to get user's password value after success authenticate?
                    nathandennis

                    why are you using

                    redisplay="true"?

                    http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/h/inputSecret.html

                    Flag indicating that any existing value in this field should be rendered when the form is created. Because this is a potential security risk, password values are not displayed by default.

                     

                    i doubt this is what you want unless you are trying to do something with ajax... which according to your code you arent.

                    • 7. Re: how to get user's password value after success authenticate?
                      shenlanemo

                      thanks nathan dennis.

                       

                      i cut the redisplay attribute , and the error still exist.

                       

                      and i cut the project to a very simple example to show the error.

                       

                      1.Authenticator class

                      ============

                      package security;

                      import java.util.List;

                       

                      import javax.enterprise.context.ConversationScoped;

                      import javax.enterprise.context.SessionScoped;

                      import javax.inject.Inject;

                       

                      import javax.persistence.EntityManager;

                      import org.jboss.seam.security.Authenticator;

                      import org.jboss.seam.security.BaseAuthenticator;

                      import org.jboss.seam.security.Credentials;

                      import org.picketlink.idm.impl.api.PasswordCredential;

                      import org.picketlink.idm.impl.api.model.SimpleUser;

                       

                      public class SimpleAuthenticator extends BaseAuthenticator implements Authenticator {

                       

                          @Inject EntityManager entityManager;

                          @Inject Credentials credentials;

                          @Override

                          public void authenticate() {

                              if ("demo".equals(credentials.getUsername()) &&

                                      credentials.getCredential() instanceof PasswordCredential &&

                                      "demo".equals(((PasswordCredential) credentials.getCredential()).getValue())) {

                                  setStatus(AuthenticationStatus.SUCCESS);

                                  setUser(new SimpleUser("demo"));

                                  System.out.println(AuthenticationStatus.SUCCESS);

                              } else {                   

                                  setStatus(AuthenticationStatus.FAILURE);           

                                  System.out.println(AuthenticationStatus.FAILURE);           

                              }

                          }

                      }

                      =================

                       

                       

                      2.i defined a Email class to do some work with mailserver,here i just want to get the username and password before connect to mail server.

                      =================

                      package email;

                      import javax.inject.Inject;

                      import javax.inject.Named;

                      import org.jboss.seam.security.Credentials;

                      import org.jboss.seam.security.Identity;

                      import org.picketlink.idm.impl.api.PasswordCredential;

                      @Named("Email")

                      public class Email{

                          @Inject Credentials credentials;

                          @Inject Identity identity;

                          public Email(){

                       

                          }

                          public void receiveMail() throws Exception {

                              System.out.println("to get username and password here:");

                              System.out.println(credentials.getUsername());

                              System.out.println(((PasswordCredential) credentials.getCredential()).getValue());

                              /* to connect to mail server*/

                              /* to get user's mails*/

                          }

                      }

                      ========================

                       

                      3.i use a jsf page to do user login and show user name and password.

                       

                      ======

                      <?xml version="1.0" encoding="UTF-8"?>

                      <html xmlns="http://www.w3.org/1999/xhtml"

                            xmlns:h="http://java.sun.com/jsf/html"

                      after login sucess,when i click the button:

                      <h:commandButton value="print username and password to the console" action="#{email.receiveMail}"/>

                      then code run to error.

                            xmlns:ui="http://java.sun.com/jsf/facelets">

                      <ui:fragment rendered="#{identity.loggedIn}">

                          <div>username: <b>#{identity.user.id}</b>

                          </div>

                       

                          <h:form>

                              <h:commandButton value="print username and password to the console" action="#{email.receiveMail}"/>

                              <br/>

                              <h:commandButton id="logout" value="Log out" action="#{identity.logout}"/>

                          </h:form>

                      </ui:fragment>

                       

                      <h:form id="loginForm" rendered="#{not identity.loggedIn}">

                          <h:messages/>

                          <span>demo demo</span>

                          <div class="loginRow">

                       

                              <h:inputText id="name" value="#{credentials.username}"/>

                          </div>

                          <div class="loginRow">

                       

                              <h:inputSecret id="password" value="#{credentials.password}"/>

                          </div>

                       

                          <div class="buttons">

                              <h:commandButton id="login" value="LOGIN" action="#{identity.login}" type="submit"/>

                          </div>

                      </h:form>

                      =================

                       

                      in this jsf page, after login sucess,when i click the button:

                       

                      <h:commandButton value="print username and password to the console" action="#{email.receiveMail}"/>

                       

                      then code <System.out.println(((PasswordCredential) credentials.getCredential()).getValue());> run to null pointer exception.

                      • 8. Re: how to get user's password value after success authenticate?
                        nathandennis

                        you need to take a serious look at your pom.xml.

                         

                        from glancing at the project.. i would follow the seam doc on the configuration of the authenticator ... seam-bean.xml

                        <beans xmlns="http://java.sun.com/xml/ns/javaee"

                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                           xmlns:s="urn:java:ee"

                           xmlns:security="urn:java:org.jboss.seam.security"

                           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">     

                         

                           <security:IdentityImpl>

                              <s:modifies/>

                                  <security:authenticatorName>simpleAuthenticator</security:authenticatorName>

                           </security:IdentityImpl>

                           

                        </beans>

                         

                        get rid of the @Override

                        i also see you referencing identity without ever moving any sort of role into that.. you might want one at some point..

                         

                                setStatus(AuthenticationStatus.SUCCESS);
                                setUser(new SimpleUser("demo"));
                                identity.addRole("user", "USERS", "user");

                         

                         

                        but seriously.. you pom is all messed up.. you are using some versions of stuff that probably wont work. there is no repo info in there. I cant really tell what you have going on because this project will not compile with this build script.

                        • 9. Re: how to get user's password value after success authenticate?
                          shenlanemo

                          thanks nathan dennis.

                           

                          sorry !!!! my code is so in a mess.

                           

                          so i use official example "security-authorization" in seam-3.1.0.Final and modified a little to show the problem.

                           

                          1. i modifed the method in PrivilegedActions.java:

                          ============================

                          public void doSomethingRestricted() {

                                  System.out.println("print username and password:===========================");

                                  System.out.println(credentials.getUsername());

                                 

                                  System.out.println(((PasswordCredential)(credentials.getCredential())).getValue());

                                  System.out.println("print username and password:---------------------------");

                                  //messages.info("doSomethingRestricted() invoked");

                              }

                          ============================

                           

                           

                          2.cut @Override and modifed home.xhtml to add a <h:inputSecret> field.

                           

                           

                          3.called privilegedActions.doSomethingRestricted method by this commandButton:

                          <h:commandButton value="print password on console()" action="#{privilegedActions.doSomethingRestricted}"/>

                           

                           

                          the code [System.out.println(((PasswordCredential)(credentials.getCredential())).getValue());] still run to Exception.

                          • 10. Re: how to get user's password value after success authenticate?
                            bhanu246

                            Hi Haisheng !!!

                             

                             

                                   If you are using credentials.username and credentials.password seam will provide you to get the username and password by this to retreive the logged in username and password :

                             

                                 identity.getusername();

                                 identity.getpassword();

                             

                                 * Here is the sample of code which may help you out :

                             

                                    



                                                       <div style="color: #000; padding-left: 890px; padding-top: 12px;">Welcome,


                                                                    <h:outputText value=" #{identity.username}" /> <a:commandLink



                            action="#{myProfile.editMyProfile()}">

                             

                             

                             

                            Regards,

                            Prakash

                            • 11. Re: how to get user's password value after success authenticate?
                              shenlanemo

                              thanks bhanu prakash!!

                               

                              i want to get username and password in a back bean not jsf page.

                              • 12. Re: how to get user's password value after success authenticate?
                                bhanu246

                                Hi Haisheng !!!                  In your bean you can declare as :                                  @In              Identity identity;              and directly set the values in the setters for example :                 xxxx.setusername(identity.getusername());                  Regards ,  Bhanu Prakash

                                • 13. Re: how to get user's password value after success authenticate?
                                  lucaster

                                  Credentials is @RequestScoped, not @SessionScoped.

                                   

                                  You might want to store your username and password in a @SessionScoped bean after login success, in order to retreive them later.