1 15 package org.jahia.admin.users; 16 17 import java.io.IOException ; 18 import java.lang.reflect.InvocationTargetException ; 19 import java.lang.reflect.Method ; 20 import java.security.Principal ; 21 import java.util.ArrayList ; 22 import java.util.Enumeration ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import java.util.Vector ; 27 import javax.servlet.ServletException ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.http.HttpSession ; 31 32 import org.jahia.admin.homepages.HomePageTool; 33 import org.jahia.bin.JahiaAdministration; 34 import org.jahia.data.JahiaData; 35 import org.jahia.data.viewhelper.principal.PrincipalViewHelper; 36 import org.jahia.exceptions.JahiaException; 37 import org.jahia.params.ParamBean; 38 import org.jahia.registries.ServicesRegistry; 39 import org.jahia.resourcebundle.JahiaResourceBundle; 40 import org.jahia.services.fields.ContentField; 41 import org.jahia.services.homepages.JahiaHomepage; 42 import org.jahia.services.homepages.JahiaHomepageLink; 43 import org.jahia.services.homepages.JahiaHomepagesService; 44 import org.jahia.services.pages.ContentPage; 45 import org.jahia.services.pages.JahiaPageBaseService; 46 import org.jahia.services.sites.JahiaSite; 47 import org.jahia.services.sites.JahiaSitesService; 48 import org.jahia.services.usermanager.JahiaDBUser; 49 import org.jahia.services.usermanager.JahiaGroup; 50 import org.jahia.services.usermanager.JahiaGroupManagerService; 51 import org.jahia.services.usermanager.JahiaSiteGroupManagerService; 52 import org.jahia.services.usermanager.JahiaSiteUserManagerService; 53 import org.jahia.services.usermanager.JahiaUser; 54 import org.jahia.services.usermanager.JahiaUserManagerService; 55 import org.jahia.services.version.EntryLoadRequest; 56 import org.jahia.utils.JahiaTools; 57 import org.jahia.utils.LanguageCodeConverters; 58 59 72 73 public class ManageGroups 74 { 75 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 76 77 private static JahiaUserManagerService uMgr; 78 private static JahiaGroupManagerService gMgr; 79 private static JahiaSiteUserManagerService uSiteMgr; 80 private JahiaSite jahiaSite; 81 private String groupMessage = ""; 82 private static HashSet groupMembers; 84 ParamBean jParams; 85 86 private HomePageTool homePageTool = null; 87 private GroupMembersTool groupMembersTool = null; 88 89 97 public ManageGroups(HttpServletRequest request, 98 HttpServletResponse response, 99 HttpSession session) 100 throws Throwable 101 { 102 ServicesRegistry sReg = ServicesRegistry.getInstance(); 104 if (sReg != null) { 105 uMgr = sReg.getJahiaUserManagerService(); 106 gMgr = sReg.getJahiaGroupManagerService(); 107 uSiteMgr = sReg.getJahiaSiteUserManagerService(); 108 } 109 jahiaSite = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); 111 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 112 this.jParams = jData.params(); 113 114 if (jahiaSite == null) { 115 JahiaSitesService sitesService = sReg.getJahiaSitesService(); 116 jahiaSite = sitesService.getSite(0); 117 session.setAttribute( ParamBean.SESSION_SITE, jahiaSite ); 118 } 119 userRequestDispatcher( request, response, session ); 120 } 122 123 124 132 private void userRequestDispatcher( HttpServletRequest request, 133 HttpServletResponse response, 134 HttpSession session ) 135 throws Throwable 136 { 137 String operation = request.getParameter("sub"); 138 139 if (operation.equals("display")) { 140 displayGroupList(request, response, session ); 141 } else if (operation.equals("search")) { 142 displayGroupList(request, response, session); 143 } else if (operation.equals("create")) { 144 displayGroupCreate( request, response, session); 145 } else if (operation.equals("edit")) { 146 displayGroupEdit(request, response, session); 147 } else if (operation.equals("membership")) { 148 displayGroupMembership( request, response, session ); 149 } else if (operation.equals("copy")) { 150 displayGroupCopy(request, response, session); 151 } else if (operation.equals("remove")) { 152 displayGroupRemove(request, response, session); 153 } else if (operation.equals("processCreate")) { 154 if (processGroupCreate(request, response, session)) { 155 displayGroupList(request, response, session); 156 } else { 157 displayGroupCreate(request, response, session); 158 } 159 } else if (operation.equals("processEdit")) { 160 if (processGroupEdit(request, response, session)) { 161 displayGroupList(request, response, session); 162 } else { 163 displayGroupEdit(request, response, session); 164 } 165 } else if (operation.equals("processRemove")) { 166 processGroupRemove(request, response, session); 167 } else if (operation.equals("processCopy")) { 168 if (processGroupCopy(request, response, session)) { 169 displayGroupList(request, response, session); 170 } else { 171 displayGroupCopy(request, response, session); 172 } 173 } else if (operation.equals("homepage")) { 174 processHomePage(request, response, session); 175 } else if (operation.equals("groupmembers")) { 176 processGroupMembers(request, response, session); 177 } 178 } 179 180 192 private void doRedirect( HttpServletRequest request, 193 HttpServletResponse response, 194 HttpSession session, 195 String target ) 196 throws IOException , ServletException 197 { 198 try 199 { 200 request.setAttribute("currentSiteBean",jahiaSite); 201 202 if( request.getAttribute("warningMsg") == null ) { 204 request.setAttribute("warningMsg", ""); 205 } 206 207 if( request.getAttribute("msg") == null ) { 209 request.setAttribute("msg", 210 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 211 jParams, jParams.getLocale())); 212 } 213 214 if( request.getAttribute("focus") == null ) { 215 request.setAttribute("focus", "-none-"); 216 } 217 218 if( request.getAttribute("title") == null ) { 220 request.setAttribute("title", "Manage Groups"); 221 } 222 223 String userAgent = request.getHeader("user-agent"); 225 226 JahiaAdministration.doRedirect( request, response, session, target ); 228 229 } catch (IOException ie) { 230 logger.error("Error ", ie); 231 } catch (ServletException se) { 232 logger.error("Error ", se); 233 if (se.getRootCause() != null) { 234 logger.error("Error root cause", se.getRootCause()); 235 } 236 } 237 } 238 239 248 private void displayGroupList( HttpServletRequest request, 249 HttpServletResponse response, 250 HttpSession session ) 251 throws IOException , ServletException 252 { 253 request.setAttribute("providerList", gMgr.getProviderList()); 255 request.setAttribute("resultList", PrincipalViewHelper.getGroupSearchResult(request, jahiaSite.getID())); 256 request.setAttribute("currentSite", jahiaSite.getServerName()); 257 request.setAttribute("jspSource", JSP_PATH + "group_management/group_management.jsp"); 258 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 259 request.setAttribute("groupSearch", JSP_PATH + "group_management/group_search.jsp"); 260 session.setAttribute("jahiaDisplayMessage", 261 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 262 jParams, jParams.getLocale())); 263 session.setAttribute("groupMessage", groupMessage); 264 session.setAttribute("homePageID", null); 266 session.setAttribute("homePageLabel", null); 267 doRedirect(request, response, session, JSP_PATH + "admin.jsp"); 268 groupMessage = ""; 269 } 270 271 281 private void displayGroupCreate( HttpServletRequest request, 282 HttpServletResponse response, 283 HttpSession session ) 284 throws IOException , ServletException , JahiaException 285 { 286 logger.debug("Started"); 287 request.setAttribute("groupName", JahiaTools.nnString(request.getParameter("groupName"))); 288 289 JahiaHomepagesService hpServ = ServicesRegistry.getInstance().getJahiaHomepagesService(); 291 JahiaHomepage homePage = hpServ.getHomepage(jahiaSite.getGroupDefaultHomepageDef()); 292 if (homePage != null) { 293 JahiaHomepageLink homePageLink = (JahiaHomepageLink)homePage; 294 session.setAttribute("homePageID", new Integer (homePageLink.getPageID())); 295 request.setAttribute("defaultHomePage", JahiaPageBaseService.getInstance(). 296 lookupPageWhitoutTemplates(homePageLink.getPageID()).getTitle() + 297 " (" + homePage.getName() + ")"); 298 } 299 request.setAttribute("jspSource", JSP_PATH + "group_management/group_create.jsp"); 300 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 301 session.setAttribute("groupMessage", groupMessage); 302 session.setAttribute("jahiaDisplayMessage", 303 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 304 jParams, jParams.getLocale())); 305 doRedirect(request, response, session, JSP_PATH + "admin.jsp" ); 306 groupMessage = ""; 307 } 308 309 320 private boolean processGroupCreate(HttpServletRequest request, 321 HttpServletResponse response, 322 HttpSession session) 323 throws IOException , ServletException , JahiaException 324 { 325 String groupName = (String )request.getParameter("groupName").trim(); 326 if (groupName.length() == 0) { 327 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.specifyGroupName.label", 328 jParams, jParams.getLocale()); 329 return false; 330 } 331 if (groupName.length() == 0) { 333 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.specifyGroupName.label", 334 jParams, jParams.getLocale()); 335 return false; 336 } 337 else if (!JahiaTools.isAlphaValid(groupName)) { 340 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.onlyLettersDigitsUnderscores.label", 341 jParams, jParams.getLocale()); 342 return false; 343 } else if (gMgr.groupExists (jahiaSite.getID(), groupName)) { 344 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 345 jParams, jParams.getLocale()); 346 groupMessage += "[ " + groupName + "] "; 347 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.alreadyExist.label", 348 jParams, jParams.getLocale()); 349 return false; 350 } 351 JahiaGroup grp = createGroup(session, groupName); 353 if (grp == null) { 354 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.unableCreateGroup.label", 355 jParams, jParams.getLocale()); 356 groupMessage += " " + groupName; 357 return false; 358 } else { 359 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 360 jParams, jParams.getLocale()); 361 groupMessage += " [" + groupName + "] "; 362 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.created.label", 363 jParams, jParams.getLocale()); 364 } 365 if (request.getParameter("setHomePage") != null) { 367 Integer homePageIDInt = (Integer )session.getAttribute("homePageID"); 368 if (homePageIDInt != null) { 369 int homePageID = homePageIDInt.intValue(); 370 logger.debug("Process Home Page ID : " + homePageID); 371 grp.setHomepageID(homePageID); 372 } 373 } 374 return true; 375 } 376 377 387 private void displayGroupEdit(HttpServletRequest request, 388 HttpServletResponse response, 389 HttpSession session) 390 throws IOException , ServletException , JahiaException 391 { 392 logger.debug("Started"); 393 String groupToEdit = request.getParameter("selectedGroup"); 394 if (groupToEdit == null) { groupToEdit = (String )session.getAttribute("selectedGroup"); 396 } 397 if (groupToEdit == null || "null".equals(groupToEdit)) { 398 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.selectGroup.label", 399 jParams, jParams.getLocale()); 400 displayGroupList(request, response, session); 401 return; 402 } 403 session.setAttribute("selectedGroup", groupToEdit); 405 JahiaGroup theGroup = (JahiaGroup)gMgr.lookupGroup(jahiaSite.getID(), groupToEdit); 406 session.setAttribute("providerName",theGroup.getProviderName()); 408 410 if ("update".equals(request.getParameter("actionType"))) { 411 String [] newMembersList = (String []) request.getParameterValues("selectMember"); 414 if (newMembersList != null) { 416 Set updatedGroupSet = new HashSet (); 417 for (int i = 0; i < newMembersList.length; i++) { 418 JahiaUser usr = (JahiaUser) uMgr.lookupUser(newMembersList[ 420 i].substring(1)); 421 updatedGroupSet.add(usr); 422 } 423 request.setAttribute("groupMembers", updatedGroupSet); } else { 426 request.setAttribute("groupMembers", new HashSet ()); } 428 } else { 429 groupMembers = (HashSet )getGroupMembers(groupToEdit, jahiaSite.getID()); 430 request.setAttribute("groupMembers", groupMembers); } 433 434 if (session.getAttribute("homePageLabel") == null) { 436 int homePageID = theGroup.getHomepageID(); 437 if (homePageID != -1) { 438 444 try { 445 ArrayList locales = jahiaSite.getLanguageSettingsAsLocales(false); 446 EntryLoadRequest loadRequest = jParams.getEntryLoadRequest(); 447 if ( !locales.contains(jParams.getLocale()) ){ 448 loadRequest = EntryLoadRequest.STAGED; 449 locales.add(0,LanguageCodeConverters.languageCodeToLocale(ContentField.SHARED_LANGUAGE)); 450 loadRequest.setLocales(locales); 451 } 452 ContentPage contentPage = JahiaPageBaseService. 453 getInstance().lookupContentPage(homePageID,loadRequest,false); 454 session.setAttribute("homePageLabel", contentPage.getTitle(loadRequest)); 455 session.setAttribute("homePageID", new Integer (homePageID)); 456 } catch (JahiaException je) { 457 logger.error("Error on page ", je); 458 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.pageProblem.label", 459 jParams, jParams.getLocale()); 460 session.setAttribute("homePageLabel", "Disapeared !"); 461 } 462 } else { 463 String homePageLabelValue = 464 JahiaResourceBundle.getAdminResource("org.jahia.admin.none.label", 465 jParams, jParams.getLocale()); 466 session.setAttribute("homePageLabel", homePageLabelValue); 467 } 468 } 469 request.setAttribute("jspSource", JSP_PATH + "group_management/group_edit.jsp"); 470 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 471 session.setAttribute("jahiaDisplayMessage", 472 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 473 jParams, jParams.getLocale())); 474 session.setAttribute("groupMessage", groupMessage); 475 doRedirect(request, response, session, JSP_PATH + "admin.jsp"); 476 groupMessage = ""; 477 } 478 479 489 private boolean processGroupEdit(HttpServletRequest request, 490 HttpServletResponse response, 491 HttpSession session) 492 throws IOException , ServletException , JahiaException 493 { 494 logger.debug("Started"); 495 String groupName = (String )request.getParameter("groupName"); 496 JahiaGroup grp = gMgr.lookupGroup(jahiaSite.getID(), groupName); 497 498 if ("update".equals(request.getParameter("actionType"))) { 499 return false; 500 } 501 502 Integer homePageIDInt = (Integer )session.getAttribute("homePageID"); 504 if (homePageIDInt != null) { 505 int homePageID = homePageIDInt.intValue(); 506 if (homePageID != -1) { 507 logger.debug("Process Home Page ID : " + homePageID); 508 grp.setHomepageID(homePageID); 509 } else { 510 grp.removeProperty("group_homepage"); 511 } 512 session.removeAttribute("homePageID"); 513 session.removeAttribute("homePageLabel"); 514 } 515 516 String [] newMembersList = (String [])request.getParameterValues("selectMember"); 518 HashSet candidateMembers = new HashSet (); 520 if (newMembersList != null) { 521 for (int i = 0; i < newMembersList.length; i++) { 522 JahiaUser usr = (JahiaUser)uMgr.lookupUser(newMembersList[i].substring(1)); 524 candidateMembers.add(usr); 525 } 526 } 527 528 if (candidateMembers.size() > 0) { 530 try { addRemoveGroupMembers(groupMembers, candidateMembers, 533 JahiaGroup.class.getMethod("addMember", new Class [] {Principal .class}), grp); 534 addRemoveGroupMembers(candidateMembers, groupMembers, 536 JahiaGroup.class.getMethod("removeMember", new Class [] {Principal .class}), grp); 537 } catch (NoSuchMethodException nsme) { 538 logger.debug("Error ", nsme); 539 } 540 } else { 541 Iterator it = groupMembers.iterator(); 543 while (it.hasNext()) { 544 grp.removeMember((JahiaUser)it.next()); 545 } 546 } 547 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 548 jParams, jParams.getLocale()); 549 groupMessage += " [" + groupName + "] "; 550 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.updated.label", 551 jParams, jParams.getLocale()); 552 553 return true; 554 } 555 556 565 private void displayGroupMembership( HttpServletRequest request, 566 HttpServletResponse response, 567 HttpSession session) 568 throws IOException , ServletException 569 { 570 String selectedGroup = request.getParameter("selectedGroup"); 571 if (selectedGroup == null) { 572 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.selectGroup.label", 573 jParams, jParams.getLocale()); 574 displayGroupList(request, response, session); 575 } 576 else { 577 request.setAttribute("groupName", selectedGroup); 578 Vector groupMembership = getGroupMembership(selectedGroup, jahiaSite.getID()); 579 request.setAttribute("groupMembership", groupMembership); 580 581 request.setAttribute("jspSource", JSP_PATH + "group_management/group_view.jsp"); 582 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 583 session.setAttribute("jahiaDisplayMessage", 584 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 585 jParams, jParams.getLocale())); 586 doRedirect(request, response, session, JSP_PATH + "admin.jsp" ); 587 groupMessage = ""; 588 } 589 } 590 591 600 private void displayGroupCopy( HttpServletRequest request, 601 HttpServletResponse response, 602 HttpSession session ) 603 throws IOException , ServletException 604 { 605 logger.debug("Started"); 606 request.setAttribute("newGroup", JahiaTools.nnString(request.getParameter("newGroup"))); 607 String selectedGroup = request.getParameter("selectedGroup"); 608 if (selectedGroup == null) { selectedGroup = (String )session.getAttribute("selectedGroup"); 610 } 611 if (selectedGroup == null || "null".equals(selectedGroup)) { 612 groupMessage = "Please select a group in the select box"; 613 displayGroupList(request, response, session); 614 return; 615 } 616 session.setAttribute("selectedGroup", selectedGroup); 618 session.setAttribute("groupMessage", groupMessage); 619 620 request.setAttribute("jspSource", JSP_PATH + "group_management/group_copy.jsp"); 621 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 622 session.setAttribute("jahiaDisplayMessage", 623 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 624 jParams, jParams.getLocale())); 625 doRedirect(request, response, session, JSP_PATH + "admin.jsp" ); 626 groupMessage = ""; 627 } 628 629 639 private boolean processGroupCopy(HttpServletRequest request, 640 HttpServletResponse response, 641 HttpSession session) 642 throws IOException , ServletException 643 { 644 String groupName = (String )request.getParameter("newGroup"); 645 String sourceGroupName = (String )session.getAttribute("selectedGroup"); 646 if (groupName.length() == 0) { 648 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.specifyGroupName.label", 649 jParams, jParams.getLocale()); 650 return false; 651 } 652 else if (!JahiaTools.isAlphaValid(groupName)) { 655 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.onlyLettersDigitsUnderscores.label", 656 jParams, jParams.getLocale()); 657 return false; 658 } 659 else if (gMgr.groupExists (jahiaSite.getID(), groupName)) { 660 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 661 jParams, jParams.getLocale()); 662 groupMessage += " [" + groupName + "] "; 663 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.alreadyExist.label", 664 jParams, jParams.getLocale()); 665 return false; 666 } 667 668 if (createGroup(session, groupName) == null) { 670 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.unableCreateGroup.label", 671 jParams, jParams.getLocale()); 672 return false; 673 } 674 else { 675 JahiaGroup theNewGroup = gMgr.lookupGroup(jahiaSite.getID(), groupName); 676 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 677 jParams, jParams.getLocale()); 678 groupMessage += " [" + groupName + "] "; 679 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.created.label", 680 jParams, jParams.getLocale()); 681 Set sourceGroupMembers = getGroupMembers(sourceGroupName, jahiaSite.getID()); 682 Iterator it = sourceGroupMembers.iterator(); 683 while (it.hasNext()) { 684 theNewGroup.addMember((JahiaUser)it.next()); 685 } 686 JahiaGroup sourceGroup = gMgr.lookupGroup(jahiaSite.getID(), sourceGroupName); 688 int homePageID = sourceGroup.getHomepageID(); 689 if (homePageID != -1) { 690 theNewGroup.setHomepageID(homePageID); 691 } 692 } 693 return true; 694 } 695 696 705 private void displayGroupRemove( HttpServletRequest request, 706 HttpServletResponse response, 707 HttpSession session ) 708 throws IOException , ServletException 709 { 710 String selectedGroup = request.getParameter("selectedGroup"); 711 if (selectedGroup == null) { 712 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.selectGroup.label", 713 jParams, jParams.getLocale()); 714 displayGroupList(request, response, session); 715 } 716 else { 717 request.setAttribute("groupName", selectedGroup); 718 719 request.setAttribute("jspSource", JSP_PATH + "group_management/group_remove.jsp"); 720 request.setAttribute("directMenu", JSP_PATH + "direct_menu.jsp"); 721 session.setAttribute("jahiaDisplayMessage", 722 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 723 jParams, jParams.getLocale())); 724 session.setAttribute("groupMessage", groupMessage); 725 doRedirect(request, response, session, JSP_PATH + "admin.jsp"); 726 } 727 } 728 729 738 private void processGroupRemove( HttpServletRequest request, 739 HttpServletResponse response, 740 HttpSession session ) 741 throws IOException , ServletException 742 { 743 groupMessage = ""; 744 745 String groupName = (String ) request.getParameter("groupName"); 746 if ((groupName == null) || ("".equals(groupName))) { 748 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.cannotRemoved.label", 749 jParams, jParams.getLocale()); 750 groupMessage += " [" + groupName + "] "; 751 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 752 jParams, jParams.getLocale()); 753 } 754 755 JahiaGroup theGroup = (JahiaGroup)gMgr.lookupGroup(jahiaSite.getID(), groupName); 756 757 if (JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME.equals(groupName) || 763 JahiaGroupManagerService.USERS_GROUPNAME.equals(groupName) || 764 JahiaGroupManagerService.GUEST_GROUPNAME.equals(groupName)) { 765 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.cannotRemoved.label", 766 jParams, jParams.getLocale()); 767 groupMessage += " [" + groupName + "] "; 768 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 769 jParams, jParams.getLocale()); 770 } 771 772 if (groupMessage.equals("")) { 773 774 Set groupMembers = getGroupMembers(groupName, jahiaSite.getID()); 775 Iterator it = groupMembers.iterator(); 776 while (it.hasNext()) { 777 theGroup.removeMember((JahiaUser)it.next()); 778 } 779 780 try { 782 JahiaSiteGroupManagerService siteGroupManager = ServicesRegistry.getInstance().getJahiaSiteGroupManagerService(); 783 siteGroupManager.removeGroup(theGroup); 784 } catch (Exception e) { 785 } 786 if (!gMgr.deleteGroup(theGroup)) { 788 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.cannotRemoved.label", 789 jParams, jParams.getLocale()); 790 groupMessage += " [" + groupName + "] "; 791 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 792 jParams, jParams.getLocale()); 793 } else { 794 groupMessage = JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.group.label", 795 jParams, jParams.getLocale()); 796 groupMessage += " [" + groupName + "] "; 797 groupMessage += JahiaResourceBundle.getAdminResource("org.jahia.admin.groupMessage.removed.label", 798 jParams, jParams.getLocale()); 799 } 800 } 801 displayGroupList( request, response, session ); 802 groupMessage = ""; 803 } 804 805 813 private JahiaGroup createGroup(HttpSession session, String name) 814 { 815 JahiaGroup theGroup = null; 817 theGroup = gMgr.createGroup(jahiaSite.getID(), name , null); 818 if (theGroup != null) { 819 try { 821 JahiaSiteGroupManagerService siteGroupManager = 822 ServicesRegistry.getInstance().getJahiaSiteGroupManagerService(); 823 siteGroupManager.addGroup(jahiaSite.getID(), theGroup); 824 } catch (Exception e) { } 825 } 826 return theGroup; 827 } 828 829 837 private Set getGroupMembers(String groupName, int jahiaSite) { 838 839 JahiaGroup theGroup = (JahiaGroup)gMgr.lookupGroup(jahiaSite, groupName); 840 Set groupMembers = new HashSet (); 841 if (theGroup != null) { 842 Enumeration groupMembersEnum = theGroup.members(); 843 while (groupMembersEnum.hasMoreElements()) { 844 Object member = (Object )groupMembersEnum.nextElement(); 845 if (member instanceof JahiaUser) { 847 if (member instanceof JahiaDBUser) { 850 int siteID = ((JahiaUser)member).getSiteID(); 851 if (siteID == jahiaSite || siteID == 0) { 852 groupMembers.add((JahiaUser)member); 853 } 854 } else { 855 groupMembers.add((JahiaUser)member); 856 } 857 } else { 858 if (((JahiaGroup)member).getSiteID() == jahiaSite) { 859 groupMembers.add((JahiaGroup)member); 860 } 861 } 862 } 863 } 864 return groupMembers; 865 } 866 867 876 private Vector getGroupMembership(String groupName, int jahiaSite) 877 { 878 JahiaGroup theGroup = (JahiaGroup)gMgr.lookupGroup(jahiaSite, groupName); 879 Vector groupMembership = new Vector (); 880 if (theGroup != null) { 881 Enumeration groupMembersEnum = theGroup.members(); 882 while (groupMembersEnum.hasMoreElements()) { 883 Object obj = (Object )groupMembersEnum.nextElement(); 884 if ((obj instanceof JahiaUser) && (((JahiaUser)obj).getSiteID() != jahiaSite)) { 886 JahiaUser grpMembers = (JahiaUser)obj; 887 groupMembership.add(grpMembers.getUsername()); int memberSiteID = grpMembers.getSiteID(); 890 if (memberSiteID == 0) { 891 groupMembership.add("jahia server"); 892 } else { 893 try { 894 JahiaSitesService sitesManager = 895 ServicesRegistry.getInstance().getJahiaSitesService(); 896 JahiaSite memberSite = sitesManager.getSite(memberSiteID); 897 if (memberSite != null) { 898 groupMembership.add(memberSite.getServerName()); 899 } else { 900 groupMembership.add("unknow"); 901 } 902 } catch (Exception e) { 903 } 904 } 905 } 906 } 907 } 908 return groupMembership; 909 } 910 911 920 private void addRemoveGroupMembers(HashSet left, HashSet right, Method addRem, JahiaGroup grp) { 921 Iterator itRight = right.iterator(); 922 while (itRight.hasNext()) { 923 JahiaUser elementRight = (JahiaUser)itRight.next(); 924 Iterator itLeft = left.iterator(); 925 while (itLeft.hasNext()) { 926 JahiaUser elementLeft = (JahiaUser)itLeft.next(); 927 if (elementLeft.getUsername().equals(elementRight.getUsername())) { 928 elementRight = null; 929 break; 930 } 931 } 932 if (elementRight != null) { 933 try { 934 Object [] args = { elementRight }; 935 addRem.invoke(grp, args); 936 } catch (IllegalAccessException iae) { 937 logger.error("Error ", iae); 938 } catch (InvocationTargetException ite) { 939 logger.error("Error ", ite); 940 } 941 } 942 } 943 } 944 945 985 993 private void processHomePage(HttpServletRequest request, 994 HttpServletResponse response, 995 HttpSession session) 996 throws Throwable 997 { 998 if (homePageTool == null) { 999 homePageTool = new HomePageTool(request, response, session); 1000 } else { 1001 homePageTool.requestDispatcher(request, response, session); 1002 } 1003 } 1004 1005 1013 private void processGroupMembers(HttpServletRequest request, 1014 HttpServletResponse response, 1015 HttpSession session) 1016 throws Throwable 1017 { 1018 if (groupMembersTool == null) { 1019 groupMembersTool = new GroupMembersTool(request, response, session); 1020 } else { 1021 groupMembersTool.requestDispatcher(request, response, session); 1022 } 1023 } 1024 1025 private static org.apache.log4j.Logger logger = 1026 org.apache.log4j.Logger.getLogger(ManageGroups.class); 1027 1028} 1029 | Popular Tags |