001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.login; 029 030import org.opencms.db.CmsLoginMessage; 031import org.opencms.db.CmsUserSettings; 032import org.opencms.file.CmsObject; 033import org.opencms.file.CmsProject; 034import org.opencms.file.CmsRequestContext; 035import org.opencms.file.CmsUser; 036import org.opencms.i18n.CmsMessageContainer; 037import org.opencms.i18n.CmsResourceBundleLoader; 038import org.opencms.jsp.CmsJspActionElement; 039import org.opencms.jsp.CmsJspLoginBean; 040import org.opencms.main.CmsException; 041import org.opencms.main.CmsLog; 042import org.opencms.main.OpenCms; 043import org.opencms.security.CmsCustomLoginException; 044import org.opencms.security.CmsRole; 045import org.opencms.ui.A_CmsDialogContext; 046import org.opencms.ui.A_CmsUI; 047import org.opencms.ui.CmsVaadinUtils; 048import org.opencms.ui.I_CmsDialogContext; 049import org.opencms.ui.I_CmsDialogContext.ContextType; 050import org.opencms.ui.Messages; 051import org.opencms.ui.apps.CmsAppHierarchyConfiguration; 052import org.opencms.ui.apps.CmsAppWorkplaceUi; 053import org.opencms.ui.apps.CmsFileExplorerConfiguration; 054import org.opencms.ui.components.CmsBasicDialog; 055import org.opencms.ui.components.CmsBasicDialog.DialogWidth; 056import org.opencms.ui.dialogs.CmsUserDataDialog; 057import org.opencms.ui.login.CmsLoginHelper.LoginParameters; 058import org.opencms.util.CmsStringUtil; 059import org.opencms.util.CmsUUID; 060import org.opencms.workplace.CmsLoginUserAgreement; 061import org.opencms.workplace.CmsWorkplace; 062import org.opencms.workplace.CmsWorkplaceLoginHandler; 063import org.opencms.workplace.CmsWorkplaceManager; 064import org.opencms.workplace.CmsWorkplaceSettings; 065 066import java.io.IOException; 067import java.text.SimpleDateFormat; 068import java.util.Collection; 069import java.util.Date; 070import java.util.List; 071import java.util.MissingResourceException; 072import java.util.ResourceBundle; 073 074import javax.servlet.http.HttpServletRequest; 075import javax.servlet.http.HttpServletResponse; 076import javax.servlet.http.HttpSession; 077 078import org.apache.commons.logging.Log; 079 080import com.vaadin.server.Page; 081import com.vaadin.server.VaadinService; 082import com.vaadin.server.VaadinServletRequest; 083import com.vaadin.server.VaadinServletResponse; 084import com.vaadin.ui.Component; 085import com.vaadin.ui.UI; 086 087/** 088 * Controller class which actually handles the login dialog logic.<p> 089 */ 090public class CmsLoginController { 091 092 /** 093 * Represents the login target information.<p> 094 */ 095 public static class CmsLoginTargetInfo { 096 097 /** The password. */ 098 private String m_password; 099 100 /** The login target. */ 101 private String m_target; 102 103 /** The user. */ 104 private String m_user; 105 106 /** 107 * Creates a new instance.<p> 108 * 109 * @param target the login target 110 * @param user the user name 111 * @param password the password 112 */ 113 public CmsLoginTargetInfo(String target, String user, String password) { 114 115 super(); 116 m_target = target; 117 m_user = user; 118 m_password = password; 119 } 120 121 /** 122 * Returns the password.<p> 123 * 124 * @return the password 125 */ 126 public String getPassword() { 127 128 return m_password; 129 } 130 131 /** 132 * Returns the target.<p> 133 * 134 * @return the target 135 */ 136 public String getTarget() { 137 138 return m_target; 139 } 140 141 /** 142 * Returns the user.<p> 143 * 144 * @return the user 145 */ 146 public String getUser() { 147 148 return m_user; 149 } 150 } 151 152 /** 153 * Helper subclass of CmsLoginUserAgreement which can be used without a page context.<p> 154 * 155 * This is only used for detecting whether we need to display the user agreement dialog, not for displaying the dialog itself.<p> 156 */ 157 protected static class UserAgreementHelper extends CmsLoginUserAgreement { 158 159 /** The replacement CMS context. */ 160 private CmsObject m_cms; 161 162 /** The replacemenet workplace settings. */ 163 private CmsWorkplaceSettings m_wpSettings; 164 165 /** 166 * Creates a new instance.<p> 167 * 168 * @param cms the replacement CMS context 169 * @param wpSettings the replacement workplace settings 170 */ 171 public UserAgreementHelper(CmsObject cms, CmsWorkplaceSettings wpSettings) { 172 173 super(null); 174 m_cms = cms; 175 m_wpSettings = wpSettings; 176 initAcceptData(); 177 } 178 179 /** 180 * @see org.opencms.workplace.CmsWorkplace#getCms() 181 */ 182 @Override 183 public CmsObject getCms() { 184 185 return m_cms; 186 } 187 188 /** 189 * @see org.opencms.workplace.CmsWorkplace#getSettings() 190 */ 191 @Override 192 public CmsWorkplaceSettings getSettings() { 193 194 return m_wpSettings; 195 } 196 197 /** 198 * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement) 199 */ 200 @Override 201 protected void initWorkplaceMembers(CmsJspActionElement jsp) { 202 203 // do nothing 204 } 205 } 206 207 /** Additional info key to mark accounts as locked due to inactivity. */ 208 public static final String KEY_ACCOUNT_LOCKED = "accountLocked"; 209 210 /** The logger for this class. */ 211 private static final Log LOG = CmsLog.getLog(CmsLoginController.class); 212 213 /** The UI instance. */ 214 CmsLoginUI m_ui; 215 216 /** The administrator CMS context. */ 217 private CmsObject m_adminCms; 218 219 /** The parameters collected when the login app was opened. */ 220 private LoginParameters m_params; 221 222 /*** 223 * Creates a new instance.<p> 224 * 225 * @param adminCms the admin cms context 226 * @param params the parameters for the UI 227 */ 228 public CmsLoginController(CmsObject adminCms, LoginParameters params) { 229 230 m_params = params; 231 m_adminCms = adminCms; 232 } 233 234 /** 235 * Returns the link to the login form.<p> 236 * 237 * @param cms the current cms context 238 * 239 * @return the login form link 240 */ 241 public static String getFormLink(CmsObject cms) { 242 243 return OpenCms.getLinkManager().substituteLinkForUnknownTarget( 244 cms, 245 CmsWorkplaceLoginHandler.LOGIN_HANDLER, 246 false); 247 } 248 249 /** 250 * Gets the login target link.<p> 251 * 252 * @param currentCms the current CMS context 253 * @param settings the workplace settings 254 * @param requestedResource the requested resource parameter 255 * 256 * @return the login target 257 * 258 * @throws CmsException in case the user has insufficient permissions to access the login target 259 */ 260 public static String getLoginTarget(CmsObject currentCms, CmsWorkplaceSettings settings, String requestedResource) 261 throws CmsException { 262 263 String directEditPath = CmsLoginHelper.getDirectEditPath(currentCms, settings.getUserSettings(), false); 264 String target = ""; 265 boolean checkRole = false; 266 String fragment = UI.getCurrent() != null ? UI.getCurrent().getPage().getUriFragment() : ""; 267 boolean workplace2 = false; 268 269 if ((requestedResource == null) && (directEditPath != null)) { 270 target = directEditPath; 271 } else if ((requestedResource != null) && !CmsWorkplace.JSP_WORKPLACE_URI.equals(requestedResource)) { 272 target = requestedResource; 273 } else { 274 workplace2 = true; 275 target = CmsVaadinUtils.getWorkplaceLink(); 276 checkRole = true; 277 } 278 279 UserAgreementHelper userAgreementHelper = new UserAgreementHelper(currentCms, settings); 280 boolean showUserAgreement = userAgreementHelper.isShowUserAgreement(); 281 if (showUserAgreement) { 282 target = userAgreementHelper.getConfigurationVfsPath() 283 + "?" 284 + CmsLoginUserAgreement.PARAM_WPRES 285 + "=" 286 + target; 287 } 288 if (checkRole && !OpenCms.getRoleManager().hasRole(currentCms, CmsRole.WORKPLACE_USER)) { 289 workplace2 = false; 290 target = CmsLoginHelper.getDirectEditPath(currentCms, settings.getUserSettings(), true); 291 if (target == null) { 292 throw new CmsCustomLoginException( 293 org.opencms.workplace.Messages.get().container( 294 org.opencms.workplace.Messages.GUI_LOGIN_FAILED_NO_WORKPLACE_PERMISSIONS_0)); 295 } 296 } 297 if (!workplace2) { 298 target = OpenCms.getLinkManager().substituteLink(currentCms, target); 299 } 300 301 if (workplace2 && CmsStringUtil.isEmptyOrWhitespaceOnly(fragment)) { 302 if (settings.getUserSettings().getStartView().startsWith("/")) { 303 if (CmsWorkplace.VIEW_WORKPLACE.equals(settings.getUserSettings().getStartView())) { 304 fragment = CmsFileExplorerConfiguration.APP_ID; 305 } else if (CmsWorkplace.VIEW_ADMIN.equals(settings.getUserSettings().getStartView())) { 306 fragment = CmsAppHierarchyConfiguration.APP_ID; 307 } 308 } else { 309 fragment = settings.getUserSettings().getStartView(); 310 } 311 } 312 313 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(fragment)) { 314 target += "#" + fragment; 315 } 316 return target; 317 } 318 319 /** 320 * Logs the current user out by invalidating the session an reloading the current URI.<p> 321 * Important: This works only within vaadin apps.<p> 322 */ 323 public static void logout() { 324 325 CmsObject cms = A_CmsUI.getCmsObject(); 326 if (UI.getCurrent() instanceof CmsAppWorkplaceUi) { 327 ((CmsAppWorkplaceUi)UI.getCurrent()).onWindowClose(); 328 } 329 String loggedInUser = cms.getRequestContext().getCurrentUser().getName(); 330 UI.getCurrent().getSession().close(); 331 String loginLink = OpenCms.getLinkManager().substituteLinkForUnknownTarget( 332 cms, 333 CmsWorkplaceLoginHandler.LOGIN_HANDLER, 334 false); 335 VaadinService.getCurrentRequest().getWrappedSession().invalidate(); 336 Page.getCurrent().setLocation(loginLink); 337 // logout was successful 338 if (LOG.isInfoEnabled()) { 339 LOG.info( 340 org.opencms.jsp.Messages.get().getBundle().key( 341 org.opencms.jsp.Messages.LOG_LOGOUT_SUCCESFUL_3, 342 loggedInUser, 343 "{workplace logout option}", 344 cms.getRequestContext().getRemoteAddress())); 345 } 346 } 347 348 /** 349 * Logs out the current user redirecting to the login form afterwards.<p> 350 * 351 * @param cms the cms context 352 * @param request the servlet request 353 * @param response the servlet response 354 * 355 * @throws IOException if writing to the response fails 356 */ 357 public static void logout(CmsObject cms, HttpServletRequest request, HttpServletResponse response) 358 throws IOException { 359 360 String loggedInUser = cms.getRequestContext().getCurrentUser().getName(); 361 HttpSession session = request.getSession(false); 362 if (session != null) { 363 session.invalidate(); 364 /* we need this because a new session might be created after this method, 365 but before the session info is updated in OpenCmsCore.showResource. */ 366 cms.getRequestContext().setUpdateSessionEnabled(false); 367 } 368 // logout was successful 369 if (LOG.isInfoEnabled()) { 370 LOG.info( 371 org.opencms.jsp.Messages.get().getBundle().key( 372 org.opencms.jsp.Messages.LOG_LOGOUT_SUCCESFUL_3, 373 loggedInUser, 374 cms.getRequestContext().addSiteRoot(cms.getRequestContext().getUri()), 375 cms.getRequestContext().getRemoteAddress())); 376 } 377 response.sendRedirect(getFormLink(cms)); 378 } 379 380 /** 381 * Gets the PC type.<p> 382 * 383 * @return the PC type 384 */ 385 public String getPcType() { 386 387 String result = m_params.getPcType(); 388 if (CmsStringUtil.isEmptyOrWhitespaceOnly(result)) { 389 result = "public"; 390 } 391 return result; 392 } 393 394 /** 395 * Returns the reset password link.<p> 396 * 397 * @return the reset password link 398 */ 399 public String getResetPasswordLink() { 400 401 return OpenCms.getLinkManager().substituteLinkForUnknownTarget( 402 CmsLoginUI.m_adminCms, 403 CmsWorkplaceLoginHandler.LOGIN_HANDLER, 404 false) + "?" + CmsLoginHelper.PARAM_RESET_PASSWORD; 405 } 406 407 /** 408 * Returns true if the security option should be displayed in the login dialog.<p> 409 * 410 * @return true if the security option should be displayed in the login dialog 411 */ 412 public boolean isShowSecure() { 413 414 return OpenCms.getLoginManager().isEnableSecurity(); 415 } 416 417 /** 418 * Called when the user clicks on the 'forgot password' button.<p> 419 */ 420 public void onClickForgotPassword() { 421 422 A_CmsUI.get().getPage().setLocation(getResetPasswordLink()); 423 } 424 425 /** 426 * Called when the user clicks on the login button.<p> 427 */ 428 public void onClickLogin() { 429 430 String user = m_ui.getUser(); 431 String password = m_ui.getPassword(); 432 CmsMessageContainer message = CmsLoginHelper.validateUserAndPasswordNotEmpty(user, password); 433 CmsLoginMessage loginMessage = OpenCms.getLoginManager().getLoginMessage(); 434 String storedMessage = null; 435 if ((loginMessage != null) && !loginMessage.isLoginCurrentlyForbidden() && loginMessage.isActive()) { 436 storedMessage = loginMessage.getMessage(); 437 // If login is forbidden, we will get an error message anyway, so we don't need to store the message here 438 } 439 if (message != null) { 440 String errorMessage = message.key(m_params.getLocale()); 441 // m_ui.displayError(errorMessage); 442 displayError(errorMessage, true); 443 return; 444 } 445 446 String ou = m_ui.getOrgUnit(); 447 String realUser = CmsStringUtil.joinPaths(ou, user); 448 String pcType = m_ui.getPcType(); 449 CmsObject currentCms = A_CmsUI.getCmsObject(); 450 CmsUser userObj = null; 451 452 try { 453 try { 454 userObj = currentCms.readUser(realUser); 455 } catch (CmsException e) { 456 LOG.warn(e.getLocalizedMessage(), e); 457 message = org.opencms.workplace.Messages.get().container( 458 org.opencms.workplace.Messages.GUI_LOGIN_FAILED_0); 459 displayError(message.key(m_params.getLocale()), true, true); 460 return; 461 } 462 if (OpenCms.getLoginManager().canLockBecauseOfInactivity(currentCms, userObj)) { 463 boolean locked = null != userObj.getAdditionalInfo().get(KEY_ACCOUNT_LOCKED); 464 if (locked) { 465 displayError(CmsInactiveUserMessages.getLockoutText(A_CmsUI.get().getLocale()), false); 466 return; 467 } 468 } 469 String messageToChange = ""; 470 if (OpenCms.getLoginManager().isPasswordReset(currentCms, userObj)) { 471 messageToChange = CmsVaadinUtils.getMessageText(Messages.GUI_PWCHANGE_RESET_0); 472 } 473 if (OpenCms.getLoginManager().requiresPasswordChange(currentCms, userObj)) { 474 messageToChange = getPasswordChangeMessage(); 475 } 476 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(messageToChange)) { 477 CmsChangePasswordDialog passwordDialog = new CmsChangePasswordDialog( 478 currentCms, 479 userObj, 480 A_CmsUI.get().getLocale()); 481 passwordDialog.setAdditionalMessage(messageToChange); 482 A_CmsUI.get().setContentToDialog( 483 Messages.get().getBundle(A_CmsUI.get().getLocale()).key(Messages.GUI_PWCHANGE_HEADER_0) 484 + userObj.getSimpleName(), 485 passwordDialog); 486 return; 487 } 488 // do a provisional login first, to check the login target 489 CmsObject cloneCms = OpenCms.initCmsObject(currentCms); 490 cloneCms.loginUser(realUser, password); 491 CmsWorkplaceSettings settings = CmsLoginHelper.initSiteAndProject(cloneCms); 492 final String loginTarget = getLoginTarget(cloneCms, settings, m_params.getRequestedResource()); 493 494 // make sure we have a new session after login for security reasons 495 HttpSession session = ((HttpServletRequest)VaadinService.getCurrentRequest()).getSession(false); 496 if (session != null) { 497 session.invalidate(); 498 } 499 session = ((HttpServletRequest)VaadinService.getCurrentRequest()).getSession(true); 500 501 // provisional login successful, now do for real 502 currentCms.loginUser(realUser, password); 503 if (LOG.isInfoEnabled()) { 504 CmsRequestContext context = currentCms.getRequestContext(); 505 LOG.info( 506 org.opencms.jsp.Messages.get().getBundle().key( 507 org.opencms.jsp.Messages.LOG_LOGIN_SUCCESSFUL_3, 508 context.getCurrentUser().getName(), 509 "{workplace login dialog}", 510 context.getRemoteAddress())); 511 } 512 settings = CmsLoginHelper.initSiteAndProject(currentCms); 513 OpenCms.getSessionManager().updateSessionInfo( 514 currentCms, 515 (HttpServletRequest)VaadinService.getCurrentRequest()); 516 if ((loginMessage != null) && loginMessage.isLoginCurrentlyForbidden()) { 517 if (loginMessage.getTimeEnd() == CmsLoginMessage.DEFAULT_TIME_END) { 518 // we are an administrator 519 storedMessage = org.opencms.workplace.Messages.get().container( 520 org.opencms.workplace.Messages.GUI_LOGIN_SUCCESS_WITH_MESSAGE_WITHOUT_TIME_1, 521 loginMessage.getMessage(), 522 new Date(loginMessage.getTimeEnd())).key(A_CmsUI.get().getLocale()); 523 524 } else { 525 // we are an administrator 526 storedMessage = org.opencms.workplace.Messages.get().container( 527 org.opencms.workplace.Messages.GUI_LOGIN_SUCCESS_WITH_MESSAGE_2, 528 loginMessage.getMessage(), 529 new Date(loginMessage.getTimeEnd())).key(A_CmsUI.get().getLocale()); 530 } 531 } 532 533 if (storedMessage != null) { 534 OpenCms.getSessionManager().sendBroadcast( 535 null, 536 storedMessage, 537 currentCms.getRequestContext().getCurrentUser()); 538 } 539 540 CmsLoginHelper.setCookieData( 541 pcType, 542 user, 543 ou, 544 (VaadinServletRequest)(VaadinService.getCurrentRequest()), 545 (VaadinServletResponse)(VaadinService.getCurrentResponse())); 546 VaadinService.getCurrentRequest().getWrappedSession().setAttribute( 547 CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS, 548 settings); 549 550 final boolean isPublicPC = CmsLoginForm.PC_TYPE_PUBLIC.equals(pcType); 551 if (OpenCms.getLoginManager().requiresUserDataCheck(currentCms, userObj)) { 552 I_CmsDialogContext context = new A_CmsDialogContext("", ContextType.appToolbar, null) { 553 554 @Override 555 public void finish(CmsProject project, String siteRoot) { 556 557 finish(null); 558 } 559 560 @Override 561 public void finish(Collection<CmsUUID> result) { 562 563 m_ui.openLoginTarget(loginTarget, isPublicPC); 564 } 565 566 public void focus(CmsUUID structureId) { 567 568 // nothing to do 569 } 570 571 public List<CmsUUID> getAllStructureIdsInView() { 572 573 return null; 574 } 575 576 @Override 577 public void start(String title, Component dialog, DialogWidth style) { 578 579 if (dialog != null) { 580 m_window = CmsBasicDialog.prepareWindow(style); 581 m_window.setCaption(title); 582 m_window.setContent(dialog); 583 UI.getCurrent().addWindow(m_window); 584 if (dialog instanceof CmsBasicDialog) { 585 ((CmsBasicDialog)dialog).initActionHandler(m_window); 586 } 587 } 588 } 589 590 public void updateUserInfo() { 591 592 // not supported 593 } 594 }; 595 CmsUser u = currentCms.readUser(userObj.getId()); 596 u.setAdditionalInfo( 597 CmsUserSettings.ADDITIONAL_INFO_LAST_USER_DATA_CHECK, 598 Long.toString(System.currentTimeMillis())); 599 currentCms.writeUser(u); 600 CmsUserDataDialog dialog = new CmsUserDataDialog(context, true); 601 context.start(dialog.getTitle(UI.getCurrent().getLocale()), dialog); 602 } else { 603 604 m_ui.openLoginTarget(loginTarget, isPublicPC); 605 } 606 } catch (Exception e) { 607 608 // there was an error during login 609 if (e instanceof CmsException) { 610 CmsMessageContainer exceptionMessage = ((CmsException)e).getMessageContainer(); 611 if (org.opencms.security.Messages.ERR_LOGIN_FAILED_DISABLED_2 == exceptionMessage.getKey()) { 612 // the user account is disabled 613 message = org.opencms.workplace.Messages.get().container( 614 org.opencms.workplace.Messages.GUI_LOGIN_FAILED_DISABLED_0); 615 } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_TEMP_DISABLED_4 == exceptionMessage.getKey()) { 616 // the user account is temporarily disabled because of too many login failures 617 message = org.opencms.workplace.Messages.get().container( 618 org.opencms.workplace.Messages.GUI_LOGIN_FAILED_TEMP_DISABLED_0); 619 } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_WITH_MESSAGE_1 == exceptionMessage.getKey()) { 620 // all logins have been disabled be the Administration 621 CmsLoginMessage loginMessage2 = OpenCms.getLoginManager().getLoginMessage(); 622 if (loginMessage2 != null) { 623 message = org.opencms.workplace.Messages.get().container( 624 org.opencms.workplace.Messages.GUI_LOGIN_FAILED_WITH_MESSAGE_1, 625 loginMessage2.getMessage()); 626 } 627 } 628 } 629 if (message == null) { 630 if (e instanceof CmsCustomLoginException) { 631 message = ((CmsCustomLoginException)e).getMessageContainer(); 632 } else { 633 // any other error - display default message 634 message = org.opencms.workplace.Messages.get().container( 635 org.opencms.workplace.Messages.GUI_LOGIN_FAILED_0); 636 displayError(message.key(m_params.getLocale()), true, true); 637 return; 638 } 639 } 640 641 if (e instanceof CmsException) { 642 CmsJspLoginBean.logLoginException(currentCms.getRequestContext(), user, (CmsException)e); 643 } else { 644 LOG.error(e.getLocalizedMessage(), e); 645 } 646 displayError(message.key(m_params.getLocale()), false); 647 return; 648 } 649 } 650 651 /** 652 * Called on initialization.<p> 653 */ 654 public void onInit() { 655 656 String authToken = m_params.getAuthToken(); 657 if (authToken != null) { 658 m_ui.showForgotPasswordView(authToken); 659 } else if (m_params.isReset()) { 660 m_ui.showPasswordResetDialog(); 661 } else { 662 boolean loggedIn = !A_CmsUI.getCmsObject().getRequestContext().getCurrentUser().isGuestUser(); 663 m_ui.setSelectableOrgUnits(CmsLoginHelper.getOrgUnitsForLoginDialog(A_CmsUI.getCmsObject(), null)); 664 if (loggedIn) { 665 if (m_params.isLogout()) { 666 logout(); 667 } else { 668 m_ui.showAlreadyLoggedIn(); 669 } 670 } else { 671 m_ui.showLoginView(m_params.getOufqn()); 672 } 673 } 674 675 } 676 677 /** 678 * Sets the login ui reference.<p> 679 * 680 * @param ui the login ui 681 */ 682 public void setUi(CmsLoginUI ui) { 683 684 m_ui = ui; 685 } 686 687 /** 688 * Returns the message to be displayed for the user data check dialog.<p> 689 * 690 * @return the message to display 691 */ 692 protected String getPasswordChangeMessage() { 693 694 ResourceBundle bundle = null; 695 try { 696 bundle = CmsResourceBundleLoader.getBundle("org.opencms.passwordchange.custom", A_CmsUI.get().getLocale()); 697 return bundle.getString("passwordchange.text"); 698 } catch (MissingResourceException e) { 699 return CmsVaadinUtils.getMessageText(Messages.GUI_PWCHANGE_INTERVAL_EXPIRED_0); 700 } 701 } 702 703 /** 704 * Gets the CMS context.<p> 705 * 706 * @return the CMS context 707 */ 708 CmsObject getCms() { 709 710 return m_adminCms; 711 } 712 713 /** 714 * Displays the given error message.<p> 715 * 716 * @param message the message 717 * @param showForgotPassword in case the forgot password link should be shown 718 */ 719 private void displayError(String message, boolean showForgotPassword) { 720 721 displayError(message, showForgotPassword, false); 722 723 } 724 725 /** 726 * Displays the given error message.<p> 727 * 728 * @param message the message 729 * @param showForgotPassword in case the forgot password link should be shown 730 * @param showTime show the time 731 */ 732 private void displayError(String message, boolean showForgotPassword, boolean showTime) { 733 734 message = message.replace("\n", "<br />"); 735 if (showForgotPassword) { 736 message += "<br /><br /><a href=\"" 737 + getResetPasswordLink() 738 + "\">" 739 + CmsVaadinUtils.getMessageText(Messages.GUI_FORGOT_PASSWORD_0) 740 + "</a>"; 741 } 742 if (showTime) { 743 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 744 message += "<div style=\"position:absolute;right:6px;bottom:5px;\">" 745 + CmsVaadinUtils.getMessageText(Messages.GUI_TIME_1, sdf.format(new Date())) 746 + "</div>"; 747 } 748 m_ui.showLoginError(message); 749 } 750}