3 Replies Latest reply on Sep 17, 2009 11:02 PM by Tony Herstell

    Identity Manager how do you change password.

    Tony Herstell Master

      Using password hash... how do you actually change the password?


      I need to change but when I do in code and check DB all I see is the un MD5'd password.



        • 1. Re: Identity Manager how do you change password.
          Stefano Travelli Newbie


          IdentityStore identityStore = (IdentityStore) Component
                 .getInstance("org.jboss.seam.security.identityStore", true);
          identityStore.changePassword(username, password);
          



          • 2. Re: Identity Manager how do you change password.
            Tony Herstell Master

            Ok, tried this


            if (crudsController.getMode() == Mode.UPDATE) {
                 // Update the user. HACK HACK
                 User this_user = (User) entityManager.createQuery("from User u where u.id = :id").setParameter("id", user.getId()).getSingleResult();
                 updateUser(this.user, this_user);
                 entityManager.persist(this_user);
                 final User final_user = this_user;
                 new RunAsOperation() {
                      public void execute() {
                           identityManager.changePassword(final_user.getEmail(), final_user.getPasswordHash());
                      }
                      }.addRole("admin")
                      .run();
            //     Credentials credentials = identity.getCredentials();
            //     credentials.setUsername(this_user.getEmail());




            but get this!


            (Had to do runas as by default don't have permission to change your password....


            07:04:22,234 INFO  [STDOUT] Hibernate: 
                select
                    user0_.id as id1_,
                    user0_.email as email1_,
                    user0_.enabled as enabled1_,
                    user0_.firstname as firstname1_,
                    user0_.lastname as lastname1_,
                    user0_.passwordhash as password6_1_,
                    user0_.version4OptLock as version7_1_ 
                from
                    User user0_ 
                where
                    user0_.id=? limit ?
            07:04:43,234 DEBUG [Lifecycle] >>> Begin call
            07:04:43,234 DEBUG [Contexts] destroying business process context
            07:04:43,234 DEBUG [Contexts] destroying conversation context
            07:04:43,234 DEBUG [Contexts] destroying: org.jboss.seam.bpm.businessProcess
            07:04:43,234 DEBUG [Contexts] flushing server-side conversation context
            07:04:43,234 DEBUG [Contexts] flushing session context
            07:04:43,234 DEBUG [Contexts] destroying event context
            07:04:43,250 DEBUG [Contexts] destroying: org.jboss.seam.transaction.transaction
            07:04:43,250 DEBUG [Contexts] destroying: org.jboss.seam.core.manager
            07:04:43,250 DEBUG [Contexts] destroying: org.jboss.seam.core.events
            07:04:43,250 DEBUG [Lifecycle] <<< End call
            07:06:27,468 DEBUG [SeamExpressionEvaluator] Exceptions occurred when parsing ${risingstars.registrationController.updateUser}
            07:06:27,468 DEBUG [SeamExpressionEvaluator] Possible cause
            javax.el.ELException: java.lang.reflect.InvocationTargetException
                 at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
                 at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
                 at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                 at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                 at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                 at org.jboss.seam.bpm.SeamExpressionEvaluator$1.evaluate(SeamExpressionEvaluator.java:92)
                 at org.jboss.seam.bpm.SeamExpressionEvaluator.evaluate(SeamExpressionEvaluator.java:45)
                 at org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator.evaluate(JbpmExpressionEvaluator.java:39)
                 at org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator.evaluate(JbpmExpressionEvaluator.java:30)
                 at org.jbpm.graph.def.Action.execute(Action.java:118)
                 at org.jboss.seam.bpm.SeamUserCodeInterceptor.executeAction(SeamUserCodeInterceptor.java:70)
                 at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:262)
                 at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:220)
                 at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:190)
                 at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:174)
                 at org.jbpm.graph.def.Transition.take(Transition.java:138)
                 at org.jbpm.graph.def.Node.leave(Node.java:394)
                 at org.jbpm.graph.exe.Token.signal(Token.java:195)
                 at org.jbpm.graph.exe.Token.signal(Token.java:158)
                 at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:283)
                 at org.jboss.seam.pageflow.Pageflow.signal(Pageflow.java:485)
                 at org.jboss.seam.pageflow.Pageflow.navigate(Pageflow.java:341)
                 at org.jboss.seam.jsf.SeamNavigationHandler.handleNavigation(SeamNavigationHandler.java:40)
                 at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:130)
                 at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                 at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
                 at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:318)
                 at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:293)
                 at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:250)
                 at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:463)
                 at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                 at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                 at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                 at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                 at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                 at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                 at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                 at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                 at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                 at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                 at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                 at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                 at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                 at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:436)
                 at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:384)
                 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                 at java.lang.Thread.run(Thread.java:619)
            Caused by: java.lang.reflect.InvocationTargetException
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:597)
                 at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                 at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                 at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                 at nz.co.softwarefactory.risingstars.controller.user.RegistrationControllerImpl_$$_javassist_seam_2.updateUser(RegistrationControllerImpl_$$_javassist_seam_2.java)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:597)
                 at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
                 ... 73 more
            Caused by: java.lang.NoClassDefFoundError: nz/co/softwarefactory/risingstars/controller/user/RegistrationControllerImpl$3
                 at nz.co.softwarefactory.risingstars.controller.user.RegistrationControllerImpl.updateUser(RegistrationControllerImpl.java:211)
                 ... 99 more





            Humm....

            • 3. Re: Identity Manager how do you change password.
              Tony Herstell Master

              Got a working version.


              log.info("> " + this.getClass().getName()+ " updateUser ");
                        
                   if (crudsController.getMode() == Mode.UPDATE) {
                        // Update the user. HACK HACK
                        User this_user = (User) entityManager.createQuery("from User u where u.id = :id").setParameter("id", user.getId()).getSingleResult();
                        updateUser(this.user, this_user);
                        entityManager.persist(this_user);
                        final User final_user = this_user;
                        new RunAsOperation() {
                             public void execute() {
                                  identityManager.changePassword(final_user.getEmail(), final_user.getPasswordHash());
                             }
                             }.addRole("admin")
                             .run();
                        Credentials credentials = identity.getCredentials();
                        credentials.setUsername(this_user.getEmail());
                        statusMessages.addFromResourceBundle(Severity.INFO, "registration_user_successfully_updated", user.getLastname() + "," + user.getFirstname());
                   } else {
                        throw new IllegalArgumentException(this.getClass().getName() + "updateUser called with disallowed Mode type");
                   }
                        
                   log.info("< " + this.getClass().getName()+ " updateUser ");




              The HACK part is due to open JIRA JBSEAM-4411