1 17 18 19 package org.apache.catalina.connector; 20 21 import java.io.BufferedReader ; 22 import java.io.IOException ; 23 import java.security.AccessController ; 24 import java.security.PrivilegedAction ; 25 import java.util.Enumeration ; 26 import java.util.Locale ; 27 import java.util.Map ; 28 29 import javax.servlet.RequestDispatcher ; 30 import javax.servlet.ServletInputStream ; 31 import javax.servlet.http.Cookie ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpSession ; 34 35 import org.apache.catalina.util.StringManager; 36 37 38 import org.apache.catalina.security.SecurityUtil; 39 40 49 50 @SuppressWarnings ("deprecation") 51 public class RequestFacade implements HttpServletRequest { 52 53 54 56 private final class GetAttributePrivilegedAction 57 implements PrivilegedAction { 58 59 public Object run() { 60 return request.getAttributeNames(); 61 } 62 } 63 64 65 private final class GetParameterMapPrivilegedAction 66 implements PrivilegedAction { 67 68 public Object run() { 69 return request.getParameterMap(); 70 } 71 } 72 73 74 private final class GetRequestDispatcherPrivilegedAction 75 implements PrivilegedAction { 76 77 private String path; 78 79 public GetRequestDispatcherPrivilegedAction(String path){ 80 this.path = path; 81 } 82 83 public Object run() { 84 return request.getRequestDispatcher(path); 85 } 86 } 87 88 89 private final class GetParameterPrivilegedAction 90 implements PrivilegedAction { 91 92 public String name; 93 94 public GetParameterPrivilegedAction(String name){ 95 this.name = name; 96 } 97 98 public Object run() { 99 return request.getParameter(name); 100 } 101 } 102 103 104 private final class GetParameterNamesPrivilegedAction 105 implements PrivilegedAction { 106 107 public Object run() { 108 return request.getParameterNames(); 109 } 110 } 111 112 113 private final class GetParameterValuePrivilegedAction 114 implements PrivilegedAction { 115 116 public String name; 117 118 public GetParameterValuePrivilegedAction(String name){ 119 this.name = name; 120 } 121 122 public Object run() { 123 return request.getParameterValues(name); 124 } 125 } 126 127 128 private final class GetCookiesPrivilegedAction 129 implements PrivilegedAction { 130 131 public Object run() { 132 return request.getCookies(); 133 } 134 } 135 136 137 private final class GetCharacterEncodingPrivilegedAction 138 implements PrivilegedAction { 139 140 public Object run() { 141 return request.getCharacterEncoding(); 142 } 143 } 144 145 146 private final class GetHeadersPrivilegedAction 147 implements PrivilegedAction { 148 149 private String name; 150 151 public GetHeadersPrivilegedAction(String name){ 152 this.name = name; 153 } 154 155 public Object run() { 156 return request.getHeaders(name); 157 } 158 } 159 160 161 private final class GetHeaderNamesPrivilegedAction 162 implements PrivilegedAction { 163 164 public Object run() { 165 return request.getHeaderNames(); 166 } 167 } 168 169 170 private final class GetLocalePrivilegedAction 171 implements PrivilegedAction { 172 173 public Object run() { 174 return request.getLocale(); 175 } 176 } 177 178 179 private final class GetLocalesPrivilegedAction 180 implements PrivilegedAction { 181 182 public Object run() { 183 return request.getLocales(); 184 } 185 } 186 187 private final class GetSessionPrivilegedAction 188 implements PrivilegedAction { 189 190 private boolean create; 191 192 public GetSessionPrivilegedAction(boolean create){ 193 this.create = create; 194 } 195 196 public Object run() { 197 return request.getSession(create); 198 } 199 } 200 201 203 204 209 public RequestFacade(Request request) { 210 211 this.request = request; 212 213 } 214 215 216 218 219 222 protected Request request = null; 223 224 225 228 protected static StringManager sm = 229 StringManager.getManager(Constants.Package); 230 231 232 234 235 238 public void clear() { 239 request = null; 240 } 241 242 243 246 protected Object clone() 247 throws CloneNotSupportedException { 248 throw new CloneNotSupportedException (); 249 } 250 251 252 254 255 public Object getAttribute(String name) { 256 257 if (request == null) { 258 throw new IllegalStateException ( 259 sm.getString("requestFacade.nullRequest")); 260 } 261 262 return request.getAttribute(name); 263 } 264 265 266 public Enumeration getAttributeNames() { 267 268 if (request == null) { 269 throw new IllegalStateException ( 270 sm.getString("requestFacade.nullRequest")); 271 } 272 273 if (System.getSecurityManager() != null){ 274 return (Enumeration )AccessController.doPrivileged( 275 new GetAttributePrivilegedAction()); 276 } else { 277 return request.getAttributeNames(); 278 } 279 } 280 281 282 public String getCharacterEncoding() { 283 284 if (request == null) { 285 throw new IllegalStateException ( 286 sm.getString("requestFacade.nullRequest")); 287 } 288 289 if (System.getSecurityManager() != null){ 290 return (String )AccessController.doPrivileged( 291 new GetCharacterEncodingPrivilegedAction()); 292 } else { 293 return request.getCharacterEncoding(); 294 } 295 } 296 297 298 public void setCharacterEncoding(String env) 299 throws java.io.UnsupportedEncodingException { 300 301 if (request == null) { 302 throw new IllegalStateException ( 303 sm.getString("requestFacade.nullRequest")); 304 } 305 306 request.setCharacterEncoding(env); 307 } 308 309 310 public int getContentLength() { 311 312 if (request == null) { 313 throw new IllegalStateException ( 314 sm.getString("requestFacade.nullRequest")); 315 } 316 317 return request.getContentLength(); 318 } 319 320 321 public String getContentType() { 322 323 if (request == null) { 324 throw new IllegalStateException ( 325 sm.getString("requestFacade.nullRequest")); 326 } 327 328 return request.getContentType(); 329 } 330 331 332 public ServletInputStream getInputStream() throws IOException { 333 334 if (request == null) { 335 throw new IllegalStateException ( 336 sm.getString("requestFacade.nullRequest")); 337 } 338 339 return request.getInputStream(); 340 } 341 342 343 public String getParameter(String name) { 344 345 if (request == null) { 346 throw new IllegalStateException ( 347 sm.getString("requestFacade.nullRequest")); 348 } 349 350 if (System.getSecurityManager() != null){ 351 return (String )AccessController.doPrivileged( 352 new GetParameterPrivilegedAction(name)); 353 } else { 354 return request.getParameter(name); 355 } 356 } 357 358 359 public Enumeration getParameterNames() { 360 361 if (request == null) { 362 throw new IllegalStateException ( 363 sm.getString("requestFacade.nullRequest")); 364 } 365 366 if (System.getSecurityManager() != null){ 367 return (Enumeration )AccessController.doPrivileged( 368 new GetParameterNamesPrivilegedAction()); 369 } else { 370 return request.getParameterNames(); 371 } 372 } 373 374 375 public String [] getParameterValues(String name) { 376 377 if (request == null) { 378 throw new IllegalStateException ( 379 sm.getString("requestFacade.nullRequest")); 380 } 381 382 String [] ret = null; 383 384 388 if (SecurityUtil.isPackageProtectionEnabled()){ 389 ret = (String []) AccessController.doPrivileged( 390 new GetParameterValuePrivilegedAction(name)); 391 if (ret != null) { 392 ret = (String []) ret.clone(); 393 } 394 } else { 395 ret = request.getParameterValues(name); 396 } 397 398 return ret; 399 } 400 401 402 public Map getParameterMap() { 403 404 if (request == null) { 405 throw new IllegalStateException ( 406 sm.getString("requestFacade.nullRequest")); 407 } 408 409 if (System.getSecurityManager() != null){ 410 return (Map )AccessController.doPrivileged( 411 new GetParameterMapPrivilegedAction()); 412 } else { 413 return request.getParameterMap(); 414 } 415 } 416 417 418 public String getProtocol() { 419 420 if (request == null) { 421 throw new IllegalStateException ( 422 sm.getString("requestFacade.nullRequest")); 423 } 424 425 return request.getProtocol(); 426 } 427 428 429 public String getScheme() { 430 431 if (request == null) { 432 throw new IllegalStateException ( 433 sm.getString("requestFacade.nullRequest")); 434 } 435 436 return request.getScheme(); 437 } 438 439 440 public String getServerName() { 441 442 if (request == null) { 443 throw new IllegalStateException ( 444 sm.getString("requestFacade.nullRequest")); 445 } 446 447 return request.getServerName(); 448 } 449 450 451 public int getServerPort() { 452 453 if (request == null) { 454 throw new IllegalStateException ( 455 sm.getString("requestFacade.nullRequest")); 456 } 457 458 return request.getServerPort(); 459 } 460 461 462 public BufferedReader getReader() throws IOException { 463 464 if (request == null) { 465 throw new IllegalStateException ( 466 sm.getString("requestFacade.nullRequest")); 467 } 468 469 return request.getReader(); 470 } 471 472 473 public String getRemoteAddr() { 474 475 if (request == null) { 476 throw new IllegalStateException ( 477 sm.getString("requestFacade.nullRequest")); 478 } 479 480 return request.getRemoteAddr(); 481 } 482 483 484 public String getRemoteHost() { 485 486 if (request == null) { 487 throw new IllegalStateException ( 488 sm.getString("requestFacade.nullRequest")); 489 } 490 491 return request.getRemoteHost(); 492 } 493 494 495 public void setAttribute(String name, Object o) { 496 497 if (request == null) { 498 throw new IllegalStateException ( 499 sm.getString("requestFacade.nullRequest")); 500 } 501 502 request.setAttribute(name, o); 503 } 504 505 506 public void removeAttribute(String name) { 507 508 if (request == null) { 509 throw new IllegalStateException ( 510 sm.getString("requestFacade.nullRequest")); 511 } 512 513 request.removeAttribute(name); 514 } 515 516 517 public Locale getLocale() { 518 519 if (request == null) { 520 throw new IllegalStateException ( 521 sm.getString("requestFacade.nullRequest")); 522 } 523 524 if (System.getSecurityManager() != null){ 525 return (Locale )AccessController.doPrivileged( 526 new GetLocalePrivilegedAction()); 527 } else { 528 return request.getLocale(); 529 } 530 } 531 532 533 public Enumeration getLocales() { 534 535 if (request == null) { 536 throw new IllegalStateException ( 537 sm.getString("requestFacade.nullRequest")); 538 } 539 540 if (System.getSecurityManager() != null){ 541 return (Enumeration )AccessController.doPrivileged( 542 new GetLocalesPrivilegedAction()); 543 } else { 544 return request.getLocales(); 545 } 546 } 547 548 549 public boolean isSecure() { 550 551 if (request == null) { 552 throw new IllegalStateException ( 553 sm.getString("requestFacade.nullRequest")); 554 } 555 556 return request.isSecure(); 557 } 558 559 560 public RequestDispatcher getRequestDispatcher(String path) { 561 562 if (request == null) { 563 throw new IllegalStateException ( 564 sm.getString("requestFacade.nullRequest")); 565 } 566 567 if (System.getSecurityManager() != null){ 568 return (RequestDispatcher )AccessController.doPrivileged( 569 new GetRequestDispatcherPrivilegedAction(path)); 570 } else { 571 return request.getRequestDispatcher(path); 572 } 573 } 574 575 public String getRealPath(String path) { 576 577 if (request == null) { 578 throw new IllegalStateException ( 579 sm.getString("requestFacade.nullRequest")); 580 } 581 582 return request.getRealPath(path); 583 } 584 585 586 public String getAuthType() { 587 588 if (request == null) { 589 throw new IllegalStateException ( 590 sm.getString("requestFacade.nullRequest")); 591 } 592 593 return request.getAuthType(); 594 } 595 596 597 public Cookie [] getCookies() { 598 599 if (request == null) { 600 throw new IllegalStateException ( 601 sm.getString("requestFacade.nullRequest")); 602 } 603 604 Cookie [] ret = null; 605 606 610 if (SecurityUtil.isPackageProtectionEnabled()){ 611 ret = (Cookie [])AccessController.doPrivileged( 612 new GetCookiesPrivilegedAction()); 613 if (ret != null) { 614 ret = (Cookie []) ret.clone(); 615 } 616 } else { 617 ret = request.getCookies(); 618 } 619 620 return ret; 621 } 622 623 624 public long getDateHeader(String name) { 625 626 if (request == null) { 627 throw new IllegalStateException ( 628 sm.getString("requestFacade.nullRequest")); 629 } 630 631 return request.getDateHeader(name); 632 } 633 634 635 public String getHeader(String name) { 636 637 if (request == null) { 638 throw new IllegalStateException ( 639 sm.getString("requestFacade.nullRequest")); 640 } 641 642 return request.getHeader(name); 643 } 644 645 646 public Enumeration getHeaders(String name) { 647 648 if (request == null) { 649 throw new IllegalStateException ( 650 sm.getString("requestFacade.nullRequest")); 651 } 652 653 if (System.getSecurityManager() != null){ 654 return (Enumeration )AccessController.doPrivileged( 655 new GetHeadersPrivilegedAction(name)); 656 } else { 657 return request.getHeaders(name); 658 } 659 } 660 661 662 public Enumeration getHeaderNames() { 663 664 if (request == null) { 665 throw new IllegalStateException ( 666 sm.getString("requestFacade.nullRequest")); 667 } 668 669 if (System.getSecurityManager() != null){ 670 return (Enumeration )AccessController.doPrivileged( 671 new GetHeaderNamesPrivilegedAction()); 672 } else { 673 return request.getHeaderNames(); 674 } 675 } 676 677 678 public int getIntHeader(String name) { 679 680 if (request == null) { 681 throw new IllegalStateException ( 682 sm.getString("requestFacade.nullRequest")); 683 } 684 685 return request.getIntHeader(name); 686 } 687 688 689 public String getMethod() { 690 691 if (request == null) { 692 throw new IllegalStateException ( 693 sm.getString("requestFacade.nullRequest")); 694 } 695 696 return request.getMethod(); 697 } 698 699 700 public String getPathInfo() { 701 702 if (request == null) { 703 throw new IllegalStateException ( 704 sm.getString("requestFacade.nullRequest")); 705 } 706 707 return request.getPathInfo(); 708 } 709 710 711 public String getPathTranslated() { 712 713 if (request == null) { 714 throw new IllegalStateException ( 715 sm.getString("requestFacade.nullRequest")); 716 } 717 718 return request.getPathTranslated(); 719 } 720 721 722 public String getContextPath() { 723 724 if (request == null) { 725 throw new IllegalStateException ( 726 sm.getString("requestFacade.nullRequest")); 727 } 728 729 return request.getContextPath(); 730 } 731 732 733 public String getQueryString() { 734 735 if (request == null) { 736 throw new IllegalStateException ( 737 sm.getString("requestFacade.nullRequest")); 738 } 739 740 return request.getQueryString(); 741 } 742 743 744 public String getRemoteUser() { 745 746 if (request == null) { 747 throw new IllegalStateException ( 748 sm.getString("requestFacade.nullRequest")); 749 } 750 751 return request.getRemoteUser(); 752 } 753 754 755 public boolean isUserInRole(String role) { 756 757 if (request == null) { 758 throw new IllegalStateException ( 759 sm.getString("requestFacade.nullRequest")); 760 } 761 762 return request.isUserInRole(role); 763 } 764 765 766 public java.security.Principal getUserPrincipal() { 767 768 if (request == null) { 769 throw new IllegalStateException ( 770 sm.getString("requestFacade.nullRequest")); 771 } 772 773 return request.getUserPrincipal(); 774 } 775 776 777 public String getRequestedSessionId() { 778 779 if (request == null) { 780 throw new IllegalStateException ( 781 sm.getString("requestFacade.nullRequest")); 782 } 783 784 return request.getRequestedSessionId(); 785 } 786 787 788 public String getRequestURI() { 789 790 if (request == null) { 791 throw new IllegalStateException ( 792 sm.getString("requestFacade.nullRequest")); 793 } 794 795 return request.getRequestURI(); 796 } 797 798 799 public StringBuffer getRequestURL() { 800 801 if (request == null) { 802 throw new IllegalStateException ( 803 sm.getString("requestFacade.nullRequest")); 804 } 805 806 return request.getRequestURL(); 807 } 808 809 810 public String getServletPath() { 811 812 if (request == null) { 813 throw new IllegalStateException ( 814 sm.getString("requestFacade.nullRequest")); 815 } 816 817 return request.getServletPath(); 818 } 819 820 821 public HttpSession getSession(boolean create) { 822 823 if (request == null) { 824 throw new IllegalStateException ( 825 sm.getString("requestFacade.nullRequest")); 826 } 827 828 if (SecurityUtil.isPackageProtectionEnabled()){ 829 return (HttpSession )AccessController. 830 doPrivileged(new GetSessionPrivilegedAction(create)); 831 } else { 832 return request.getSession(create); 833 } 834 } 835 836 public HttpSession getSession() { 837 838 if (request == null) { 839 throw new IllegalStateException ( 840 sm.getString("requestFacade.nullRequest")); 841 } 842 843 return getSession(true); 844 } 845 846 847 public boolean isRequestedSessionIdValid() { 848 849 if (request == null) { 850 throw new IllegalStateException ( 851 sm.getString("requestFacade.nullRequest")); 852 } 853 854 return request.isRequestedSessionIdValid(); 855 } 856 857 858 public boolean isRequestedSessionIdFromCookie() { 859 860 if (request == null) { 861 throw new IllegalStateException ( 862 sm.getString("requestFacade.nullRequest")); 863 } 864 865 return request.isRequestedSessionIdFromCookie(); 866 } 867 868 869 public boolean isRequestedSessionIdFromURL() { 870 871 if (request == null) { 872 throw new IllegalStateException ( 873 sm.getString("requestFacade.nullRequest")); 874 } 875 876 return request.isRequestedSessionIdFromURL(); 877 } 878 879 880 public boolean isRequestedSessionIdFromUrl() { 881 882 if (request == null) { 883 throw new IllegalStateException ( 884 sm.getString("requestFacade.nullRequest")); 885 } 886 887 return request.isRequestedSessionIdFromURL(); 888 } 889 890 891 public String getLocalAddr() { 892 893 if (request == null) { 894 throw new IllegalStateException ( 895 sm.getString("requestFacade.nullRequest")); 896 } 897 898 return request.getLocalAddr(); 899 } 900 901 902 public String getLocalName() { 903 904 if (request == null) { 905 throw new IllegalStateException ( 906 sm.getString("requestFacade.nullRequest")); 907 } 908 909 return request.getLocalName(); 910 } 911 912 913 public int getLocalPort() { 914 915 if (request == null) { 916 throw new IllegalStateException ( 917 sm.getString("requestFacade.nullRequest")); 918 } 919 920 return request.getLocalPort(); 921 } 922 923 924 public int getRemotePort() { 925 926 if (request == null) { 927 throw new IllegalStateException ( 928 sm.getString("requestFacade.nullRequest")); 929 } 930 931 return request.getRemotePort(); 932 } 933 934 } 935 | Popular Tags |