Class CmsJspLoginBean

  • Direct Known Subclasses:
    CmsJspLoginPersistingBean, CmsLoginHelper

    public class CmsJspLoginBean
    extends CmsJspActionElement
    Provides convenient wrappers useful to create user login pages.

    Initialize this bean at the beginning of your JSP like this:

     <jsp:useBean id="cmslogin" class="org.opencms.jsp.CmsJspLoginBean">
     <% cmslogin.init(pageContext, request, response); %>
     </jsp:useBean>
     

    Since:
    6.0.0
    • Constructor Detail

      • CmsJspLoginBean

        public CmsJspLoginBean()
        Empty constructor, required for every JavaBean.

      • CmsJspLoginBean

        public CmsJspLoginBean​(javax.servlet.jsp.PageContext context,
                               javax.servlet.http.HttpServletRequest req,
                               javax.servlet.http.HttpServletResponse res)
        Constructor, with parameters.

        Parameters:
        context - the JSP page context object
        req - the JSP request
        res - the JSP response
    • Method Detail

      • logLoginException

        public static void logLoginException​(CmsRequestContext requestContext,
                                             java.lang.String userName,
                                             CmsException currentLoginException)
        Logs any login exception.

        Parameters:
        requestContext - the request context
        userName - the user name
        currentLoginException - the exception to log
      • getFormLink

        public java.lang.String getFormLink()
        Returns the link to the form that contains the login element.

        Returns:
        the link to the form that contains the login element
      • getLoginException

        public CmsException getLoginException()
        Returns the exception that was thrown after login, or null if no Exception was thrown (i.e. login was successful or not attempted).

        Returns:
        the exception thrown after login
      • getUser

        public CmsUser getUser()
        Returns the currently logged in user.

        Returns:
        the currently logged in user
      • getUserName

        public java.lang.String getUserName()
        Returns the user name of the currently logged in user.

        Returns:
        the user name of the currently logged in user
      • isLoggedIn

        public boolean isLoggedIn()
        Returns true if the current user is not the guest user, i.e. if he already has logged in with some other user account.

        Returns:
        true if the current user is already logged in
      • isLoginSuccess

        public boolean isLoginSuccess()
        Indicates if a login was successful or not.

        Returns:
        true if the login was successful
      • login

        public void login​(java.lang.String userName,
                          java.lang.String password)
        Logs a system user in to OpenCms.

        Parameters:
        userName - the users name
        password - the password
      • login

        public void login​(java.lang.String userName,
                          java.lang.String password,
                          java.lang.String projectName)
        Logs a system user into OpenCms.

        Note that if a login project name is provided, this project must exist, otherwise the login is regarded as a failure even if the user data was correct.

        Parameters:
        userName - the users name
        password - the password
        projectName - the project to switch to after login (if null project is not switched)
      • login

        public void login​(java.lang.String userName,
                          java.lang.String password,
                          java.lang.String projectName,
                          java.lang.String redirectUri)
                   throws java.io.IOException
        Logs a system user in to OpenCms.

        Note that if a login project name is provided, this project must exist, otherwise the login is regarded as a failure even if the user data was correct.

        Parameters:
        userName - the users name
        password - the password
        projectName - the project to switch to after login (if null project is not switched)
        redirectUri - the URI to redirect to after login (if null the current URI is used)
        Throws:
        java.io.IOException - in case redirect after login was not successful
      • logout

        public void logout()
                    throws java.io.IOException
        Logs a user out, i.e. destroys the current users session, after that the current page will be redirected to itself one time to ensure that the users session is truly destroyed.

        Throws:
        java.io.IOException - if redirect after logout fails
      • setVerificationCode

        public void setVerificationCode​(java.lang.String code)
        Sets the verification code for two-factor authentication.
        Parameters:
        code - the verification code