1 40 package org.dspace.app.webui.servlet.admin; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 import java.util.HashMap ; 45 import java.util.List ; 46 import java.util.Map ; 47 48 import javax.servlet.ServletException ; 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 51 52 import org.dspace.app.webui.servlet.DSpaceServlet; 53 import org.dspace.app.webui.util.JSPManager; 54 import org.dspace.app.webui.util.UIUtil; 55 import org.dspace.authorize.AuthorizeException; 56 import org.dspace.authorize.AuthorizeManager; 57 import org.dspace.authorize.PolicySet; 58 import org.dspace.authorize.ResourcePolicy; 59 import org.dspace.content.Bitstream; 60 import org.dspace.content.Bundle; 61 import org.dspace.content.Collection; 62 import org.dspace.content.Community; 63 import org.dspace.content.DSpaceObject; 64 import org.dspace.content.Item; 65 import org.dspace.core.Constants; 66 import org.dspace.core.Context; 67 import org.dspace.eperson.EPerson; 68 import org.dspace.eperson.Group; 69 import org.dspace.handle.HandleManager; 70 71 77 public class AuthorizeAdminServlet extends DSpaceServlet 78 { 79 protected void doDSGet(Context c, HttpServletRequest request, 80 HttpServletResponse response) throws ServletException , IOException , 81 SQLException , AuthorizeException 82 { 83 doDSPost(c, request, response); 85 86 } 89 90 protected void doDSPost(Context c, HttpServletRequest request, 91 HttpServletResponse response) throws ServletException , IOException , 92 SQLException , AuthorizeException 93 { 94 String button = UIUtil.getSubmitButton(request, "submit"); 95 96 if (button.equals("submit_collection")) 97 { 98 Collection[] collections = Collection.findAll(c); 100 101 request.setAttribute("collections", collections); 102 JSPManager.showJSP(request, response, 103 "/dspace-admin/collection-select.jsp"); 104 } 105 else if (button.equals("submit_community")) 106 { 107 Community[] communities = Community.findAll(c); 109 110 request.setAttribute("communities", communities); 111 JSPManager.showJSP(request, response, 112 "/dspace-admin/community-select.jsp"); 113 } 114 else if (button.equals("submit_advanced")) 115 { 116 Collection[] collections = Collection.findAll(c); 118 Group[] groups = Group.findAll(c, Group.NAME); 119 120 request.setAttribute("collections", collections); 121 request.setAttribute("groups", groups); 122 123 JSPManager.showJSP(request, response, 124 "/dspace-admin/authorize-advanced.jsp"); 125 } 126 else if (button.equals("submit_item")) 127 { 128 JSPManager.showJSP(request, response, 130 "/dspace-admin/item-select.jsp"); 131 } 132 else if (button.equals("submit_item_select")) 134 { 135 Item item = null; 136 137 int item_id = UIUtil.getIntParameter(request, "item_id"); 138 String handle = request.getParameter("handle"); 139 140 if (item_id > 0) 142 { 143 item = Item.find(c, item_id); 144 } 145 else if ((handle != null) && !handle.equals("")) 146 { 147 DSpaceObject dso = HandleManager.resolveToObject(c, handle); 149 150 if ((dso != null) && (dso.getType() == Constants.ITEM)) 152 { 153 item = (Item) dso; 154 } 155 } 156 157 if (item == null) 159 { 160 request.setAttribute("invalid.id", new Boolean (true)); 161 JSPManager.showJSP(request, response, 162 "/dspace-admin/item-select.jsp"); 163 } 164 else 165 { 166 prepItemEditForm(c, request, item); 168 169 JSPManager.showJSP(request, response, 170 "/dspace-admin/authorize-item-edit.jsp"); 171 } 172 } 173 else if (button.equals("submit_item_add_policy")) 174 { 175 Item item = Item 177 .find(c, UIUtil.getIntParameter(request, "item_id")); 178 179 ResourcePolicy policy = ResourcePolicy.create(c); 180 policy.setResource(item); 181 policy.update(); 182 183 Group[] groups = Group.findAll(c, Group.NAME); 184 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 185 186 request.setAttribute("edit_title", "Item " + item.getID()); 188 request.setAttribute("policy", policy); 189 request.setAttribute("groups", groups); 190 request.setAttribute("epeople", epeople); 191 request.setAttribute("id_name", "item_id"); 192 request.setAttribute("id", "" + item.getID()); 193 request.setAttribute("newpolicy", "true"); 194 195 JSPManager.showJSP(request, response, 196 "/dspace-admin/authorize-policy-edit.jsp"); 197 } 198 else if (button.equals("submit_item_edit_policy")) 199 { 200 Item item = Item 202 .find(c, UIUtil.getIntParameter(request, "item_id")); 203 204 int policy_id = UIUtil.getIntParameter(request, "policy_id"); 205 ResourcePolicy policy = null; 206 207 policy = ResourcePolicy.find(c, policy_id); 208 209 Group[] groups = Group.findAll(c, Group.NAME); 210 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 211 212 request.setAttribute("edit_title", "Item " + item.getID()); 214 request.setAttribute("policy", policy); 215 request.setAttribute("groups", groups); 216 request.setAttribute("epeople", epeople); 217 request.setAttribute("id_name", "item_id"); 218 request.setAttribute("id", "" + item.getID()); 219 JSPManager.showJSP(request, response, 220 "/dspace-admin/authorize-policy-edit.jsp"); 221 } 222 else if (button.equals("submit_bundle_add_policy")) 223 { 224 Item item = Item 226 .find(c, UIUtil.getIntParameter(request, "item_id")); 227 Bundle bundle = Bundle.find(c, UIUtil.getIntParameter(request, 228 "bundle_id")); 229 230 ResourcePolicy policy = ResourcePolicy.create(c); 231 policy.setResource(bundle); 232 policy.update(); 233 234 Group[] groups = Group.findAll(c, Group.NAME); 235 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 236 237 request.setAttribute("edit_title", "(Item, Bundle) = (" 239 + item.getID() + "," + bundle.getID() + ")"); 240 request.setAttribute("policy", policy); 241 request.setAttribute("groups", groups); 242 request.setAttribute("epeople", epeople); 243 request.setAttribute("id_name", "item_id"); 244 request.setAttribute("id", "" + item.getID()); 245 request.setAttribute("newpolicy", "true"); 246 247 JSPManager.showJSP(request, response, 248 "/dspace-admin/authorize-policy-edit.jsp"); 249 } 250 else if (button.equals("submit_bitstream_add_policy")) 251 { 252 Item item = Item 254 .find(c, UIUtil.getIntParameter(request, "item_id")); 255 Bitstream bitstream = Bitstream.find(c, UIUtil.getIntParameter( 256 request, "bitstream_id")); 257 258 ResourcePolicy policy = ResourcePolicy.create(c); 259 policy.setResource(bitstream); 260 policy.update(); 261 262 Group[] groups = Group.findAll(c, Group.NAME); 263 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 264 265 request.setAttribute("edit_title", "(Item,Bitstream) = (" 267 + item.getID() + "," + bitstream.getID() + ")"); 268 request.setAttribute("policy", policy); 269 request.setAttribute("groups", groups); 270 request.setAttribute("epeople", epeople); 271 request.setAttribute("id_name", "item_id"); 272 request.setAttribute("id", "" + item.getID()); 273 request.setAttribute("newpolicy", "true"); 274 275 JSPManager.showJSP(request, response, 276 "/dspace-admin/authorize-policy-edit.jsp"); 277 } 278 else if (button.equals("submit_item_delete_policy")) 279 { 280 Item item = Item 282 .find(c, UIUtil.getIntParameter(request, "item_id")); 283 ResourcePolicy policy = ResourcePolicy.find(c, UIUtil 284 .getIntParameter(request, "policy_id")); 285 286 policy.delete(); 288 289 prepItemEditForm(c, request, item); 291 292 JSPManager.showJSP(request, response, 293 "/dspace-admin/authorize-item-edit.jsp"); 294 } 295 else if (button.equals("submit_collection_add_policy")) 297 { 298 Collection collection = Collection.find(c, UIUtil.getIntParameter( 300 request, "collection_id")); 301 302 ResourcePolicy policy = ResourcePolicy.create(c); 303 policy.setResource(collection); 304 policy.update(); 305 306 Group[] groups = Group.findAll(c, Group.NAME); 307 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 308 309 request.setAttribute("edit_title", "Collection " 311 + collection.getID()); 312 request.setAttribute("policy", policy); 313 request.setAttribute("groups", groups); 314 request.setAttribute("epeople", epeople); 315 request.setAttribute("id_name", "collection_id"); 316 request.setAttribute("id", "" + collection.getID()); 317 request.setAttribute("newpolicy", "true"); 318 319 JSPManager.showJSP(request, response, 320 "/dspace-admin/authorize-policy-edit.jsp"); 321 } 322 else if (button.equals("submit_community_select")) 323 { 324 Community target = Community.find(c, UIUtil.getIntParameter( 326 request, "community_id")); 327 List policies = AuthorizeManager.getPolicies(c, target); 328 329 request.setAttribute("community", target); 330 request.setAttribute("policies", policies); 331 JSPManager.showJSP(request, response, 332 "/dspace-admin/authorize-community-edit.jsp"); 333 } 334 else if (button.equals("submit_collection_delete_policy")) 335 { 336 Collection collection = Collection.find(c, UIUtil.getIntParameter( 338 request, "collection_id")); 339 ResourcePolicy policy = ResourcePolicy.find(c, UIUtil 340 .getIntParameter(request, "policy_id")); 341 342 policy.delete(); 344 345 request.setAttribute("collection", collection); 347 348 List policies = AuthorizeManager.getPolicies(c, collection); 349 request.setAttribute("policies", policies); 350 351 JSPManager.showJSP(request, response, 352 "/dspace-admin/authorize-collection-edit.jsp"); 353 } 354 else if (button.equals("submit_community_delete_policy")) 355 { 356 Community community = Community.find(c, UIUtil.getIntParameter( 358 request, "community_id")); 359 ResourcePolicy policy = ResourcePolicy.find(c, UIUtil 360 .getIntParameter(request, "policy_id")); 361 362 policy.delete(); 364 365 request.setAttribute("community", community); 367 368 List policies = AuthorizeManager.getPolicies(c, community); 369 request.setAttribute("policies", policies); 370 371 JSPManager.showJSP(request, response, 372 "/dspace-admin/authorize-community-edit.jsp"); 373 } 374 else if (button.equals("submit_collection_edit_policy")) 375 { 376 Collection collection = Collection.find(c, UIUtil.getIntParameter( 378 request, "collection_id")); 379 380 int policy_id = UIUtil.getIntParameter(request, "policy_id"); 381 ResourcePolicy policy = null; 382 383 if (policy_id == -1) 384 { 385 policy = ResourcePolicy.create(c); 387 policy.setResource(collection); 388 policy.update(); 389 } 390 else 391 { 392 policy = ResourcePolicy.find(c, policy_id); 393 } 394 395 Group[] groups = Group.findAll(c, Group.NAME); 396 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 397 398 request.setAttribute("edit_title", "Collection " 400 + collection.getID()); 401 request.setAttribute("policy", policy); 402 request.setAttribute("groups", groups); 403 request.setAttribute("epeople", epeople); 404 request.setAttribute("id_name", "collection_id"); 405 request.setAttribute("id", "" + collection.getID()); 406 JSPManager.showJSP(request, response, 407 "/dspace-admin/authorize-policy-edit.jsp"); 408 } 409 else if (button.equals("submit_community_edit_policy")) 410 { 411 Community community = Community.find(c, UIUtil.getIntParameter( 413 request, "community_id")); 414 415 int policy_id = UIUtil.getIntParameter(request, "policy_id"); 416 ResourcePolicy policy = null; 417 418 if (policy_id == -1) 419 { 420 policy = ResourcePolicy.create(c); 422 policy.setResource(community); 423 policy.update(); 424 } 425 else 426 { 427 policy = ResourcePolicy.find(c, policy_id); 428 } 429 430 Group[] groups = Group.findAll(c, Group.NAME); 431 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 432 433 request 435 .setAttribute("edit_title", "Community " 436 + community.getID()); 437 request.setAttribute("policy", policy); 438 request.setAttribute("groups", groups); 439 request.setAttribute("epeople", epeople); 440 request.setAttribute("id_name", "community_id"); 441 request.setAttribute("id", "" + community.getID()); 442 JSPManager.showJSP(request, response, 443 "/dspace-admin/authorize-policy-edit.jsp"); 444 } 445 else if (button.equals("submit_collection_add_policy")) 446 { 447 Collection collection = Collection.find(c, UIUtil.getIntParameter( 449 request, "collection_id")); 450 451 ResourcePolicy policy = ResourcePolicy.create(c); 452 policy.setResource(collection); 453 policy.update(); 454 455 Group[] groups = Group.findAll(c, Group.NAME); 456 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 457 458 request.setAttribute("edit_title", "Collection " 460 + collection.getID()); 461 request.setAttribute("policy", policy); 462 request.setAttribute("groups", groups); 463 request.setAttribute("epeople", epeople); 464 request.setAttribute("id_name", "collection_id"); 465 request.setAttribute("id", "" + collection.getID()); 466 request.setAttribute("newpolicy", "true"); 467 468 JSPManager.showJSP(request, response, 469 "/dspace-admin/authorize-policy-edit.jsp"); 470 } 471 else if (button.equals("submit_community_add_policy")) 472 { 473 Community community = Community.find(c, UIUtil.getIntParameter( 475 request, "community_id")); 476 477 ResourcePolicy policy = ResourcePolicy.create(c); 478 policy.setResource(community); 479 policy.update(); 480 481 Group[] groups = Group.findAll(c, Group.NAME); 482 EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL); 483 484 request 486 .setAttribute("edit_title", "Community " 487 + community.getID()); 488 request.setAttribute("policy", policy); 489 request.setAttribute("groups", groups); 490 request.setAttribute("epeople", epeople); 491 request.setAttribute("id_name", "community_id"); 492 request.setAttribute("id", "" + community.getID()); 493 request.setAttribute("newpolicy", "true"); 494 495 JSPManager.showJSP(request, response, 496 "/dspace-admin/authorize-policy-edit.jsp"); 497 } 498 else if (button.equals("submit_save_policy")) 499 { 500 int policy_id = UIUtil.getIntParameter(request, "policy_id"); 501 int action_id = UIUtil.getIntParameter(request, "action_id"); 502 int group_id = UIUtil.getIntParameter(request, "group_id"); 503 int collection_id = UIUtil 504 .getIntParameter(request, "collection_id"); 505 int community_id = UIUtil.getIntParameter(request, "community_id"); 506 int item_id = UIUtil.getIntParameter(request, "item_id"); 507 508 Item item = null; 509 Collection collection = null; 510 Community community = null; 511 String display_page = null; 512 513 ResourcePolicy policy = ResourcePolicy.find(c, policy_id); 514 Group group = Group.find(c, group_id); 515 516 if (collection_id != -1) 517 { 518 collection = Collection.find(c, collection_id); 519 520 policy.setAction(action_id); 522 policy.setGroup(group); 523 policy.update(); 524 525 if (action_id == Constants.READ) 527 { 528 List rps = AuthorizeManager.getPoliciesActionFilter(c, 530 collection, Constants.READ); 531 532 Bitstream bs = collection.getLogo(); 534 535 if (bs != null) 536 { 537 AuthorizeManager.removeAllPolicies(c, bs); 538 AuthorizeManager.addPolicies(c, rps, bs); 539 } 540 } 541 542 request.setAttribute("collection", collection); 544 request.setAttribute("policies", AuthorizeManager.getPolicies( 545 c, collection)); 546 display_page = "/dspace-admin/authorize-collection-edit.jsp"; 547 } 548 else if (community_id != -1) 549 { 550 community = Community.find(c, community_id); 551 552 policy.setAction(action_id); 554 policy.setGroup(group); 555 policy.update(); 556 557 if (action_id == Constants.READ) 559 { 560 List rps = AuthorizeManager.getPoliciesActionFilter(c, 562 community, Constants.READ); 563 564 Bitstream bs = community.getLogo(); 566 567 if (bs != null) 568 { 569 AuthorizeManager.removeAllPolicies(c, bs); 570 AuthorizeManager.addPolicies(c, rps, bs); 571 } 572 } 573 574 request.setAttribute("community", community); 576 request.setAttribute("policies", AuthorizeManager.getPolicies( 577 c, community)); 578 display_page = "/dspace-admin/authorize-community-edit.jsp"; 579 } 580 else if (item_id != -1) 581 { 582 item = Item.find(c, item_id); 583 584 policy.setAction(action_id); 586 policy.setGroup(group); 587 policy.update(); 588 589 prepItemEditForm(c, request, item); 591 592 display_page = "/dspace-admin/authorize-item-edit.jsp"; 593 } 594 595 JSPManager.showJSP(request, response, display_page); 597 } 598 else if (button.equals("submit_cancel_policy")) 599 { 600 if ((request.getParameter("newpolicy") != null)) 602 { 603 int policy_id = UIUtil.getIntParameter(request, "policy_id"); 604 ResourcePolicy rp = ResourcePolicy.find(c, policy_id); 605 rp.delete(); 606 } 607 608 int collection_id = UIUtil 610 .getIntParameter(request, "collection_id"); 611 int community_id = UIUtil.getIntParameter(request, "community_id"); 612 int item_id = UIUtil.getIntParameter(request, "item_id"); 613 String display_page = null; 614 615 if (collection_id != -1) 616 { 617 Collection t = Collection.find(c, collection_id); 619 620 request.setAttribute("collection", t); 621 request.setAttribute("policies", AuthorizeManager.getPolicies( 622 c, t)); 623 display_page = "/dspace-admin/authorize-collection-edit.jsp"; 624 } 625 else if (community_id != -1) 626 { 627 Community t = Community.find(c, community_id); 629 630 request.setAttribute("community", t); 631 request.setAttribute("policies", AuthorizeManager.getPolicies( 632 c, t)); 633 display_page = "/dspace-admin/authorize-community-edit.jsp"; 634 } 635 else if (item_id != -1) 636 { 637 Item t = Item.find(c, item_id); 639 640 prepItemEditForm(c, request, t); 642 643 display_page = "/dspace-admin/authorize-item-edit.jsp"; 644 } 645 646 JSPManager.showJSP(request, response, display_page); 647 } 648 else if (button.equals("submit_advanced_clear")) 649 { 650 int collection_id = UIUtil 652 .getIntParameter(request, "collection_id"); 653 int resource_type = UIUtil 654 .getIntParameter(request, "resource_type"); 655 656 PolicySet.setPolicies(c, Constants.COLLECTION, collection_id, 658 resource_type, 0, 0, false, true); 659 660 if (resource_type == Constants.BITSTREAM) 661 { 662 PolicySet.setPolicies(c, Constants.COLLECTION, collection_id, 663 Constants.BUNDLE, 0, 0, false, true); 664 } 665 666 showMainPage(c, request, response); 668 } 669 else if (button.equals("submit_advanced_add")) 670 { 671 int collection_id = UIUtil 673 .getIntParameter(request, "collection_id"); 674 int resource_type = UIUtil 675 .getIntParameter(request, "resource_type"); 676 int action_id = UIUtil.getIntParameter(request, "action_id"); 677 int group_id = UIUtil.getIntParameter(request, "group_id"); 678 679 PolicySet.setPolicies(c, Constants.COLLECTION, collection_id, 680 resource_type, action_id, group_id, false, false); 681 682 if (resource_type == Constants.BITSTREAM) 684 { 685 PolicySet.setPolicies(c, Constants.COLLECTION, collection_id, 686 Constants.BUNDLE, action_id, group_id, false, false); 687 } 688 689 showMainPage(c, request, response); 691 } 692 else if (button.equals("submit_collection_select")) 693 { 694 Collection collection = Collection.find(c, UIUtil.getIntParameter( 696 request, "collection_id")); 697 List policies = AuthorizeManager.getPolicies(c, collection); 698 699 request.setAttribute("collection", collection); 700 request.setAttribute("policies", policies); 701 JSPManager.showJSP(request, response, 702 "/dspace-admin/authorize-collection-edit.jsp"); 703 } 704 else 705 { 706 showMainPage(c, request, response); 708 } 709 710 c.complete(); 711 } 712 713 void showMainPage(Context c, HttpServletRequest request, 714 HttpServletResponse response) throws ServletException , IOException , 715 SQLException , AuthorizeException 716 { 717 JSPManager.showJSP(request, response, 718 "/dspace-admin/authorize-main.jsp"); 719 } 720 721 void prepItemEditForm(Context c, HttpServletRequest request, Item item) 722 throws SQLException 723 { 724 List item_policies = AuthorizeManager.getPolicies(c, item); 725 726 Map bundle_policies = new HashMap (); 728 Map bitstream_policies = new HashMap (); 729 730 Bundle[] bundles = item.getBundles(); 731 732 for (int i = 0; i < bundles.length; i++) 733 { 734 Bundle myBundle = bundles[i]; 735 List myPolicies = AuthorizeManager.getPolicies(c, myBundle); 736 737 bundle_policies.put(new Integer (myBundle.getID()), myPolicies); 739 740 Bitstream[] bitstreams = myBundle.getBitstreams(); 742 743 for (int j = 0; j < bitstreams.length; j++) 744 { 745 Bitstream myBitstream = bitstreams[j]; 746 myPolicies = AuthorizeManager.getPolicies(c, myBitstream); 747 bitstream_policies.put(new Integer (myBitstream.getID()), 748 myPolicies); 749 } 750 } 751 752 request.setAttribute("item", item); 753 request.setAttribute("item_policies", item_policies); 754 request.setAttribute("bundles", bundles); 755 request.setAttribute("bundle_policies", bundle_policies); 756 request.setAttribute("bitstream_policies", bitstream_policies); 757 } 758 } 759 | Popular Tags |