4 Replies Latest reply on Aug 8, 2007 4:17 PM by indyjones

    Access UserModule from a portlet when not authenticated

      Portal: 2.6.1
      JB AS: 4.0.5
      MySQL: 4.2

      I am still trying to understand the security...

      For some reason i get a Hibernate class cast exception when trying to access the UserModule from a portlet in a session that is not currently authenticated...

      I am trying to implement a "Forgot My Password" functionality. To get the user data I was trying to use the UserModule while the user is not logged in...

      Why am I doing wrong?

      Thanks

      indy

        • 1. Re: Access UserModule from a portlet when not authenticated

          Here is the code....

          
          User test = userModule.findUserByUserName("admin");
          
          


          Here is the error

          
          java.lang.ClassCastException: org.hibernate.hql.ast.HqlToken cannot be cast to org.hibernate.hql.ast.HqlToken
          
          


          I do not get that error running the exact same code when the user is authenticated...

          Any ideas?

          Thanks

          Indy

          • 2. Re: Access UserModule from a portlet when not authenticated

            ok...i get the userModule the following way...

            
            userModule = (UserModule) new InitialContext().lookup("java:portal/UserModule");
            
            


            Thanks

            indy


            • 3. Re: Access UserModule from a portlet when not authenticated

              ok...got it to work...here is how I did it using JSF...

              Get the userModule through JNDI

              
              userModule = (UserModule) new InitialContext().lookup("java:portal/UserModule");
              
              



              Get the user by using its user id....NOT user name....

              DO THIS

              
              User test = userModule.findUserById(id);
              
              


              DO NOT DO THIS

              
              User test = userModule.findUserByUserName("admin");
              
              


              I basically wrote a simple Hibernate service layer to get the user id after a email is given and the answer to the secret question is correct.

              Then, create a new password and change it

              
              test.updatePassword(newpassword);
              
              


              Then fire an email off to the user with their new password. I used ...

              
              Session session = (Session) new InitialContext().lookup("java:Mail");
              
              


              That is configured through the deploy/mail-service.xml file. The Forums Portlet uses the same service

              POOF! I now have a self managed user password system...AKA..."Forgot My Password" link

              Indy

              • 4. Re: Access UserModule from a portlet when not authenticated

                The reason I was getting the Hibernate error was because of conflicts with my web apps Hibernate3.jar and the one in default/lib