/** * Logs a system user in to OpenCms.<p> * * 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.<p> * * @param userName the users name * @param password the password * @param projectName the project to switch to after login (if null project is not switched) * @param redirectUri the URI to redirect to after login (if null the current URI is used) * * @throws IOException in case redirect after login was not successful */ public void login(String userName, String password, String projectName, String redirectUri) throws IOException { login(userName, password, projectName); if (m_loginException == null) { if (redirectUri != null) { getResponse().sendRedirect( OpenCms.getLinkManager().substituteLink(getCmsObject(), redirectUri, null, true)); } else { getResponse().sendRedirect(getFormLink()); } } }
/** * Returns the link to the form that contains the login element.<p> * * @return the link to the form that contains the login element */ public String getFormLink() { return link(getRequestContext().getUri()); }
/** * Constructor, with parameters.<p> * * @param context the JSP page context object * @param req the JSP request * @param res the JSP response */ public CmsJspLoginBean(PageContext context, HttpServletRequest req, HttpServletResponse res) { super(); init(context, req, res); }
/** * 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.<p> * * @throws IOException if redirect after logout fails */ public void logout() throws IOException { HttpSession session = getRequest().getSession(false); if (session != null) { session.invalidate(); } // logout was successful if (LOG.isInfoEnabled()) { LOG.info(Messages.get().getBundle().key( Messages.LOG_LOGOUT_SUCCESFUL_3, getRequestContext().currentUser().getName(), getRequestContext().addSiteRoot(getRequestContext().getUri()), getRequestContext().getRemoteAddress())); } getResponse().sendRedirect(getFormLink()); } }
CmsUser user = getCmsObject().readUser(userName); OpenCms.getSessionManager().checkCreateSessionForUser(user); getCmsObject().loginUser(userName, password, getRequestContext().getRemoteAddress()); session = getRequest().getSession(false); if (session != null) { session.invalidate(); session = getRequest().getSession(true); if (projectName != null) { getCmsObject().getRequestContext().setCurrentProject(getCmsObject().readProject(projectName)); if (!getCmsObject().getRequestContext().getCurrentProject().isOnlineProject()) { OpenCms.getSessionManager().updateSessionInfo(getCmsObject(), getRequest()); OpenCms.getSessionManager().sendBroadcast(null, loginMessage.getMessage(), user); Messages.LOG_LOGIN_SUCCESSFUL_3, userName, getRequestContext().addSiteRoot(getRequestContext().getUri()), getRequestContext().getRemoteAddress())); logLoginException(getRequestContext(), userName, currentLoginException);
getCmsObject().loginUser(userName, password, getRequestContext().getRemoteAddress()); session = getRequest().getSession(false); if (session != null) { session.invalidate(); session = getRequest().getSession(true); if (projectName != null) { getCmsObject().getRequestContext().setCurrentProject(getCmsObject().readProject(projectName)); Messages.LOG_LOGIN_SUCCESSFUL_3, userName, getRequestContext().addSiteRoot(getRequestContext().getUri()), getRequestContext().getRemoteAddress())); Messages.LOG_LOGIN_FAILED_DISABLED_3, userName, getRequestContext().addSiteRoot(getRequestContext().getUri()), getRequestContext().getRemoteAddress())); new Object[] { userName, getRequestContext().addSiteRoot(getRequestContext().getUri()), getRequestContext().getRemoteAddress(), m_loginException.getMessageContainer().getArgs()[2], m_loginException.getMessageContainer().getArgs()[3]})); Messages.LOG_LOGIN_FAILED_NO_USER_3,
/** * @see org.opencms.jsp.CmsJspLoginBean#getFormLink() */ @Override public String getFormLink() { if (getPreDefOuFqn() == null) { return super.getFormLink(); } return link("/system/login" + (String)getRequest().getAttribute(PARAM_PREDEF_OUFQN)); }
/** * Returns the currently logged in user.<p> * * @return the currently logged in user */ public CmsUser getUser() { return getRequestContext().getCurrentUser(); }
/** * Logs a system user in to OpenCms.<p> * * @param userName the users name * @param password the password */ public void login(String userName, String password) { login(userName, password, null); }
/** * Returns true if the current user is not the guest user, * i.e. if he already has logged in with some other user account.<p> * * @return true if the current user is already logged in */ public boolean isLoggedIn() { return !getCmsObject().getRequestContext().getCurrentUser().isGuestUser(); }
CmsJspLoginBean.logLoginException(currentCms.getRequestContext(), user, (CmsException)e); } else { LOG.error(e.getLocalizedMessage(), e);
/** * 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.<p> * * @throws IOException if redirect after logout fails */ public void logout() throws IOException { String loggedInUserName = getRequestContext().getCurrentUser().getName(); HttpSession session = getRequest().getSession(false); if (session != null) { session.invalidate(); /* we need this because a new session might be created after this method, but before the session info is updated in OpenCmsCore.showResource. */ getCmsObject().getRequestContext().setUpdateSessionEnabled(false); } // logout was successful if (LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_LOGOUT_SUCCESFUL_3, loggedInUserName, getRequestContext().addSiteRoot(getRequestContext().getUri()), getRequestContext().getRemoteAddress())); } getResponse().sendRedirect(getFormLink()); } }
/** * @see org.opencms.jsp.CmsJspLoginBean#getFormLink() */ @Override public String getFormLink() { if (getPreDefOuFqn() == null) { return super.getFormLink(); } String preDefOuFqn = (String)getRequest().getAttribute(PARAM_PREDEF_OUFQN); try { OpenCms.getOrgUnitManager().readOrganizationalUnit(getCmsObject(), preDefOuFqn); } catch (CmsException e) { // organizational unit does not exist return super.getFormLink(); } return link("/system/login" + CmsEncoder.escapeXml(preDefOuFqn)); }
/** * Returns the currently logged in user.<p> * * @return the currently logged in user */ public CmsUser getUser() { return getRequestContext().currentUser(); }
/** * Logs a system user in to OpenCms.<p> * * @param userName the users name * @param password the password */ public void login(String userName, String password) { login(userName, password, null); }
/** * Returns true if the current user is not the guest user, * i.e. if he already has logged in with some other user account.<p> * * @return true if the current user is already logged in */ public boolean isLoggedIn() { return !getCmsObject().getRequestContext().currentUser().isGuestUser(); }
/** * Logs a system user in to OpenCms.<p> * * 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.<p> * * @param userName the users name * @param password the password * @param projectName the project to switch to after login (if null project is not switched) * @param redirectUri the URI to redirect to after login (if null the current URI is used) * * @throws IOException in case redirect after login was not successful */ public void login(String userName, String password, String projectName, String redirectUri) throws IOException { login(userName, password, projectName); if (m_loginException == null) { if (redirectUri != null) { getResponse().sendRedirect( OpenCms.getLinkManager().substituteLink(getCmsObject(), redirectUri, null, true)); } else { getResponse().sendRedirect(getFormLink()); } } }
/** * Returns the link to the form that contains the login element.<p> * * @return the link to the form that contains the login element */ public String getFormLink() { return link(getRequestContext().getUri()); }
/** * Returns the user name of the currently logged in user.<p> * * @return the user name of the currently logged in user */ public String getUserName() { return getRequestContext().getCurrentUser().getName(); }
/** * @see org.opencms.jsp.CmsJspLoginBean#login(java.lang.String, java.lang.String, java.lang.String) */ @Override public void login(String userName, String password, String projectName) { super.login(userName, password, projectName); if (isLoginSuccess()) { CmsObject cms = getCmsObject(); CmsPersistentLoginTokenHandler tokenHandler = new CmsPersistentLoginTokenHandler(); tokenHandler.setTokenLifetime(m_tokenLifetime); try { final String token = tokenHandler.createToken(cms); Cookie cookie = new Cookie(CmsPersistentLoginAuthorizationHandler.COOKIE_NAME, token); cookie.setMaxAge((int)(m_tokenLifetime / 1000)); cookie.setPath(getCookiePath(true)); getResponse().addCookie(cookie); m_isTokenSet = true; } catch (CmsException e) { LOG.error(e.getMessage(), e); } } }