1 15 package org.jahia.admin.users; 16 17 import org.jahia.admin.homepages.HomePageTool; 18 import org.jahia.bin.Jahia; 19 import org.jahia.bin.JahiaAdministration; 20 import org.jahia.data.JahiaData; 21 import org.jahia.data.viewhelper.principal.PrincipalViewHelper; 22 import org.jahia.exceptions.JahiaException; 23 import org.jahia.params.ParamBean; 24 import org.jahia.registries.ServicesRegistry; 25 import org.jahia.resourcebundle.JahiaResourceBundle; 26 import org.jahia.security.license.License; 27 import org.jahia.services.fields.ContentField; 28 import org.jahia.services.homepages.JahiaHomepage; 29 import org.jahia.services.homepages.JahiaHomepageLink; 30 import org.jahia.services.homepages.JahiaHomepagesService; 31 import org.jahia.services.pages.ContentPage; 32 import org.jahia.services.pages.JahiaPageBaseService; 33 import org.jahia.services.sites.JahiaSite; 34 import org.jahia.services.usermanager.*; 35 import org.jahia.services.version.EntryLoadRequest; 36 import org.jahia.utils.JahiaTools; 37 import org.jahia.utils.LanguageCodeConverters; 38 39 import javax.servlet.ServletException ; 40 import javax.servlet.http.HttpServletRequest ; 41 import javax.servlet.http.HttpServletResponse ; 42 import javax.servlet.http.HttpSession ; 43 import java.io.IOException ; 44 import java.util.*; 45 46 58 public class ManageUsers 59 { 60 public static final String REQUEST_KEY_PREFIX = "manage-user-"; 61 public static final String REQUEST_PASSWORD_KEY = REQUEST_KEY_PREFIX + "password"; 62 public static final String REQUEST_PASSWORD_CONFIRMATION_KEY = 63 REQUEST_KEY_PREFIX + "passwordConfirmation"; 64 65 public static final String SEPARATOR = "#"; 66 public static final String USER_PROPERTY_PREFIX = REQUEST_KEY_PREFIX + "property" + SEPARATOR; 67 68 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 69 70 private static JahiaUserManagerService uMgr; 71 private static JahiaGroupManagerService gMgr; 72 73 private JahiaSite jahiaSite; 74 75 private HomePageTool homePageTool = null; 76 77 ParamBean jParams; 78 79 private String userMessage = ""; 80 81 private License coreLicense; 82 83 private static boolean isSuperAdminProp; 86 87 96 public ManageUsers( HttpServletRequest request, 97 HttpServletResponse response, 98 HttpSession session ) 99 throws Throwable 100 { 101 ServicesRegistry sReg = ServicesRegistry.getInstance(); 103 if (sReg != null) { 104 uMgr = sReg.getJahiaUserManagerService(); 105 gMgr = sReg.getJahiaGroupManagerService(); 106 } 107 108 jahiaSite = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); 110 111 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 112 this.jParams = jData.params(); 113 114 coreLicense = Jahia.getCoreLicense(); 115 if ( coreLicense == null ){ 116 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.invalidLicenseKey.label", 118 jParams, jParams.getLocale()); 119 request.setAttribute("jahiaDisplayMessage", dspMsg); 120 doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); 122 return; 123 } 124 125 userRequestDispatcher( request, response, session ); 127 } 128 129 134 public ManageUsers() 135 throws Throwable 136 { 137 ServicesRegistry sReg = ServicesRegistry.getInstance(); 138 if (sReg != null) { 139 uMgr = sReg.getJahiaUserManagerService(); 140 gMgr = sReg.getJahiaGroupManagerService(); 141 } 142 } 143 144 153 private void userRequestDispatcher( HttpServletRequest request, 154 HttpServletResponse response, 155 HttpSession session ) 156 throws Throwable 157 { 158 String operation = request.getParameter("sub"); 159 160 if (operation.equals("display")) { 161 displayUsers(request, response, session); 162 } else if (operation.equals("search")) { 163 displayUsers(request, response, session); 164 } else if (operation.equals("create")) { 165 displayUserCreate(request, response, session); 166 } else if (operation.equals("edit")) { 167 isSuperAdminProp = false; 168 displayUserEdit(request, response, session); 169 } else if (operation.equals("superAdminProps")) { 170 isSuperAdminProp = true; 171 displayUserEdit(request, response, session); 172 } else if (operation.equals("remove")) { 173 displayUserRemove(request, response, session); 174 } else if (operation.equals("processCreate")) { 175 if (processUserCreate(request, response, session)) { 176 displayUsers(request, response, session); 177 } else { 178 displayUserCreate(request, response, session); 179 } 180 } else if (operation.equals("processEdit")) { 181 if (processUserEdit(request, response, session)) { 182 if (isSuperAdminProp) { 183 JahiaAdministration.displayMenu(request, response, session); 184 } else { 185 displayUsers(request, response, session); 186 } 187 } else { 188 displayUserEdit(request, response, session); 189 } 190 } else if (operation.equals("processRemove")) { 191 processUserRemove(request, response, session); 192 } else if (operation.equals("homepage")) { 193 processHomePage(request, response, session); 194 } 195 } 196 197 198 210 private void doRedirect( HttpServletRequest request, 211 HttpServletResponse response, 212 HttpSession session, 213 String target ) 214 throws IOException , ServletException 215 { 216 try { 217 request.setAttribute("jahiaSite",jahiaSite); 218 219 if ( request.getAttribute("warningMsg") == null ) { 221 request.setAttribute("warningMsg", ""); 222 } 223 224 if ( request.getAttribute("msg") == null ) { 226 request.setAttribute("msg", 227 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 228 jParams, jParams.getLocale())); 229 } 230 231 if ( request.getAttribute("title") == null ) { 233 request.setAttribute("title", "Manage Users"); 234 } 235 236 JahiaAdministration.doRedirect(request, response, session, target); 238 239 } catch (IOException ie) { 240 logger.error("Error ", ie); 241 } catch (ServletException se) { 242 logger.error("Error ", se); 243 if (se.getRootCause() != null) { 244 logger.error("Error root cause", se.getRootCause()); 245 } 246 } 247 } 248 249 259 private void displayUsers(HttpServletRequest request, 260 HttpServletResponse response, 261 HttpSession session) 262 throws IOException , ServletException , JahiaException 263 { 264 request.setAttribute("providerList", uMgr.getProviderList()); 265 Set userSet = PrincipalViewHelper.getSearchResult(request, jahiaSite.getID()); 266 userSet = PrincipalViewHelper.removeJahiaAdministrators(userSet); 267 request.setAttribute("resultList", userSet); 268 request.setAttribute("currentSite", jahiaSite.getServerName()); 269 request.setAttribute("jspSource", JSP_PATH + "user_management/user_management.jsp"); 270 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 271 request.setAttribute("userSearch", JSP_PATH + "user_management/user_search.jsp"); 272 session.setAttribute("jahiaDisplayMessage", 273 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 274 jParams, jParams.getLocale())); 275 session.setAttribute("userMessage", userMessage); 276 session.setAttribute("homePageID", null); 278 session.setAttribute("homePageLabel", null); 279 doRedirect(request, response, session, JSP_PATH + "admin.jsp"); 280 userMessage = ""; 281 } 282 283 293 private void displayUserCreate(HttpServletRequest request, 294 HttpServletResponse response, 295 HttpSession session) 296 throws IOException , ServletException , JahiaException 297 { 298 logger.debug("Started"); 299 int nbUserSite = ServicesRegistry.getInstance().getJahiaUserManagerService().getNbUsers(); 301 int nbUserLic = Jahia.getUserLimit(); 302 303 if (!(nbUserLic == -1 || nbUserLic >= nbUserSite)) { 304 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.licenseLimited.label", 305 jParams, jParams.getLocale()); 306 userMessage += " " + nbUserLic + " "; 307 userMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.users.label", 308 jParams, jParams.getLocale()); 309 displayUsers(request, response, session); 310 return; 311 } 312 Map userProperties = new HashMap(); 313 userProperties.put("username", JahiaTools.nnString(request.getParameter("username"))); 314 userProperties.put("passwd", JahiaTools.nnString(request.getParameter("passwd"))); 315 userProperties.put("passwdconfirm", JahiaTools.nnString(request.getParameter("passwdconfirm"))); 316 317 Enumeration names = jParams.getRequest ().getParameterNames (); 322 if (names != null) { 323 while (names.hasMoreElements ()) { 324 String name = (String ) names.nextElement (); 325 if (name != null && name.startsWith (USER_PROPERTY_PREFIX)) { 326 String newValue = jParams.getRequest ().getParameter (name); 327 int index = name.indexOf (SEPARATOR); 328 String key = name.substring (index + 1); 329 String currentValue = (String ) userProperties.get(key); 330 if (newValue == null) { 331 continue; 332 } 333 if (currentValue == null) { 334 userProperties.put (key, newValue); 335 } else if (!currentValue.equals (newValue)) { 336 userProperties.put (key, currentValue); 337 } 338 } 339 } 340 } 341 342 JahiaHomepagesService hpServ = ServicesRegistry.getInstance().getJahiaHomepagesService(); 344 JahiaHomepage homePage = hpServ.getHomepage(jahiaSite.getUserDefaultHomepageDef()); 345 if (homePage != null) { 346 JahiaHomepageLink homePageLink = (JahiaHomepageLink)homePage; 347 session.setAttribute("homePageID", new Integer (homePageLink.getPageID())); 348 ContentPage contentPage = JahiaPageBaseService.getInstance(). 349 lookupContentPage(homePageLink.getPageID(),jParams.getEntryLoadRequest(),false); 350 request.setAttribute("defaultHomePage", contentPage.getTitle(jParams.getEntryLoadRequest()) + 351 " (" + homePage.getName() + ")"); 352 } 353 354 request.setAttribute("userProperties", userProperties); 356 session.setAttribute("userMessage", userMessage); 357 if (session.getAttribute("homePageLabel") == null) { 358 String homePageLabelValue = 361 JahiaResourceBundle.getAdminResource("org.jahia.admin.none.label", 362 jParams, jParams.getLocale()); 363 session.setAttribute("homePageLabel", homePageLabelValue); 364 } 365 request.setAttribute("jspSource", JSP_PATH + "user_management/user_create.jsp"); 366 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 367 session.setAttribute("jahiaDisplayMessage", 368 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 369 jParams, jParams.getLocale())); 370 doRedirect(request, response, session, JSP_PATH + "admin.jsp"); 371 userMessage = ""; 372 } 373 374 389 private boolean processUserCreate(HttpServletRequest request, 390 HttpServletResponse response, 391 HttpSession session) 392 throws IOException , ServletException , JahiaException 393 { 394 if (!"save".equals(request.getParameter("actionType"))) { 396 return false; 399 } 400 String username = request.getParameter("username").trim(); 401 if (username.length() == 0) { 402 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.specifyUserName.label", 403 jParams, jParams.getLocale()); 404 return false; 405 } 406 else if (!JahiaTools.isAlphaValid(username)) { 409 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.onlyLettersDigitsUnderscores.label", 410 jParams, jParams.getLocale()); 411 return false; 412 } 413 else if (uMgr.userExists(jahiaSite.getID(), username)) { 414 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.user.label", 415 jParams, jParams.getLocale()); 416 userMessage += " [" + username + "] "; 417 userMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.alreadyExist.label", 418 jParams, jParams.getLocale()); 419 return false; 420 } 421 String passwd = request.getParameter("passwd").trim(); 422 if ("".equals(passwd)) { 423 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.passwdLeast6Chars.label", 424 jParams, jParams.getLocale()); 425 return false; 426 } else { 427 String passwdConfirm = request.getParameter("passwdconfirm").trim(); 428 if (!passwdConfirm.equals(passwd)) { 429 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.passwdNotMatch.label", 430 jParams, jParams.getLocale()); 431 return false; 432 } else if (passwd.length() < 6) { 433 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.passwdLeast6Chars.label", 434 jParams, jParams.getLocale()); 435 return false; 436 } 437 } 438 Properties userProps = new Properties(); 439 440 Enumeration names = jParams.getRequest ().getParameterNames (); 441 if (names != null) { 442 while (names.hasMoreElements ()) { 443 String name = (String ) names.nextElement (); 444 if (name != null && name.startsWith (USER_PROPERTY_PREFIX)) { 445 String newValue = jParams.getRequest ().getParameter (name); 446 int index = name.indexOf (SEPARATOR); 447 String key = name.substring (index + 1); 448 String currentValue = (String ) userProps.get(key); 449 if (newValue == null) { 450 continue; 451 } 452 if (currentValue == null) { 453 userProps.put (key, newValue); 454 } else if (!currentValue.equals (newValue)) { 455 userProps.put (key, currentValue); 456 } 457 } 458 } 459 } 460 461 JahiaUser usr = uMgr.createUser(username, passwd, username + ":" + jahiaSite.getID(), jahiaSite.getID(), userProps); 462 if (usr == null) { 463 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.unableCreateUser.label", 464 jParams, jParams.getLocale()); 465 userMessage += " " + username; 466 return false; 467 } else { 468 JahiaSiteUserManagerService siteUserManager = 469 ServicesRegistry.getInstance().getJahiaSiteUserManagerService(); 470 siteUserManager.addMember(jahiaSite.getID(), usr); 471 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.user.label", 472 jParams, jParams.getLocale()); 473 userMessage += " [" + username + "] "; 474 userMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.created.label", 475 jParams, jParams.getLocale()); 476 } 477 478 if (request.getParameter("setHomePage") != null) { 480 Integer homePageIDInt = (Integer )session.getAttribute("homePageID"); 481 if (homePageIDInt != null) { 482 int homePageID = homePageIDInt.intValue(); 483 logger.debug("Process Home Page ID : " + homePageID); 484 usr.setHomepageID(homePageID); 485 } 486 } 487 Integer homePageIDInt = (Integer )session.getAttribute("homePageID"); 489 if (homePageIDInt != null) { 490 int homePageID = homePageIDInt.intValue(); 491 if (homePageID != -1) { 492 logger.debug("Process Home Page ID : " + homePageID); 493 usr.setHomepageID(homePageID); 494 } else { 495 usr.removeProperty("user_homepage"); 497 } 498 session.removeAttribute("homePageID"); 499 session.removeAttribute("homePageLabel"); 500 } 501 return true; 502 } 503 504 514 private void displayUserEdit(HttpServletRequest request, 515 HttpServletResponse response, 516 HttpSession session) 517 throws IOException , ServletException , JahiaException 518 { 519 logger.debug("Started"); 520 String userToEdit; 521 JahiaUser theUser; 522 if (isSuperAdminProp) { 523 userToEdit = (String )session.getAttribute(JahiaAdministration.CLASS_NAME + "jahiaLoginUsername"); 524 theUser = (JahiaUser)uMgr.lookupUser(0, userToEdit); 525 request.setAttribute("isSuperAdminProp", ""); 527 } else { 528 userToEdit = (String )request.getParameter("selectedUsers"); 529 if (userToEdit == null) { userToEdit = (String )session.getAttribute("selectedUsers"); 531 } 532 if (userToEdit == null || "null".equals(userToEdit)) { 533 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.selectUser.label", 534 jParams, jParams.getLocale()); 535 displayUsers(request, response, session); 536 return; 537 } 538 session.setAttribute("selectedUsers", userToEdit); 540 userToEdit = JahiaTools.replacePattern(userToEdit, " ", " "); 541 theUser = (JahiaUser)uMgr.lookupUser(userToEdit.substring(1)); 542 } 543 request.setAttribute("theUser", theUser); 544 545 Set groups = (HashSet)getGroups(theUser, jahiaSite.getID()); 546 request.setAttribute("groups", groups); 548 549 UserProperties userProperties = (UserProperties) theUser.getUserProperties().clone(); 550 Enumeration names = jParams.getRequest ().getParameterNames (); 553 if (names != null) { 554 while (names.hasMoreElements ()) { 555 String name = (String ) names.nextElement (); 556 if (name != null && name.startsWith (USER_PROPERTY_PREFIX)) { 557 String newValue = jParams.getRequest ().getParameter (name); 558 int index = name.indexOf (SEPARATOR); 559 String key = name.substring (index + 1); 560 UserProperty currentProp = userProperties.getUserProperty (key); 561 if (newValue == null) { 562 continue; 563 } 564 if (currentProp == null) { 565 currentProp = new UserProperty(name, newValue, false); 566 userProperties.setUserProperty (key, currentProp); 567 } else if (!currentProp.getValue().equals (newValue)) { 568 if (!currentProp.isReadOnly()) { 570 currentProp.setValue(newValue); 571 userProperties.setUserProperty(key, currentProp); 572 } 573 } 574 } 575 } 576 } 577 578 request.setAttribute("passwd", ""); 579 request.setAttribute("passwdconfirm", ""); 580 request.setAttribute("userProperties", userProperties); 581 582 if (session.getAttribute("homePageLabel") == null) { 584 int homePageID = theUser.getHomepageID(); 585 if (homePageID != -1) { 586 592 try { 593 ArrayList locales = jahiaSite.getLanguageSettingsAsLocales(false); 594 EntryLoadRequest loadRequest = jParams.getEntryLoadRequest(); 595 if ( !locales.contains(jParams.getLocale()) ){ 596 loadRequest = EntryLoadRequest.STAGED; 597 locales.add(0,LanguageCodeConverters.languageCodeToLocale(ContentField.SHARED_LANGUAGE)); 598 loadRequest.setLocales(locales); 599 } 600 ContentPage contentPage = JahiaPageBaseService. 601 getInstance().lookupContentPage(homePageID,loadRequest,false); 602 session.setAttribute("homePageLabel", contentPage.getTitle(loadRequest)); 603 session.setAttribute("homePageID", new Integer (homePageID)); 604 } catch (JahiaException je) { 605 logger.error("Error ", je); 606 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.pageProblem.label", 607 jParams, jParams.getLocale()); 608 session.setAttribute("homePageLabel", "Disapeared !"); 609 } 610 } else { 611 String homePageLabelValue = 612 JahiaResourceBundle.getAdminResource("org.jahia.admin.none.label", 613 jParams, jParams.getLocale()); 614 session.setAttribute("homePageLabel", homePageLabelValue); 615 } 616 } 617 request.setAttribute("jspSource", JSP_PATH + "user_management/user_edit.jsp"); 618 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 619 session.setAttribute("jahiaDisplayMessage", 620 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 621 jParams, jParams.getLocale())); 622 session.setAttribute("userMessage", userMessage); 623 doRedirect(request, response, session, JSP_PATH + "admin.jsp"); 624 userMessage = ""; 625 } 626 627 642 private boolean processUserEdit(HttpServletRequest request, 643 HttpServletResponse response, 644 HttpSession session) 645 throws IOException , ServletException , JahiaException 646 { 647 logger.debug("Started"); 648 String username = request.getParameter("username"); 650 JahiaUser usr; 651 final JahiaSiteUserManagerService jahiaSiteUserManagerService = ServicesRegistry.getInstance().getJahiaSiteUserManagerService(); 652 if (isSuperAdminProp) { 653 usr = (JahiaUser)uMgr.lookupUser(0, username); 654 } else { 655 usr = jahiaSiteUserManagerService.getMember(jahiaSite.getID(), username); 656 } 657 logger.debug("Update user : " + usr.getUserKey()); 658 659 if ("update".equals(request.getParameter("actionType").trim())) { 661 return false; 662 } 663 String passwd = request.getParameter("passwd"); 664 if (passwd != null) { 666 passwd = passwd.trim(); 667 if (!"".equals(passwd)) { 668 String passwdConfirm = request.getParameter("passwdconfirm"). 669 trim(); 670 if (!passwdConfirm.equals(passwd)) { 671 userMessage = JahiaResourceBundle.getAdminResource( 672 "org.jahia.admin.userMessage.passwdNotMatch.label", 673 jParams, jParams.getLocale()); 674 return false; 675 } else if (passwd.length() < 6) { 676 userMessage = JahiaResourceBundle.getAdminResource( 677 "org.jahia.admin.userMessage.passwdLeast6Chars.label", 678 jParams, jParams.getLocale()); 679 return false; 680 } 681 } 682 if (!"".equals(passwd) && !usr.setPassword(passwd)) { 683 userMessage = JahiaResourceBundle.getAdminResource( 684 "org.jahia.admin.userMessage.cannotChangePasswd.label", 685 jParams, jParams.getLocale()); 686 userMessage += " [" + username + "] "; 687 return false; 688 } 689 } 690 Enumeration names = jParams.getRequest().getParameterNames(); 693 if (names != null) { 694 while (names.hasMoreElements()) { 695 String name = (String ) names.nextElement(); 696 if (name != null && name.startsWith(USER_PROPERTY_PREFIX)) { 697 String newValue = jParams.getRequest().getParameter(name); 698 int index = name.indexOf(SEPARATOR); 699 String key = name.substring(index + 1); 700 UserProperty currentProp = usr.getUserProperty(key); 701 if (newValue == null) { 702 continue; 703 } 704 if (currentProp == null) { 705 usr.setProperty(key, newValue); 706 } else if (!currentProp.getValue().equals(newValue)) { 707 if (!currentProp.isReadOnly()) { 709 usr.setProperty(key, newValue); 710 } 711 } 712 } 713 } 714 } 715 716 Integer homePageIDInt = (Integer )session.getAttribute("homePageID"); 718 if (homePageIDInt != null) { 719 int homePageID = homePageIDInt.intValue(); 720 if (homePageID != -1) { 721 logger.debug("Process Home Page ID : " + homePageID); 722 usr.setHomepageID(homePageID); 723 } else { 724 usr.removeProperty("user_homepage"); 726 } 727 session.removeAttribute("homePageID"); 728 session.removeAttribute("homePageLabel"); 729 } 730 jahiaSiteUserManagerService.refreshUser(jahiaSite.getID(),username); 731 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.user.label", 732 jParams, jParams.getLocale()); 733 userMessage += " [" + username + "] "; 734 userMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.updated.label", 735 jParams, jParams.getLocale()); 736 return true; 737 } 738 739 private Set getGroups(JahiaUser usr, int site) { 740 Set groups = new HashSet(); 741 JahiaGroupManagerService jahiaGroupManagerService = ServicesRegistry.getInstance().getJahiaGroupManagerService(); 742 Vector v = jahiaGroupManagerService.getUserMembership(usr); 743 Enumeration en = v.elements(); 744 while (en.hasMoreElements()) { 745 String gname = (String ) en.nextElement(); 746 JahiaGroup g = jahiaGroupManagerService.lookupGroup(gname); 747 if (g != null && (g.getSiteID() == site || g.getSiteID() ==0)) { 748 groups.add(g); 749 } 750 } 751 return groups; 752 } 753 754 765 private void displayUserRemove(HttpServletRequest request, 766 HttpServletResponse response, 767 HttpSession session) 768 throws IOException , ServletException , JahiaException { 769 770 logger.debug("Started"); 771 String selectedUsers = request.getParameter("selectedUsers"); 772 selectedUsers = JahiaTools.replacePattern(selectedUsers, " ", " "); 773 if (selectedUsers == null || "null".equals(selectedUsers)) { 774 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.selectUser.label", 775 jParams, jParams.getLocale()); 776 displayUsers(request, response, session); 777 } else { 778 request.setAttribute("selectedUsers", selectedUsers); 780 session.setAttribute("userMessage", userMessage); 781 request.setAttribute("jspSource", JSP_PATH + "user_management/user_remove.jsp"); 782 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 783 session.setAttribute("jahiaDisplayMessage", 784 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 785 jParams, jParams.getLocale())); 786 doRedirect(request, response, session, JSP_PATH + "admin.jsp"); 787 userMessage = ""; 788 } 789 } 790 791 802 private void processUserRemove(HttpServletRequest request, 803 HttpServletResponse response, 804 HttpSession session) 805 throws IOException , ServletException , JahiaException 806 { 807 logger.debug("Started"); 808 809 session.setAttribute("selectedUsers", null); 810 String userName = request.getParameter("username"); 811 if (!userName.equals("guest")) { 812 try { 814 JahiaUser user = uMgr.lookupUser(jahiaSite.getID(), userName); 815 JahiaUser currentUser = (JahiaUser)session.getAttribute(ParamBean.SESSION_USER); 816 if (!user.getUserKey().equals(currentUser.getUserKey())) { 817 JahiaSiteUserManagerService siteUserManager = 818 ServicesRegistry.getInstance().getJahiaSiteUserManagerService(); 819 siteUserManager.removeMember(user); 820 uMgr.deleteUser(user); 821 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.user.label", 822 jParams, jParams.getLocale()); 823 userMessage += " [" + userName + "] "; 824 userMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.removed.label", 825 jParams, jParams.getLocale()); 826 } else { 827 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.cannotRemoveYourUser.label", 828 jParams, jParams.getLocale()); 829 } 830 } catch (Exception e) { 831 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.cannotRemoveUser.label", 832 jParams, jParams.getLocale()); 833 userMessage += " " + userName + "."; 834 } 835 } else { 836 userMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.userMessage.cannotRemoveGuest.label", 837 jParams, jParams.getLocale()); 838 } 839 displayUsers( request, response, session); 840 } 841 842 850 private void processHomePage(HttpServletRequest request, 851 HttpServletResponse response, 852 HttpSession session) 853 throws Throwable 854 { 855 if (homePageTool == null) { 856 homePageTool = new HomePageTool(request, response, session); 857 } else { 858 homePageTool.requestDispatcher(request, response, session); 859 } 860 } 861 862 private static org.apache.log4j.Logger logger = 863 org.apache.log4j.Logger.getLogger(ManageUsers.class); 864 865 } 866 | Popular Tags |