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.apps.user; 029 030import org.opencms.db.CmsUserSettings; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsUser; 033import org.opencms.main.CmsException; 034import org.opencms.main.CmsLog; 035import org.opencms.main.CmsSessionInfo; 036import org.opencms.main.OpenCms; 037import org.opencms.security.CmsRole; 038import org.opencms.security.CmsRoleViolationException; 039import org.opencms.ui.A_CmsUI; 040import org.opencms.ui.CmsCssIcon; 041import org.opencms.ui.CmsVaadinUtils; 042import org.opencms.ui.apps.Messages; 043import org.opencms.ui.apps.sessions.CmsKillSessionDialog; 044import org.opencms.ui.apps.sessions.CmsUserInfoDialog; 045import org.opencms.ui.components.CmsBasicDialog; 046import org.opencms.ui.components.CmsBasicDialog.DialogWidth; 047import org.opencms.ui.components.CmsConfirmationDialog; 048import org.opencms.ui.components.OpenCmsTheme; 049import org.opencms.ui.contextmenu.CmsContextMenu; 050import org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode; 051import org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry; 052import org.opencms.util.CmsDateUtil; 053import org.opencms.util.CmsStringUtil; 054import org.opencms.util.CmsUUID; 055 056import java.text.DateFormat; 057import java.util.ArrayList; 058import java.util.Date; 059import java.util.HashSet; 060import java.util.Iterator; 061import java.util.List; 062import java.util.Locale; 063import java.util.Set; 064 065import org.apache.commons.logging.Log; 066 067import com.vaadin.server.Resource; 068import com.vaadin.shared.MouseEventDetails.MouseButton; 069import com.vaadin.ui.Component; 070import com.vaadin.ui.Window; 071import com.vaadin.ui.themes.ValoTheme; 072import com.vaadin.v7.data.Item; 073import com.vaadin.v7.data.util.IndexedContainer; 074import com.vaadin.v7.data.util.filter.Or; 075import com.vaadin.v7.data.util.filter.SimpleStringFilter; 076import com.vaadin.v7.event.ItemClickEvent; 077import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; 078import com.vaadin.v7.ui.Table; 079import com.vaadin.v7.ui.VerticalLayout; 080 081/** 082 * Table for user.<p> 083 * 084 */ 085public class CmsUserTable extends Table implements I_CmsFilterableTable, I_CmsToggleTable { 086 087 /**Table properties. */ 088 public enum TableProperty { 089 090 /**Last login. */ 091 Created(Messages.GUI_USERMANAGEMENT_USER_DATE_CREATED_0, Long.class, Long.valueOf(0L)), 092 /**Is the user disabled? */ 093 DISABLED("", Boolean.class, Boolean.valueOf(false)), 094 /**From Other ou?. */ 095 FROMOTHEROU("", Boolean.class, Boolean.valueOf(false)), 096 /**Description. */ 097 FullName(Messages.GUI_USERMANAGEMENT_USER_NAME_0, String.class, ""), 098 /**Icon. */ 099 Icon(null, Resource.class, new CmsCssIcon("oc-icon-24-user")), 100 /**IsIndirect?. */ 101 INDIRECT("", Boolean.class, Boolean.valueOf(false)), 102 /**Last login. */ 103 LastLogin(Messages.GUI_USERMANAGEMENT_USER_LAST_LOGIN_0, Long.class, Long.valueOf(0L)), 104 /**Name. */ 105 Name(Messages.GUI_USERMANAGEMENT_USER_USER_0, String.class, ""), 106 /**Is the user new? */ 107 NEWUSER("", Boolean.class, Boolean.valueOf(false)), 108 /**OU. */ 109 OU(Messages.GUI_USERMANAGEMENT_USER_OU_0, String.class, ""), 110 /**Status. */ 111 STATUS("", Integer.class, Integer.valueOf(0)), 112 /**Full system Name. */ 113 SystemName("", String.class, ""); 114 115 /**Default value for column.*/ 116 private Object m_defaultValue; 117 118 /**Header Message key.*/ 119 private String m_headerMessage; 120 121 /**Type of column property.*/ 122 private Class<?> m_type; 123 124 /** 125 * constructor.<p> 126 * 127 * @param name Name 128 * @param type type 129 * @param defaultValue value 130 */ 131 TableProperty(String name, Class<?> type, Object defaultValue) { 132 133 m_headerMessage = name; 134 m_type = type; 135 m_defaultValue = defaultValue; 136 } 137 138 /** 139 * The default value.<p> 140 * 141 * @return the default value object 142 */ 143 Object getDefault() { 144 145 return m_defaultValue; 146 } 147 148 /** 149 * Gets the name of the property.<p> 150 * 151 * @return a name 152 */ 153 String getName() { 154 155 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(m_headerMessage)) { 156 return CmsVaadinUtils.getMessageText(m_headerMessage); 157 } 158 return ""; 159 } 160 161 /** 162 * Gets the type of property.<p> 163 * 164 * @return the type 165 */ 166 Class<?> getType() { 167 168 return m_type; 169 } 170 171 } 172 173 /** 174 *Entry to addition info dialog.<p> 175 */ 176 class EntryAddInfos implements I_CmsSimpleContextMenuEntry<Set<String>> { 177 178 /** 179 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 180 */ 181 public void executeAction(Set<String> context) { 182 183 Window window = CmsBasicDialog.prepareWindow(DialogWidth.max); 184 CmsAdditionalInfosDialog dialog = new CmsAdditionalInfosDialog( 185 m_cms, 186 new CmsUUID(context.iterator().next()), 187 window, 188 m_app); 189 window.setContent(dialog); 190 A_CmsUI.get().addWindow(window); 191 } 192 193 /** 194 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 195 */ 196 public String getTitle(Locale locale) { 197 198 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_ADDITIONAL_INFOS_MENU_0); 199 } 200 201 /** 202 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 203 */ 204 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 205 206 if (context.size() > 1) { 207 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 208 } 209 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 210 } 211 212 } 213 214 /** 215 * Menu entry to delete user.<p> 216 */ 217 class EntryDelete implements I_CmsSimpleContextMenuEntry<Set<String>> { 218 219 /** 220 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 221 */ 222 public void executeAction(final Set<String> context) { 223 224 Window window = CmsBasicDialog.prepareWindow(); 225 CmsBasicDialog dialog = null; 226 227 dialog = new CmsDeleteMultiplePrincipalDialog(m_cms, context, window, m_app); 228 229 window.setContent(dialog); 230 window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_DELETE_0)); 231 A_CmsUI.get().addWindow(window); 232 } 233 234 /** 235 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 236 */ 237 public String getTitle(Locale locale) { 238 239 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_DELETE_0); 240 } 241 242 /** 243 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 244 */ 245 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 246 247 return onlyVisibleForOU(context); 248 } 249 250 } 251 252 /** 253 * Menu entry to edit user.<p> 254 */ 255 class EntryEdit implements I_CmsSimpleContextMenuEntry<Set<String>> { 256 257 /** 258 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 259 */ 260 public void executeAction(Set<String> context) { 261 262 Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide); 263 window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_EDIT_USER_0)); 264 window.setContent(new CmsUserEditDialog(m_cms, new CmsUUID(context.iterator().next()), window, m_app)); 265 266 A_CmsUI.get().addWindow(window); 267 } 268 269 /** 270 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 271 */ 272 public String getTitle(Locale locale) { 273 274 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_EDIT_USER_0); 275 } 276 277 /** 278 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 279 */ 280 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 281 282 CmsUUID id = new CmsUUID(context.iterator().next()); 283 return CmsMenuItemVisibilityMode.activeInactive( 284 m_app.canEditUser(id) && onlyVisibleForOU(id) && (context.size() <= 1)); 285 } 286 287 } 288 289 /** 290 * Menu entry to edit groups.<p> 291 */ 292 class EntryEditGroup implements I_CmsSimpleContextMenuEntry<Set<String>> { 293 294 /** 295 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 296 */ 297 public void executeAction(Set<String> context) { 298 299 Window window = CmsBasicDialog.prepareWindow(DialogWidth.max); 300 301 window.setContent( 302 new CmsUserEditGroupsDialog(m_cms, new CmsUUID(context.iterator().next()), window, m_app)); 303 A_CmsUI.get().addWindow(window); 304 } 305 306 /** 307 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 308 */ 309 public String getTitle(Locale locale) { 310 311 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_EDIT_USERGROUP_0); 312 } 313 314 /** 315 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 316 */ 317 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 318 319 return CmsMenuItemVisibilityMode.activeInactive( 320 onlyVisibleForOU(new CmsUUID(context.iterator().next())) && (context.size() <= 1)); 321 } 322 323 } 324 325 /** 326 * Menu entry for editing roles of user.<p> 327 */ 328 class EntryEditRole implements I_CmsSimpleContextMenuEntry<Set<String>> { 329 330 /** 331 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 332 */ 333 public void executeAction(Set<String> context) { 334 335 Window window = CmsBasicDialog.prepareWindow(DialogWidth.max); 336 337 window.setContent(new CmsUserEditRoleDialog(m_cms, new CmsUUID(context.iterator().next()), window, m_app)); 338 339 A_CmsUI.get().addWindow(window); 340 } 341 342 /** 343 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 344 */ 345 public String getTitle(Locale locale) { 346 347 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_EDIT_USERROLES_0); 348 } 349 350 /** 351 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 352 */ 353 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 354 355 return CmsMenuItemVisibilityMode.activeInactive( 356 onlyVisibleForOU(new CmsUUID(context.iterator().next())) && (context.size() <= 1)); 357 } 358 359 } 360 361 /** 362 *Entry to enable after password was entered wrong.<p> 363 */ 364 class EntryEnable implements I_CmsSimpleContextMenuEntry<Set<String>> { 365 366 /** 367 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 368 */ 369 public void executeAction(Set<String> context) { 370 371 final Window window = CmsBasicDialog.prepareWindow(); 372 try { 373 final CmsUser user = m_cms.readUser(new CmsUUID(context.iterator().next())); 374 375 CmsConfirmationDialog dialog = new CmsConfirmationDialog( 376 CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_UNLOCK_USER_LABEL_0), 377 new Runnable() { 378 379 public void run() { 380 381 OpenCms.getLoginManager().resetUserTempDisable(user.getName()); 382 window.close(); 383 m_app.reload(); 384 } 385 386 }, 387 new Runnable() { 388 389 public void run() { 390 391 window.close(); 392 393 } 394 395 }); 396 window.setCaption( 397 CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_UNLOCK_USER_CAPTION_1, user.getName())); 398 window.setContent(dialog); 399 A_CmsUI.get().addWindow(window); 400 } catch (CmsException e) { 401 LOG.error("Unable to read user", e); 402 } 403 404 } 405 406 /** 407 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 408 */ 409 public String getTitle(Locale locale) { 410 411 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_UNLOCK_USER_CONTEXT_MENU_TITLE_0); 412 } 413 414 /** 415 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 416 */ 417 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 418 419 try { 420 CmsUser user = m_cms.readUser(new CmsUUID(context.iterator().next())); 421 if (OpenCms.getLoginManager().isUserTempDisabled(user.getName())) { 422 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 423 } else { 424 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 425 } 426 427 } catch (CmsException e) { 428 LOG.error("Can not read user.", e); 429 } 430 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 431 } 432 433 } 434 435 /** 436 *Entry to info dialog.<p> 437 */ 438 class EntryInfo implements I_CmsSimpleContextMenuEntry<Set<String>>, I_CmsSimpleContextMenuEntry.I_HasCssStyles { 439 440 /** 441 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 442 */ 443 public void executeAction(Set<String> context) { 444 445 try { 446 openInfoDialog(new CmsUUID(context.iterator().next())); 447 } catch (CmsException e) { 448 LOG.error("Error on opening user info dialog", e); 449 } 450 } 451 452 /** 453 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry.I_HasCssStyles#getStyles() 454 */ 455 public String getStyles() { 456 457 return ValoTheme.LABEL_BOLD; 458 } 459 460 /** 461 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 462 */ 463 public String getTitle(Locale locale) { 464 465 return CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_SHOW_USER_0); 466 } 467 468 /** 469 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 470 */ 471 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 472 473 if (context.size() > 1) { 474 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 475 } 476 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 477 } 478 479 } 480 481 /** 482 *Entry to kill Session.<p> 483 */ 484 class EntryKillSession implements I_CmsSimpleContextMenuEntry<Set<String>> { 485 486 /** 487 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 488 */ 489 public void executeAction(Set<String> context) { 490 491 final Window window = CmsBasicDialog.prepareWindow(); 492 window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_DESTROY_SESSION_0)); 493 Set<String> sessionIds = new HashSet<String>(); 494 for (CmsSessionInfo info : OpenCms.getSessionManager().getSessionInfos( 495 new CmsUUID(context.iterator().next()))) { 496 sessionIds.add(info.getSessionId().getStringValue()); 497 } 498 CmsKillSessionDialog dialog = new CmsKillSessionDialog(sessionIds, new Runnable() { 499 500 public void run() { 501 502 window.close(); 503 } 504 }); 505 window.setContent(dialog); 506 A_CmsUI.get().addWindow(window); 507 } 508 509 /** 510 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 511 */ 512 public String getTitle(Locale locale) { 513 514 return CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_DESTROY_SESSION_0); 515 } 516 517 /** 518 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 519 */ 520 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 521 522 if (context.size() > 1) { 523 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 524 } 525 if (!OpenCms.getSessionManager().getSessionInfos(new CmsUUID(context.iterator().next())).isEmpty()) { 526 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 527 } 528 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 529 } 530 531 } 532 533 /** 534 * Menu entry to move user to another ou.<p> 535 */ 536 class EntryMoveOU implements I_CmsSimpleContextMenuEntry<Set<String>> { 537 538 /** 539 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 540 */ 541 public void executeAction(final Set<String> context) { 542 543 Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide); 544 CmsBasicDialog dialog = null; 545 546 dialog = new CmsMoveUserToOU(m_cms, new CmsUUID(context.iterator().next()), window, m_app); 547 548 window.setContent(dialog); 549 window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_MOVE_OU_0)); 550 A_CmsUI.get().addWindow(window); 551 } 552 553 /** 554 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 555 */ 556 public String getTitle(Locale locale) { 557 558 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_MOVE_OU_0); 559 } 560 561 /** 562 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 563 */ 564 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 565 566 try { 567 if (OpenCms.getOrgUnitManager().readOrganizationalUnit(m_cms, m_ou).hasFlagWebuser()) { 568 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 569 } 570 } catch (CmsException e) { 571 LOG.error("Unable to read OU", e); 572 } 573 574 return onlyVisibleForOU(context); 575 } 576 577 } 578 579 /** 580 * Menu entry to remove user from group.<p> 581 */ 582 class EntryRemoveFromGroup implements I_CmsSimpleContextMenuEntry<Set<String>> { 583 584 /** 585 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 586 */ 587 public void executeAction(final Set<String> context) { 588 589 try { 590 final Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide); 591 final String user = m_cms.readUser(new CmsUUID(context.iterator().next())).getName(); 592 String confirmText = ""; 593 String caption = ""; 594 Runnable okRunnable = null; 595 if (m_type.isGroup()) { 596 caption = CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_REMOVE_USER_FROM_GROUP_0); 597 confirmText = CmsVaadinUtils.getMessageText( 598 Messages.GUI_USERMANAGEMENT_REMOVE_USER_FROM_GROUP_CONFIRM_2, 599 user, 600 m_group); 601 okRunnable = new Runnable() { 602 603 public void run() { 604 605 try { 606 m_cms.removeUserFromGroup(user, m_group); 607 } catch (CmsException e) { 608 // 609 } 610 window.close(); 611 m_app.reload(); 612 } 613 }; 614 } 615 if (m_type.equals(CmsOuTreeType.ROLE)) { 616 caption = CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_REMOVE_USER_FROM_ROLE_0); 617 confirmText = CmsVaadinUtils.getMessageText( 618 Messages.GUI_USERMANAGEMENT_REMOVE_USER_FROM_ROLE_CONFIRM_2, 619 user, 620 m_group); 621 okRunnable = new Runnable() { 622 623 public void run() { 624 625 try { 626 OpenCms.getRoleManager().removeUserFromRole( 627 m_cms, 628 CmsRole.valueOfRoleName(m_group), 629 user); 630 631 } catch (CmsException e) { 632 // 633 } 634 window.close(); 635 m_app.reload(); 636 } 637 }; 638 } 639 640 window.setCaption(caption); 641 window.setContent(new CmsConfirmationDialog(confirmText, okRunnable, new Runnable() { 642 643 public void run() { 644 645 window.close(); 646 } 647 })); 648 649 A_CmsUI.get().addWindow(window); 650 } catch (CmsException e) { 651 // 652 } 653 } 654 655 /** 656 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 657 */ 658 public String getTitle(Locale locale) { 659 660 if (m_type.isGroup()) { 661 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_REMOVE_USER_FROM_GROUP_0); 662 } 663 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_REMOVE_USER_FROM_ROLE_0); 664 } 665 666 /** 667 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 668 */ 669 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 670 671 if (!m_app.canRemoveGroupMemebers(m_group)) { 672 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 673 } 674 675 if (context.size() > 1) { 676 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 677 } 678 if (m_group == null) { 679 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 680 } 681 682 try { 683 CmsUser user = m_cms.readUser(context.iterator().next()); 684 return ((Boolean)(getItem(user).getItemProperty(TableProperty.INDIRECT).getValue())).booleanValue() 685 ? CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE 686 : CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 687 } catch (CmsException e) { 688 // 689 } 690 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 691 } 692 693 } 694 695 /** 696 * Menu entry for show resources of user.<p> 697 */ 698 class EntryShowResources implements I_CmsSimpleContextMenuEntry<Set<String>> { 699 700 /** 701 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 702 */ 703 public void executeAction(Set<String> context) { 704 705 Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide); 706 window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_SHOW_RESOURCES_0)); 707 window.setContent(new CmsShowResourcesDialog(context.iterator().next(), window)); 708 709 A_CmsUI.get().addWindow(window); 710 } 711 712 /** 713 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 714 */ 715 public String getTitle(Locale locale) { 716 717 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_SHOW_RESOURCES_0); 718 } 719 720 /** 721 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 722 */ 723 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 724 725 if (context.size() > 1) { 726 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 727 } 728 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 729 } 730 731 } 732 733 /** 734 *Entry to switch user.<p> 735 */ 736 class EntrySwitchUser implements I_CmsSimpleContextMenuEntry<Set<String>> { 737 738 /** 739 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object) 740 */ 741 public void executeAction(Set<String> context) { 742 743 final Window window = CmsBasicDialog.prepareWindow(); 744 final CmsUUID userID = new CmsUUID(context.iterator().next()); 745 window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_SWITCH_USER_0)); 746 CmsConfirmationDialog dialog = new CmsConfirmationDialog( 747 CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_SWITCH_USER_CONFIRM_0), 748 new Runnable() { 749 750 public void run() { 751 752 try { 753 String path = OpenCms.getSessionManager().switchUser( 754 A_CmsUI.getCmsObject(), 755 CmsVaadinUtils.getRequest(), 756 m_cms.readUser(userID)); 757 if (path == null) { 758 path = CmsVaadinUtils.getWorkplaceLink() + "?_lrid=" + (new Date()).getTime(); 759 } 760 761 A_CmsUI.get().getPage().setLocation(path); 762 if (path.contains("workplace#")) { 763 A_CmsUI.get().getPage().reload(); 764 } 765 window.close(); 766 } catch (CmsException e) { 767 LOG.error("Unable to swith user", e); 768 } 769 } 770 }, 771 new Runnable() { 772 773 public void run() { 774 775 window.close(); 776 } 777 }); 778 window.setContent(dialog); 779 A_CmsUI.get().addWindow(window); 780 } 781 782 /** 783 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale) 784 */ 785 public String getTitle(Locale locale) { 786 787 return CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_SWITCH_USER_0); 788 } 789 790 /** 791 * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object) 792 */ 793 public CmsMenuItemVisibilityMode getVisibility(Set<String> context) { 794 795 try { 796 OpenCms.getRoleManager().checkRole(m_cms, CmsRole.ADMINISTRATOR); 797 return CmsMenuItemVisibilityMode.activeInactive( 798 onlyVisibleForOU(new CmsUUID(context.iterator().next())) && (context.size() <= 1)); 799 } catch (CmsRoleViolationException e) { 800 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 801 } 802 803 } 804 805 } 806 807 /** Log instance for this class. */ 808 static final Log LOG = CmsLog.getLog(CmsUserTable.class); 809 810 /**vaadin serial id.*/ 811 private static final long serialVersionUID = 7863356514060544048L; 812 813 /**Name of group to show user for, or null. */ 814 protected String m_group; 815 816 /**Type to be shown. */ 817 protected I_CmsOuTreeType m_type; 818 819 /**The app.*/ 820 CmsAccountsApp m_app; 821 822 /**CmsObject.*/ 823 CmsObject m_cms; 824 825 /**List of indirect user. */ 826 List<CmsUser> m_indirects; 827 828 /** The context menu. */ 829 CmsContextMenu m_menu; 830 831 /**OU. */ 832 String m_ou; 833 834 /**Black list of user from higher OU than current user.*/ 835 private HashSet<CmsUser> m_blackList = new HashSet<CmsUser>(); 836 837 /**Indexed container. */ 838 private IndexedContainer m_container; 839 840 /**vaadin component.*/ 841 private VerticalLayout m_emptyLayout; 842 843 /**flag indicates if all indirect items (for roles or sub OUs) are loaded. */ 844 private boolean m_fullyLoaded; 845 846 /** The available menu entries. */ 847 private List<I_CmsSimpleContextMenuEntry<Set<String>>> m_menuEntries; 848 849 /**List of user. */ 850 private List<CmsUser> m_users; 851 852 /** 853 * puiblic constructor.<p> 854 * 855 * @param ou ou name 856 * @param groupID id of group 857 * @param cmsOuTreeType type to be shown 858 * @param showAll show all user including inherited? 859 * @param app the app 860 */ 861 public CmsUserTable( 862 String ou, 863 CmsUUID groupID, 864 I_CmsOuTreeType cmsOuTreeType, 865 boolean showAll, 866 CmsAccountsApp app) { 867 868 m_ou = ou.equals("/") ? "" : ou; 869 m_app = app; 870 871 try { 872 m_cms = getCmsObject(); 873 m_type = cmsOuTreeType; 874 875 m_indirects = new ArrayList<CmsUser>(); 876 if (m_type.isGroup()) { 877 m_group = m_cms.readGroup(groupID).getName(); 878 m_users = m_cms.getUsersOfGroup(m_group, true); 879 m_fullyLoaded = true; 880 } 881 if (m_type.isRole()) { 882 m_group = CmsRole.valueOfId(groupID).forOrgUnit(ou).getFqn(); 883 List<CmsUser> directs = OpenCms.getRoleManager().getUsersOfRole( 884 m_cms, 885 CmsRole.valueOfId(groupID).forOrgUnit(ou), 886 true, 887 true); 888 if (showAll) { 889 setAllUsers(directs); 890 } else { 891 m_users = directs; 892 } 893 } 894 895 init(showAll); 896 } catch (CmsException e) { 897 LOG.error("Unable to read user", e); 898 } 899 } 900 901 /** 902 * public constructor.<p> 903 * 904 * @param ou name 905 * @param type the tree type 906 * @param app the app 907 * @param showAll boolean 908 */ 909 public CmsUserTable(String ou, I_CmsOuTreeType type, CmsAccountsApp app, boolean showAll) { 910 911 m_ou = ou.equals("/") ? "" : ou; 912 m_app = app; 913 try { 914 m_cms = getCmsObject(); 915 m_type = type; 916 List<CmsUser> directs = m_app.getUsersWithoutAdditionalInfo(m_cms, type, ou, false); 917 m_indirects = new ArrayList<CmsUser>(); 918 if (showAll) { 919 setAllUsers(directs); 920 } else { 921 m_users = directs; 922 } 923 init(showAll); 924 } catch (CmsException e) { 925 LOG.error("Unable to read user.", e); 926 } 927 } 928 929 /** 930 * @see org.opencms.ui.apps.user.I_CmsFilterableTable#filter(java.lang.String) 931 */ 932 public void filter(String data) { 933 934 m_container.removeAllContainerFilters(); 935 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(data)) { 936 m_container.addContainerFilter( 937 new Or( 938 new SimpleStringFilter(TableProperty.SystemName, data, true, false), 939 new SimpleStringFilter(TableProperty.FullName, data, true, false))); 940 } 941 942 } 943 944 /** 945 * @see org.opencms.ui.apps.user.I_CmsToggleTable#getCurrentSize() 946 */ 947 public int getCurrentSize() { 948 949 return this.size(); 950 } 951 952 /** 953 * Layout which gets displayed if table is empty. 954 * 955 * @see org.opencms.ui.apps.user.I_CmsFilterableTable#getEmptyLayout() 956 */ 957 public VerticalLayout getEmptyLayout() { 958 959 m_emptyLayout = CmsVaadinUtils.getInfoLayout(CmsOuTreeType.USER.getEmptyMessageKey()); 960 setVisible(size() > 0); 961 m_emptyLayout.setVisible(size() == 0); 962 return m_emptyLayout; 963 } 964 965 /** 966 * Gets currently visible user. 967 * 968 * @return List of user 969 */ 970 public List<CmsUser> getVisibleUser() { 971 972 if (!m_fullyLoaded) { 973 return m_users; 974 } 975 if (size() == m_users.size()) { 976 return m_users; 977 } 978 List<CmsUser> directs = new ArrayList<CmsUser>(); 979 for (CmsUser user : m_users) { 980 if (!m_indirects.contains(user)) { 981 directs.add(user); 982 } 983 } 984 return directs; 985 } 986 987 /** 988 * @see org.opencms.ui.apps.user.I_CmsToggleTable#toggle(boolean) 989 */ 990 public void toggle(boolean pressed) { 991 992 try { 993 994 if (pressed && !m_fullyLoaded) { 995 setAllUsers(m_users); 996 } 997 } catch (CmsException e) { 998 m_fullyLoaded = false; 999 LOG.error("Error loading user", e); 1000 } 1001 fillContainer(pressed); 1002 } 1003 1004 /** 1005 * Adds given user to given IndexedContainer.<p> 1006 * 1007 * @param container to add the user to 1008 * @param user to add 1009 */ 1010 protected void addUserToContainer(IndexedContainer container, CmsUser user) { 1011 1012 if (m_blackList.contains(user)) { 1013 return; 1014 } 1015 Item item = container.addItem(user); 1016 fillItem(item, user); 1017 } 1018 1019 /** 1020 * Fills the container.<p> 1021 * 1022 * @param showIndirect true-> show all user, false -> only direct user 1023 */ 1024 protected void fillContainer(boolean showIndirect) { 1025 1026 m_container.removeAllContainerFilters(); 1027 m_container.removeAllItems(); 1028 for (CmsUser user : m_users) { 1029 if (showIndirect || !m_indirects.contains(user)) { 1030 addUserToContainer(m_container, user); 1031 } 1032 } 1033 setVisibilities(); 1034 } 1035 1036 /** 1037 * Fills the container item for a user.<p> 1038 * 1039 * @param item the item 1040 * @param user the user 1041 */ 1042 protected void fillItem(Item item, CmsUser user) { 1043 1044 item.getItemProperty(TableProperty.Name).setValue(user.getSimpleName()); 1045 item.getItemProperty(TableProperty.FullName).setValue(user.getFullName()); 1046 item.getItemProperty(TableProperty.SystemName).setValue(user.getName()); 1047 boolean disabled = !user.isEnabled(); 1048 item.getItemProperty(TableProperty.DISABLED).setValue(Boolean.valueOf(disabled)); 1049 boolean newUser = user.getLastlogin() == 0L; 1050 item.getItemProperty(TableProperty.NEWUSER).setValue(Boolean.valueOf(newUser)); 1051 try { 1052 item.getItemProperty(TableProperty.OU).setValue( 1053 OpenCms.getOrgUnitManager().readOrganizationalUnit(m_cms, user.getOuFqn()).getDisplayName( 1054 A_CmsUI.get().getLocale())); 1055 } catch (CmsException e) { 1056 LOG.error("Can't read OU", e); 1057 } 1058 item.getItemProperty(TableProperty.LastLogin).setValue(Long.valueOf(user.getLastlogin())); 1059 item.getItemProperty(TableProperty.Created).setValue(Long.valueOf(user.getDateCreated())); 1060 item.getItemProperty(TableProperty.INDIRECT).setValue(Boolean.valueOf(m_indirects.contains(user))); 1061 item.getItemProperty(TableProperty.FROMOTHEROU).setValue(Boolean.valueOf(!user.getOuFqn().equals(m_ou))); 1062 item.getItemProperty(TableProperty.STATUS).setValue(getStatusInt(disabled, newUser)); 1063 } 1064 1065 /** 1066 * initializes table. 1067 * @param showAll boolean 1068 */ 1069 protected void init(boolean showAll) { 1070 1071 m_menu = new CmsContextMenu(); 1072 m_menu.setAsTableContextMenu(this); 1073 1074 m_container = new IndexedContainer(); 1075 1076 for (TableProperty prop : TableProperty.values()) { 1077 m_container.addContainerProperty(prop, prop.getType(), prop.getDefault()); 1078 setColumnHeader(prop, prop.getName()); 1079 } 1080 m_app.addUserContainerProperties(m_container); 1081 setContainerDataSource(m_container); 1082 setItemIconPropertyId(TableProperty.Icon); 1083 setRowHeaderMode(RowHeaderMode.ICON_ONLY); 1084 1085 setColumnWidth(null, 40); 1086 setColumnWidth(TableProperty.STATUS, 100); 1087 setSelectable(true); 1088 setMultiSelect(true); 1089 1090 setVisibleColumns(TableProperty.Name, TableProperty.OU); 1091 1092 fillContainer(showAll); 1093 1094 addItemClickListener(new ItemClickListener() { 1095 1096 private static final long serialVersionUID = 4807195510202231174L; 1097 1098 @SuppressWarnings("unchecked") 1099 public void itemClick(ItemClickEvent event) { 1100 1101 changeValueIfNotMultiSelect(event.getItemId()); 1102 1103 if (event.getButton().equals(MouseButton.RIGHT) || (event.getPropertyId() == null)) { 1104 Set<String> userIds = new HashSet<String>(); 1105 for (CmsUser user : (Set<CmsUser>)getValue()) { 1106 userIds.add(user.getId().getStringValue()); 1107 } 1108 1109 m_menu.setEntries(getMenuEntries(), userIds); 1110 m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsUserTable.this); 1111 } else if (event.getButton().equals(MouseButton.LEFT) 1112 && TableProperty.Name.equals(event.getPropertyId())) { 1113 CmsUser user = ((Set<CmsUser>)getValue()).iterator().next(); 1114 try { 1115 openInfoDialog(user.getId()); 1116 } catch (CmsException e) { 1117 LOG.error("Error on opening user info dialog", e); 1118 } 1119 } 1120 1121 } 1122 1123 }); 1124 setCellStyleGenerator(new CellStyleGenerator() { 1125 1126 private static final long serialVersionUID = 4685652851810828147L; 1127 1128 public String getStyle(Table source, Object itemId, Object propertyId) { 1129 1130 if (TableProperty.STATUS.equals(propertyId)) { 1131 return getStatusStyleForItem(source.getItem(itemId), (CmsUser)itemId); 1132 1133 } 1134 String css = " "; 1135 1136 if (((Boolean)(source.getItem(itemId).getItemProperty( 1137 TableProperty.FROMOTHEROU).getValue())).booleanValue()) { 1138 css += OpenCmsTheme.EXPIRED; 1139 } 1140 1141 if (TableProperty.Name.equals(propertyId)) { 1142 css += " " + OpenCmsTheme.HOVER_COLUMN; 1143 } 1144 1145 if (((Boolean)source.getItem(itemId).getItemProperty( 1146 TableProperty.INDIRECT).getValue()).booleanValue()) { 1147 return css + " " + OpenCmsTheme.TABLE_CELL_DISABLED; 1148 } 1149 return css.length() == 1 ? null : css; 1150 } 1151 1152 private String getStatusStyleForItem(Item item, CmsUser user) { 1153 1154 if (((Boolean)item.getItemProperty(TableProperty.DISABLED).getValue()).booleanValue()) { 1155 return OpenCmsTheme.TABLE_COLUMN_BOX_GRAY; 1156 } 1157 1158 if (OpenCms.getLoginManager().isUserTempDisabled(user.getName())) { 1159 return OpenCmsTheme.TABLE_COLUMN_BOX_RED; 1160 } 1161 1162 if (((Boolean)item.getItemProperty(TableProperty.NEWUSER).getValue()).booleanValue()) { 1163 return OpenCmsTheme.TABLE_COLUMN_BOX_BLUE; 1164 } 1165 1166 if (isUserPasswordReset(user)) { 1167 return OpenCmsTheme.TABLE_COLUMN_BOX_ORANGE; 1168 } 1169 1170 return OpenCmsTheme.TABLE_COLUMN_BOX_GREEN; 1171 } 1172 }); 1173 addGeneratedColumn(TableProperty.STATUS, new ColumnGenerator() { 1174 1175 private static final long serialVersionUID = -2144476865774782965L; 1176 1177 public Object generateCell(Table source, Object itemId, Object columnId) { 1178 1179 return getStatus( 1180 (CmsUser)itemId, 1181 ((Boolean)source.getItem(itemId).getItemProperty(TableProperty.DISABLED).getValue()).booleanValue(), 1182 ((Boolean)source.getItem(itemId).getItemProperty(TableProperty.NEWUSER).getValue()).booleanValue()); 1183 1184 } 1185 1186 }); 1187 addGeneratedColumn(TableProperty.LastLogin, new ColumnGenerator() { 1188 1189 private static final long serialVersionUID = -6781906011584975559L; 1190 1191 public Object generateCell(Table source, Object itemId, Object columnId) { 1192 1193 long lastLogin = ((Long)source.getItem(itemId).getItemProperty( 1194 TableProperty.LastLogin).getValue()).longValue(); 1195 return lastLogin == 0L 1196 ? CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_NEVER_LOGGED_IN_0) 1197 : CmsDateUtil.getDateTime(new Date(lastLogin), DateFormat.SHORT, A_CmsUI.get().getLocale()); 1198 1199 } 1200 1201 }); 1202 1203 addGeneratedColumn(TableProperty.Created, new ColumnGenerator() { 1204 1205 private static final long serialVersionUID = -6781906011584975559L; 1206 1207 public Object generateCell(Table source, Object itemId, Object columnId) { 1208 1209 long created = ((Long)source.getItem(itemId).getItemProperty( 1210 TableProperty.Created).getValue()).longValue(); 1211 return created == 0L 1212 ? "" 1213 : CmsDateUtil.getDateTime(new Date(created), DateFormat.SHORT, A_CmsUI.get().getLocale()); 1214 1215 } 1216 1217 }); 1218 1219 setItemDescriptionGenerator(new ItemDescriptionGenerator() { 1220 1221 private static final long serialVersionUID = 7367011213487089661L; 1222 1223 public String generateDescription(Component source, Object itemId, Object propertyId) { 1224 1225 if (TableProperty.STATUS.equals(propertyId)) { 1226 1227 return getStatusHelp( 1228 (CmsUser)itemId, 1229 ((Boolean)((Table)source).getItem(itemId).getItemProperty( 1230 TableProperty.DISABLED).getValue()).booleanValue(), 1231 ((Boolean)((Table)source).getItem(itemId).getItemProperty( 1232 TableProperty.NEWUSER).getValue()).booleanValue()); 1233 } 1234 return null; 1235 } 1236 }); 1237 setVisibleColumns( 1238 TableProperty.STATUS, 1239 TableProperty.Name, 1240 TableProperty.FullName, 1241 TableProperty.OU, 1242 TableProperty.LastLogin, 1243 TableProperty.Created); 1244 } 1245 1246 /** 1247 * Visibility which is only active if user is in right ou.<p> 1248 * 1249 * @param userId to be checked 1250 * @return CmsMenuItemVisibilityMode 1251 */ 1252 protected boolean onlyVisibleForOU(CmsUUID userId) { 1253 1254 try { 1255 if (m_app.isOUManagable(m_cms.readUser(userId).getOuFqn())) { 1256 return true; 1257 } 1258 } catch (CmsException e) { 1259 // 1260 } 1261 return false; 1262 } 1263 1264 /** 1265 * Checks if all selected items are editable.<p> 1266 * 1267 * @param context items 1268 * @return CmsMenuItemVisibilityMode 1269 */ 1270 protected CmsMenuItemVisibilityMode onlyVisibleForOU(Set<String> context) { 1271 1272 for (String id : context) { 1273 if (!onlyVisibleForOU(new CmsUUID(id))) { 1274 return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE; 1275 } 1276 } 1277 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 1278 } 1279 1280 /** 1281 * Opens the user info dialog.<p> 1282 * 1283 * @param id of user 1284 * @throws CmsException exception 1285 */ 1286 protected void openInfoDialog(CmsUUID id) throws CmsException { 1287 1288 CmsUserInfoDialog.showUserInfo(m_cms.readUser(id)); 1289 } 1290 1291 /** 1292 * Checks value of table and sets it new if needed:<p> 1293 * if multiselect: new itemId is in current Value? -> no change of value<p> 1294 * no multiselect and multiselect, but new item not selected before: set value to new item<p> 1295 * 1296 * @param itemId if of clicked item 1297 */ 1298 void changeValueIfNotMultiSelect(Object itemId) { 1299 1300 @SuppressWarnings("unchecked") 1301 Set<String> value = (Set<String>)getValue(); 1302 if (value == null) { 1303 select(itemId); 1304 } else if (!value.contains(itemId)) { 1305 setValue(null); 1306 select(itemId); 1307 } 1308 } 1309 1310 /** 1311 * Returns the available menu entries.<p> 1312 * 1313 * @return the menu entries 1314 */ 1315 List<I_CmsSimpleContextMenuEntry<Set<String>>> getMenuEntries() { 1316 1317 if (m_menuEntries == null) { 1318 m_menuEntries = new ArrayList<I_CmsSimpleContextMenuEntry<Set<String>>>(); 1319 m_menuEntries.add(new EntryInfo()); 1320 m_menuEntries.add(new EntryEdit()); 1321 m_menuEntries.add(new EntryEditRole()); 1322 m_menuEntries.add(new EntryEditGroup()); 1323 m_menuEntries.add(new EntryAddInfos()); 1324 m_menuEntries.add(new EntryShowResources()); 1325 m_menuEntries.add(new EntrySwitchUser()); 1326 m_menuEntries.add(new EntryRemoveFromGroup()); 1327 m_menuEntries.add(new EntryMoveOU()); 1328 m_menuEntries.add(new EntryDelete()); 1329 m_menuEntries.add(new EntryKillSession()); 1330 m_menuEntries.add(new EntryEnable()); 1331 } 1332 return m_menuEntries; 1333 } 1334 1335 /** 1336 * Returns status message. 1337 * 1338 * @param user CmsUser 1339 * @param disabled boolean 1340 * @param newUser boolean 1341 * @return String 1342 */ 1343 String getStatus(CmsUser user, boolean disabled, boolean newUser) { 1344 1345 if (disabled) { 1346 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_DISABLED_0); 1347 } 1348 if (OpenCms.getLoginManager().isUserTempDisabled(user.getName())) { 1349 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_UNLOCK_USER_STATUS_0); 1350 } 1351 if (newUser) { 1352 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_INACTIVE_0); 1353 } 1354 if (isUserPasswordReset(user)) { 1355 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_PASSWORT_RESET_0); 1356 } 1357 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_ACTIVE_0); 1358 } 1359 1360 /** 1361 * Returns status help message. 1362 * 1363 * @param user CmsUser 1364 * @param disabled boolean 1365 * @param newUser boolean 1366 * @return String 1367 */ 1368 String getStatusHelp(CmsUser user, boolean disabled, boolean newUser) { 1369 1370 if (disabled) { 1371 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_DISABLED_HELP_0); 1372 } 1373 if (newUser) { 1374 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_INACTIVE_HELP_0); 1375 } 1376 if (isUserPasswordReset(user)) { 1377 return CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_PASSWORT_RESET_HELP_0); 1378 } 1379 long lastLogin = user.getLastlogin(); 1380 return CmsVaadinUtils.getMessageText( 1381 Messages.GUI_USERMANAGEMENT_USER_ACTIVE_HELP_1, 1382 CmsDateUtil.getDateTime(new Date(lastLogin), DateFormat.SHORT, A_CmsUI.get().getLocale())); 1383 } 1384 1385 /** 1386 * Integer value for status (allows to sort column). 1387 * 1388 * @param disabled boolean 1389 * @param newUser boolean 1390 * @return Integer 1391 */ 1392 Integer getStatusInt(boolean disabled, boolean newUser) { 1393 1394 if (disabled) { 1395 return Integer.valueOf(2); 1396 } 1397 if (newUser) { 1398 return Integer.valueOf(1); 1399 } 1400 return Integer.valueOf(0); 1401 } 1402 1403 /** 1404 * Is the user password reset? 1405 * 1406 * @param user User to check 1407 * @return boolean 1408 */ 1409 boolean isUserPasswordReset(CmsUser user) { 1410 1411 Boolean cachedValue = m_app.getPasswordResetStateCache().get(user.getId()); 1412 if (cachedValue != null) { 1413 return cachedValue.booleanValue(); 1414 } 1415 CmsUser currentUser = user; 1416 if (user.getAdditionalInfo().size() < 3) { 1417 1418 try { 1419 currentUser = m_cms.readUser(user.getId()); 1420 } catch (CmsException e) { 1421 LOG.error("Can not read user", e); 1422 } 1423 } 1424 boolean result = currentUser.getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_PASSWORD_RESET) != null; 1425 m_app.getPasswordResetStateCache().put(user.getId(), Boolean.valueOf(result)); 1426 return result; 1427 } 1428 1429 /** 1430 * Gets list of indirect users to show.<p> 1431 * 1432 * @param allUsers all users 1433 * @param directUsers direct user 1434 * @return indirect user 1435 */ 1436 private List<CmsUser> getAllowedIndirects(List<CmsUser> allUsers, List<CmsUser> directUsers) { 1437 1438 List<CmsUser> res = new ArrayList<CmsUser>(); 1439 for (CmsUser u : allUsers) { 1440 if (!directUsers.contains(u)) { 1441 res.add(u); 1442 } 1443 } 1444 1445 return res; 1446 } 1447 1448 /** 1449 * Gets CmsObject.<p> 1450 * 1451 * @return cmsobject 1452 */ 1453 private CmsObject getCmsObject() { 1454 1455 CmsObject cms; 1456 try { 1457 cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject()); 1458 //m_cms.getRequestContext().setSiteRoot(""); 1459 } catch (CmsException e) { 1460 cms = A_CmsUI.getCmsObject(); 1461 } 1462 return cms; 1463 } 1464 1465 /** 1466 * Checks is it is allown for the current user to see given user.<p> 1467 * 1468 * @param user to be checked 1469 * @return boolean 1470 * @throws CmsException exception 1471 */ 1472 private boolean isAllowedUser(CmsUser user) throws CmsException { 1473 1474 if (user.getOuFqn().startsWith(m_cms.getRequestContext().getOuFqn())) { 1475 return true; 1476 } 1477 return OpenCms.getRoleManager().getRolesOfUser(m_cms, user.getName(), m_ou, true, true, false).size() > 0; 1478 } 1479 1480 /** 1481 * Sets all user, including indirect user for roles.<p> 1482 * 1483 * @param directs direct user 1484 * @throws CmsException exception 1485 */ 1486 private void setAllUsers(List<CmsUser> directs) throws CmsException { 1487 1488 m_fullyLoaded = true; 1489 if (m_type.equals(CmsOuTreeType.ROLE)) { 1490 m_users = OpenCms.getRoleManager().getUsersOfRole( 1491 m_cms, 1492 CmsRole.valueOfRoleName(m_group).forOrgUnit(m_ou), 1493 true, 1494 false); 1495 } else if (m_type.equals(CmsOuTreeType.USER)) { 1496 m_users = m_app.getUsersWithoutAdditionalInfo(m_cms, m_type, m_ou, true); 1497 1498 } 1499 Iterator<CmsUser> it = m_users.iterator(); 1500 while (it.hasNext()) { 1501 CmsUser u = it.next(); 1502 if (!isAllowedUser(u)) { 1503 m_blackList.add(u); 1504 } 1505 } 1506 m_indirects.addAll(getAllowedIndirects(m_users, directs)); 1507 } 1508 1509 /** 1510 * Sets the visibility of table and empty info panel.<p> * 1511 */ 1512 private void setVisibilities() { 1513 1514 setVisible(size() > 0); 1515 if (m_emptyLayout != null) { 1516 m_emptyLayout.setVisible(size() == 0); 1517 } 1518 } 1519}