| 1 22 package org.jboss.metadata; 23 24 import java.net.URLClassLoader ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.HashMap ; 28 import java.util.HashSet ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.Set ; 33 34 import javax.management.MalformedObjectNameException ; 35 36 import org.jboss.deployment.DeploymentException; 37 import org.jboss.logging.Logger; 38 import org.jboss.metadata.web.ErrorPage; 39 import org.jboss.metadata.web.Filter; 40 import org.jboss.metadata.web.FilterMapping; 41 import org.jboss.metadata.web.LoginConfig; 42 import org.jboss.metadata.web.ParamValue; 43 import org.jboss.metadata.web.PassivationConfig; 44 import org.jboss.metadata.web.ReplicationConfig; 45 import org.jboss.metadata.web.Servlet; 46 import org.jboss.metadata.web.ServletMapping; 47 import org.jboss.metadata.web.SessionConfig; 48 import org.jboss.metamodel.descriptor.ResourceEnvRef; 49 import org.jboss.metamodel.descriptor.ResourceRef; 50 import org.jboss.mx.loading.LoaderRepositoryFactory; 51 import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig; 52 import org.jboss.mx.util.ObjectNameFactory; 53 import org.jboss.security.RunAsIdentity; 54 import org.jboss.webservice.metadata.serviceref.ServiceRefMetaData; 55 import org.w3c.dom.Element ; 56 57 67 public class WebMetaData extends MetaData 68 { 69 private static Logger log = Logger.getLogger(WebMetaData.class); 70 71 72 private String description; 73 74 private String displayName; 75 76 private String altDDPath; 77 78 private List <ParamValue> contextParams = new ArrayList <ParamValue>(); 79 80 private List <ParamValue> initParams = new ArrayList <ParamValue>(); 81 82 private HashMap <String , Servlet> servlets = new HashMap <String , Servlet>(); 83 84 private HashMap <String , ServletMapping> servletMappings = new HashMap <String , ServletMapping>(); 85 86 private HashMap <String , ResourceRefMetaData> resourceReferences = 87 new HashMap <String , ResourceRefMetaData>(); 88 89 private HashMap <String , ResourceEnvRefMetaData> resourceEnvReferences = 90 new HashMap <String , ResourceEnvRefMetaData>(); 91 92 private HashMap <String , MessageDestinationRefMetaData> messageDestinationReferences 93 = new HashMap <String , MessageDestinationRefMetaData>(); 94 95 private HashMap <String , MessageDestinationMetaData> messageDestinations = 96 new HashMap <String , MessageDestinationMetaData>(); 97 98 protected HashMap <String , Filter> filters = new HashMap <String , Filter>(); 99 100 protected HashMap <String , FilterMapping> filterMappings = 101 new HashMap <String , FilterMapping>(); 102 protected HashMap listeners = new HashMap (); 103 protected List <SessionConfig> sessionConfigs = new ArrayList <SessionConfig>(); 104 105 protected List <WebSecurityMetaData> securityConstraints = 106 new ArrayList <WebSecurityMetaData>(); 107 protected LoginConfig loginConfig; 108 protected HashMap <String , ErrorPage> errorPages = new HashMap <String , ErrorPage>(); 109 protected List <String > dependencies = new ArrayList <String >(); 110 protected ReplicationConfig replicationConfig; 111 protected PassivationConfig passivationConfig; 112 113 114 private ArrayList <EnvEntryMetaData> environmentEntries = new ArrayList <EnvEntryMetaData>(); 115 116 private HashMap <String , SecurityRoleMetaData> securityRoles = new HashMap <String , SecurityRoleMetaData>(); 117 118 private HashMap ejbReferences = new HashMap (); 119 120 private HashMap <String , EjbLocalRefMetaData> ejbLocalReferences = new HashMap <String , EjbLocalRefMetaData>(); 121 122 private HashMap serviceReferences = new HashMap (); 123 124 private HashMap securityRoleReferences = new HashMap (); 125 126 private HashMap runAsNames = new HashMap (); 127 128 private HashMap runAsIdentity = new HashMap (); 129 130 private boolean distributable = false; 131 132 private boolean java2ClassLoadingCompliance = false; 133 134 private LoaderRepositoryConfig loaderConfig; 135 136 private String contextRoot; 137 138 private String jaccContextID; 139 140 private ArrayList virtualHosts = new ArrayList (); 141 142 private String securityDomain; 143 144 private boolean flushOnSessionInvalidation; 145 146 private HashMap wsdlPublishLocationMap = new HashMap (); 147 148 private boolean webServiceDeployment; 149 150 private String configName; 151 152 private String configFile; 153 154 private ClassLoader encLoader; 155 156 private ClassLoader cxtLoader; 157 158 private ArrayList depends = new ArrayList (); 159 160 164 private HashMap arbitraryMetadata = new HashMap (); 165 166 public static final int SESSION_INVALIDATE_ACCESS =0; 167 public static final int SESSION_INVALIDATE_SET_AND_GET =1; 168 public static final int SESSION_INVALIDATE_SET_AND_NON_PRIMITIVE_GET =2; 169 public static final int SESSION_INVALIDATE_SET =3; 170 171 private int invalidateSessionPolicy = SESSION_INVALIDATE_SET_AND_NON_PRIMITIVE_GET; 172 173 public static final int REPLICATION_TYPE_SYNC = 0; 174 public static final int REPLICATION_TYPE_ASYNC = 1; 175 176 179 private int replicationType = REPLICATION_TYPE_SYNC; 180 181 185 public static final int REPLICATION_GRANULARITY_SESSION = 0; 186 public static final int REPLICATION_GRANULARITY_ATTRIBUTE = 1; 187 public static final int REPLICATION_GRANULARITY_FIELD = 2; 188 private int replicationGranularity = REPLICATION_GRANULARITY_SESSION; 189 190 194 private boolean replicationFieldBatchMode = true; 195 196 200 private boolean sessionPassivationMode = false; 201 202 207 private int sessionPassivationMinIdleTime = -1; 208 209 214 private int sessionPassivationMaxIdleTime = -1; 215 216 219 private int maxActiveSessions = -1; 220 221 222 223 private int sessionCookies = SESSION_COOKIES_DEFAULT; 224 225 public static final int SESSION_COOKIES_DEFAULT=0; 226 public static final int SESSION_COOKIES_ENABLED=1; 227 public static final int SESSION_COOKIES_DISABLED=2; 228 229 230 private URLClassLoader resourceCl; 231 232 public String getDescription() 233 { 234 return description; 235 } 236 237 public void setDescription(String description) 238 { 239 this.description = description; 240 } 241 242 public String getDisplayName() 243 { 244 return displayName; 245 } 246 247 public void setDisplayName(String displayName) 248 { 249 this.displayName = displayName; 250 } 251 252 public String getAltDDPath() 253 { 254 return altDDPath; 255 } 256 public void setAltDDPath(String altDDPath) 257 { 258 this.altDDPath = altDDPath; 259 } 260 261 public List <ParamValue> getContextParams() 262 { 263 return contextParams; 264 } 265 public void addContextParam(ParamValue pv) 266 { 267 contextParams.add(pv); 268 } 269 public List <ParamValue> getInitParams() 270 { 271 return initParams; 272 } 273 public void addInitParam(ParamValue pv) 274 { 275 initParams.add(pv); 276 } 277 278 public HashMap getArbitraryMetadata() 279 { 280 return arbitraryMetadata; 281 } 282 283 284 public void setResourceClassLoader(URLClassLoader resourceCl) 285 { 286 this.resourceCl = resourceCl; 287 } 288 289 public void addFilter(Filter filter) 290 { 291 filters.put(filter.getName(), filter); 292 } 293 294 public Collection getFilterMappings() 295 { 296 return filterMappings.values(); 297 } 298 299 public void addFilterMapping(FilterMapping mapping) 300 { 301 filterMappings.put(mapping.getFilterName(), mapping); 302 } 303 304 public Collection getListeners() 305 { 306 return listeners.values(); 307 } 308 309 public void addListener(Listener listener) 310 { 311 listeners.put(listener.getListenerClass(), listener); 312 } 313 314 public Collection getServlets() 315 { 316 return servlets.values(); 317 } 318 319 public void addServlet(Servlet servlet) 320 { 321 String servletName = servlet.getName(); 322 servlets.put(servletName, servlet); 323 } 324 325 public void updateServlet(Servlet updatedServlet) 326 { 327 Servlet servlet = (Servlet)servlets.get(updatedServlet.getName()); 328 if (servlet != null) 329 { 330 servlet.setRunAsPrincipals(updatedServlet.getRunAsPrincipals()); 331 } 332 else 333 { 334 servlets.put(updatedServlet.getName(), updatedServlet); 335 } 336 } 337 338 public Collection getServletMappings() 339 { 340 return servletMappings.values(); 341 } 342 343 public void addServletMapping(ServletMapping mapping) 344 { 345 servletMappings.put(mapping.getName(), mapping); 346 } 347 348 public Collection getSessionConfigs() 349 { 350 return sessionConfigs; 351 } 352 353 public void addSessionConfig(SessionConfig config) 354 { 355 sessionConfigs.add(config); 356 } 357 358 public void addSecurityRole(SecurityRoleMetaData securityRole) 359 { 360 securityRoles.put(securityRole.getRoleName(), securityRole); 361 } 362 363 public void updateSecurityRole(SecurityRoleMetaData updatedRole) 364 { 365 SecurityRoleMetaData role = securityRoles.get(updatedRole.getRoleName()); 366 if (role != null) 367 { 368 role.setRoleName(updatedRole.getRoleName()); 369 } 370 else 371 { 372 securityRoles.put(updatedRole.getRoleName(), updatedRole); 373 } 374 } 375 376 public Collection getSecurityConstraints() 377 { 378 return securityConstraints; 379 } 380 381 public void addSecurityConstraint(WebSecurityMetaData constraint) 382 { 383 securityConstraints.add(constraint); 384 } 385 386 public LoginConfig getLoginConfig() 387 { 388 return loginConfig; 389 } 390 391 public void setLoginConfig(LoginConfig loginConfig) 392 { 393 this.loginConfig = loginConfig; 394 } 395 396 public Collection getErrorPages() 397 { 398 return errorPages.values(); 399 } 400 401 public void addErrorPage(ErrorPage errorPage) 402 { 403 errorPages.put(errorPage.getErrorCode(), errorPage); 404 } 405 406 public Collection getMessageDestinations() 407 { 408 return messageDestinations.values(); 409 } 410 411 public void addEjbLocalRef(EjbLocalRefMetaData ref) 412 { 413 this.ejbLocalReferences.put(ref.getName(), ref); 414 } 415 public void addEjbRef(EjbRefMetaData ref) 416 { 417 this.ejbReferences.put(ref.getName(), ref); 418 } 419 public void addEnvEntry(EnvEntryMetaData ref) 420 { 421 this.environmentEntries.add(ref); 422 } 423 public void addMessageDestinationRef(MessageDestinationRefMetaData ref) 424 { 425 this.messageDestinationReferences.put(ref.getRefName(), ref); 426 } 427 public void addMessageDestination(MessageDestinationMetaData destination) 428 { 429 log.debug("addMessageDestination, "+destination); 430 messageDestinations.put(destination.getName(), destination); 431 } 432 public void updateMessageDestination(MessageDestinationMetaData updatedDestination) 433 { 434 MessageDestinationMetaData destination = (MessageDestinationMetaData) 435 messageDestinations.get(updatedDestination.getName()); 436 if (destination != null) 437 { 438 destination.setJNDIName(updatedDestination.getMappedName()); 439 } 440 else 441 { 442 messageDestinations.put(updatedDestination.getName(), updatedDestination); 443 } 444 } 445 public void addResourceEnvRef(ResourceEnvRefMetaData ref) 446 { 447 this.resourceEnvReferences.put(ref.getRefName(), ref); 448 } 449 public void updateResourceEnvRef(ResourceEnvRefMetaData updatedRef) 450 { 451 ResourceEnvRefMetaData ref = (ResourceEnvRefMetaData)resourceEnvReferences.get(updatedRef.getRefName()); 452 if (ref != null) 453 { 454 ref.setJndiName(updatedRef.getJndiName()); 455 } 456 else 457 { 458 this.addResourceEnvRef(updatedRef); 459 } 460 } 461 462 public void addResourceRef(ResourceRefMetaData ref) 463 { 464 this.resourceReferences.put(ref.getRefName(), ref); 465 } 466 public void updateResourceRef(ResourceRefMetaData updatedRef) 467 { 468 ResourceRefMetaData ref = (ResourceRefMetaData)resourceReferences.get(updatedRef.getRefName()); 469 if (ref != null) 470 { 471 ref.setJndiName(updatedRef.getJndiName()); 472 ref.setResURL(updatedRef.getResURL()); 473 ref.setResourceName(updatedRef.getResourceName()); 474 } 475 else 476 { 477 this.addResourceRef(updatedRef); 478 } 479 } 480 481 public void addDependency(String depends) 482 { 483 dependencies.add(depends); 484 } 485 486 public Collection <String > getDependencies() 487 { 488 return dependencies; 489 } 490 491 public ReplicationConfig getReplicationConfig() 492 { 493 return replicationConfig; 494 } 495 496 public void setReplicationConfig(ReplicationConfig replicationConfig) 497 { 498 this.replicationConfig = replicationConfig; 499 } 500 501 public PassivationConfig getPassivationConfig() 502 { 503 return passivationConfig; 504 } 505 506 public void setPassivationConfig(PassivationConfig passivationConfig) 507 { 508 this.passivationConfig = passivationConfig; 509 } 510 511 514 public Iterator <EnvEntryMetaData> getEnvironmentEntries() 515 { 516 return environmentEntries.iterator(); 517 } 518 522 public void setEnvironmentEntries(Collection environmentEntries) 523 { 524 this.environmentEntries.clear(); 525 this.environmentEntries.addAll(environmentEntries); 526 } 527 528 531 public Iterator getEjbReferences() 532 { 533 return ejbReferences.values().iterator(); 534 } 535 539 public void setEjbReferences(Map ejbReferences) 540 { 541 this.ejbReferences.clear(); 542 this.ejbReferences.putAll(ejbReferences); 543 } 544 545 548 public Iterator <EjbLocalRefMetaData> getEjbLocalReferences() 549 { 550 return ejbLocalReferences.values().iterator(); 551 } 552 public Map <String , EjbLocalRefMetaData> getEjbLocalReferenceMap() 553 { 554 return ejbLocalReferences; 555 } 556 560 public void setEjbLocalReferences(Map ejbReferences) 561 { 562 this.ejbLocalReferences.clear(); 563 this.ejbLocalReferences.putAll(ejbReferences); 564 } 565 566 569 public Iterator getResourceReferences() 570 { 571 return resourceReferences.values().iterator(); 572 } 573 577 public void setResourceReferences(Map resourceReferences) 578 { 579 this.resourceReferences.clear(); 580 this.resourceReferences.putAll(resourceReferences); 581 } 582 583 586 public Iterator getResourceEnvReferences() 587 { 588 return resourceEnvReferences.values().iterator(); 589 } 590 594 public void setResourceEnvReferences(Map resourceReferences) 595 { 596 this.resourceEnvReferences.clear(); 597 this.resourceEnvReferences.putAll(resourceReferences); 598 } 599 600 605 public Iterator getMessageDestinationReferences() 606 { 607 return messageDestinationReferences.values().iterator(); 608 } 609 613 public void setMessageDestinationReferences(Map messageDestinationReferences) 614 { 615 this.messageDestinationReferences.clear(); 616 this.messageDestinationReferences.putAll(messageDestinationReferences); 617 } 618 619 625 public MessageDestinationMetaData getMessageDestination(String name) 626 { 627 return (MessageDestinationMetaData) messageDestinations.get(name); 628 } 629 633 public void setMessageDestination(Map messageDestinations) 634 { 635 this.messageDestinations.clear(); 636 this.messageDestinations.putAll(messageDestinations); 637 } 638 639 642 public Iterator getServiceReferences() 643 { 644 return serviceReferences.values().iterator(); 645 } 646 650 public void setServiceReferences(Map serviceReferences) 651 { 652 this.serviceReferences.clear(); 653 this.serviceReferences.putAll(serviceReferences); 654 } 655 656 659 public String getContextRoot() 660 { 661 return contextRoot; 662 } 663 public void setContextRoot(String contextRoot) 664 { 665 this.contextRoot = contextRoot; 666 } 667 668 public String getConfigFile() 669 { 670 return configFile; 671 } 672 673 public void setConfigFile(String configFile) 674 { 675 this.configFile = configFile; 676 } 677 678 public String getConfigName() 679 { 680 return configName; 681 } 682 683 public void setConfigName(String configName) 684 { 685 this.configName = configName; 686 } 687 688 public HashMap getWsdlPublishLocations() 689 { 690 return wsdlPublishLocationMap; 691 } 692 693 694 public String getWsdlPublishLocationByName(String name) 695 { 696 return (String )wsdlPublishLocationMap.get(name); 697 } 698 702 public void setWsdlPublishLocationMap(Map wsdlPublishLocationMap) 703 { 704 this.wsdlPublishLocationMap.clear(); 705 this.wsdlPublishLocationMap.putAll(wsdlPublishLocationMap); 706 } 707 708 public boolean isWebServiceDeployment() 709 { 710 return webServiceDeployment; 711 } 712 713 public void setWebServiceDeployment(boolean webServiceDeployment) 714 { 715 this.webServiceDeployment = webServiceDeployment; 716 } 717 718 public String getJaccContextID() 719 { 720 return jaccContextID; 721 } 722 public void setJaccContextID(String jaccContextID) 723 { 724 this.jaccContextID = jaccContextID; 725 } 726 727 733 public String getSecurityDomain() 734 { 735 return securityDomain; 736 } 737 738 740 public void setSecurityDomain(String securityDomain) 741 { 742 this.securityDomain = securityDomain; 743 } 744 745 749 public boolean isFlushOnSessionInvalidation() 750 { 751 return flushOnSessionInvalidation; 752 } 753 757 public void setFlushOnSessionInvalidation(boolean flag) 758 { 759 this.flushOnSessionInvalidation = flag; 760 } 761 762 764 public Iterator <WebSecurityMetaData> getSecurityContraints() 765 { 766 return securityConstraints.iterator(); 767 } 768 769 773 public void setSecurityConstraints(Collection <WebSecurityMetaData> securityContraints) 774 { 775 this.securityConstraints.clear(); 776 this.securityConstraints.addAll(securityContraints); 777 } 778 779 782 public Map getSecurityRoleRefs() 783 { 784 return this.securityRoleReferences; 785 } 786 791 public List getSecurityRoleRefs(String servletName) 792 { 793 List roles = (List ) this.securityRoleReferences.get(servletName); 794 return roles; 795 } 796 800 public void setSecurityRoleReferences(Map securityRoleReferences) 801 { 802 this.securityRoleReferences.clear(); 803 this.securityRoleReferences.putAll(securityRoleReferences); 804 } 805 806 810 public Set getSecurityRoleNames() 811 { 812 return new HashSet (securityRoles.keySet()); 813 } 814 815 818 public Map getSecurityRoles() 819 { 820 return new HashMap (securityRoles); 821 } 822 826 public void setSecurityRoles(Map securityRoles) 827 { 828 this.securityRoles.clear(); 829 this.securityRoles.putAll(securityRoles); 830 } 831 832 837 public Set getSecurityRoleNamesByPrincipal(String userName) 838 { 839 HashSet roleNames = new HashSet (); 840 Iterator it = securityRoles.values().iterator(); 841 while (it.hasNext()) 842 { 843 SecurityRoleMetaData srMetaData = (SecurityRoleMetaData) it.next(); 844 if (srMetaData.getPrincipals().contains(userName)) 845 roleNames.add(srMetaData.getRoleName()); 846 } 847 return roleNames; 848 } 849 850 855 public Map getPrincipalVersusRolesMap() 856 { 857 Map principalRolesMap = null; 858 859 |