2 Replies Latest reply on May 10, 2007 1:22 AM by alex chen

    How to store username/password in the session in login.jsp

    Richard Abbuhl Newbie

      This wiki page briefly describes how to store the username/password in the session using several intermediate servlets.
      http://wiki.jboss.org/wiki/Wiki.jsp?page=PortletLogin

      I just want the user to login and to store their username/password in the session so I can get this information later in a portlet or a struts portlet for authorization of a web service and backend authorization.

      I think I can accomplish this by changing login.jsp without requiring a new servlet. If I do require a servlet then I need to write the servlet, add it to portal-server.war, and change web.xml in portal-server.war.

      Does anyone have example source for this change, i.e. the login.jsp, and, if necessary, the servlet code, and the changes to web.xml to enable this change?

        • 1. Re: How to store username/password in the session in login.j
          Richard Abbuhl Newbie

          I added a savelogin java class to a jar file and installed it in jbportal\server\default\deploy\jboss-portal.sar\lib

          I changed login.jsp so the form calls savelogin:
          <form method="POST" action="<%= response.encodeURL("savelogin") %>" name="loginform" id="loginForm">

          I updated portal-server.war\WEB-INF\web.xml and added these lines:
          <!-- The portal servlet is the main entrance point -->

          <servlet-name>savelogin</servlet-name>
          <servlet-class>com.mycompany.login.savelogin</servlet-class>
          <load-on-startup>0</load-on-startup>


          <!-- Provide access to login -->
          <servlet-mapping>
          <servlet-name>savelogin</servlet-name>
          <url-pattern>/savelogin/*</url-pattern>
          </servlet-mapping>

          When I access the login page login.jsp and enter a username/password it tries to access this URL http://localhost:8080/portal/auth/portal/default/default/savelogin
          and then re-displays the login.jsp page.

          I am not sure how to put the correct URL in login.jsp which invokes the URL in web.xml to access the savelogin servlet.

          Any help would be greatly appreciated.


          • 2. Re: How to store username/password in the session in login.j
            alex chen Newbie

            I think if you only want to get the username, you may just call this method in jsp

            String username = request.getUserPrincipal().getName();