1 23 24 28 29 package com.sun.enterprise.config.serverbeans; 30 31 import org.w3c.dom.*; 32 import org.netbeans.modules.schema2beans.*; 33 import java.beans.*; 34 import java.util.*; 35 import java.io.Serializable ; 36 import com.sun.enterprise.config.ConfigBean; 37 import com.sun.enterprise.config.ConfigException; 38 import com.sun.enterprise.config.StaleWriteConfigException; 39 import com.sun.enterprise.util.i18n.StringManager; 40 41 43 public class SecurityService extends ConfigBean implements Serializable 44 { 45 46 static Vector comparators = new Vector(); 47 private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(4, 2, 0); 48 49 static public final String AUTH_REALM = "AuthRealm"; 50 static public final String JACC_PROVIDER = "JaccProvider"; 51 static public final String AUDIT_MODULE = "AuditModule"; 52 static public final String MESSAGE_SECURITY_CONFIG = "MessageSecurityConfig"; 53 static public final String ELEMENT_PROPERTY = "ElementProperty"; 54 55 public SecurityService() { 56 this(Common.USE_DEFAULT_VALUES); 57 } 58 59 public SecurityService(int options) 60 { 61 super(comparators, runtimeVersion); 62 initPropertyTables(5); 64 this.createProperty("auth-realm", AUTH_REALM, 65 Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY, 66 AuthRealm.class); 67 this.createAttribute(AUTH_REALM, "name", "Name", 68 AttrProp.CDATA | AttrProp.REQUIRED, 69 null, null); 70 this.createAttribute(AUTH_REALM, "classname", "Classname", 71 AttrProp.CDATA | AttrProp.REQUIRED, 72 null, null); 73 this.createProperty("jacc-provider", JACC_PROVIDER, 74 Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY, 75 JaccProvider.class); 76 this.createAttribute(JACC_PROVIDER, "name", "Name", 77 AttrProp.CDATA | AttrProp.REQUIRED, 78 null, null); 79 this.createAttribute(JACC_PROVIDER, "policy-provider", "PolicyProvider", 80 AttrProp.CDATA | AttrProp.REQUIRED, 81 null, null); 82 this.createAttribute(JACC_PROVIDER, "policy-configuration-factory-provider", "PolicyConfigurationFactoryProvider", 83 AttrProp.CDATA | AttrProp.REQUIRED, 84 null, null); 85 this.createProperty("audit-module", AUDIT_MODULE, 86 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 87 AuditModule.class); 88 this.createAttribute(AUDIT_MODULE, "name", "Name", 89 AttrProp.CDATA | AttrProp.REQUIRED, 90 null, null); 91 this.createAttribute(AUDIT_MODULE, "classname", "Classname", 92 AttrProp.CDATA | AttrProp.REQUIRED, 93 null, null); 94 this.createProperty("message-security-config", MESSAGE_SECURITY_CONFIG, 95 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 96 MessageSecurityConfig.class); 97 this.createAttribute(MESSAGE_SECURITY_CONFIG, "auth-layer", "AuthLayer", 98 AttrProp.CDATA | AttrProp.REQUIRED, 99 null, null); 100 this.createAttribute(MESSAGE_SECURITY_CONFIG, "default-provider", "DefaultProvider", 101 AttrProp.CDATA | AttrProp.IMPLIED, 102 null, null); 103 this.createAttribute(MESSAGE_SECURITY_CONFIG, "default-client-provider", "DefaultClientProvider", 104 AttrProp.CDATA | AttrProp.IMPLIED, 105 null, null); 106 this.createProperty("property", ELEMENT_PROPERTY, 107 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 108 ElementProperty.class); 109 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 110 AttrProp.CDATA | AttrProp.REQUIRED, 111 null, null); 112 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 113 AttrProp.CDATA | AttrProp.REQUIRED, 114 null, null); 115 this.initialize(options); 116 } 117 118 void initialize(int options) { 120 121 } 122 123 public void setAuthRealm(int index, AuthRealm value) { 125 this.setValue(AUTH_REALM, index, value); 126 } 127 128 public AuthRealm getAuthRealm(int index) { 130 return (AuthRealm)this.getValue(AUTH_REALM, index); 131 } 132 133 public void setAuthRealm(AuthRealm[] value) { 135 this.setValue(AUTH_REALM, value); 136 } 137 138 public AuthRealm[] getAuthRealm() { 140 return (AuthRealm[])this.getValues(AUTH_REALM); 141 } 142 143 public int sizeAuthRealm() { 145 return this.size(AUTH_REALM); 146 } 147 148 public int addAuthRealm(AuthRealm value) 150 throws ConfigException{ 151 return addAuthRealm(value, true); 152 } 153 154 public int addAuthRealm(AuthRealm value, boolean overwrite) 156 throws ConfigException{ 157 AuthRealm old = getAuthRealmByName(value.getName()); 158 if(old != null) { 159 throw new ConfigException(StringManager.getManager(SecurityService.class).getString("cannotAddDuplicate", "AuthRealm")); 160 } 161 return this.addValue(AUTH_REALM, value, overwrite); 162 } 163 164 public int removeAuthRealm(AuthRealm value){ 169 return this.removeValue(AUTH_REALM, value); 170 } 171 172 public int removeAuthRealm(AuthRealm value, boolean overwrite) 178 throws StaleWriteConfigException{ 179 return this.removeValue(AUTH_REALM, value, overwrite); 180 } 181 182 public AuthRealm getAuthRealmByName(String id) { 183 if (null != id) { id = id.trim(); } 184 AuthRealm[] o = getAuthRealm(); 185 if (o == null) return null; 186 187 for (int i=0; i < o.length; i++) { 188 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 189 return o[i]; 190 } 191 } 192 193 return null; 194 195 } 196 public void setJaccProvider(int index, JaccProvider value) { 198 this.setValue(JACC_PROVIDER, index, value); 199 } 200 201 public JaccProvider getJaccProvider(int index) { 203 return (JaccProvider)this.getValue(JACC_PROVIDER, index); 204 } 205 206 public void setJaccProvider(JaccProvider[] value) { 208 this.setValue(JACC_PROVIDER, value); 209 } 210 211 public JaccProvider[] getJaccProvider() { 213 return (JaccProvider[])this.getValues(JACC_PROVIDER); 214 } 215 216 public int sizeJaccProvider() { 218 return this.size(JACC_PROVIDER); 219 } 220 221 public int addJaccProvider(JaccProvider value) 223 throws ConfigException{ 224 return addJaccProvider(value, true); 225 } 226 227 public int addJaccProvider(JaccProvider value, boolean overwrite) 229 throws ConfigException{ 230 JaccProvider old = getJaccProviderByName(value.getName()); 231 if(old != null) { 232 throw new ConfigException(StringManager.getManager(SecurityService.class).getString("cannotAddDuplicate", "JaccProvider")); 233 } 234 return this.addValue(JACC_PROVIDER, value, overwrite); 235 } 236 237 public int removeJaccProvider(JaccProvider value){ 242 return this.removeValue(JACC_PROVIDER, value); 243 } 244 245 public int removeJaccProvider(JaccProvider value, boolean overwrite) 251 throws StaleWriteConfigException{ 252 return this.removeValue(JACC_PROVIDER, value, overwrite); 253 } 254 255 public JaccProvider getJaccProviderByName(String id) { 256 if (null != id) { id = id.trim(); } 257 JaccProvider[] o = getJaccProvider(); 258 if (o == null) return null; 259 260 for (int i=0; i < o.length; i++) { 261 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 262 return o[i]; 263 } 264 } 265 266 return null; 267 268 } 269 public void setAuditModule(int index, AuditModule value) { 271 this.setValue(AUDIT_MODULE, index, value); 272 } 273 274 public AuditModule getAuditModule(int index) { 276 return (AuditModule)this.getValue(AUDIT_MODULE, index); 277 } 278 279 public void setAuditModule(AuditModule[] value) { 281 this.setValue(AUDIT_MODULE, value); 282 } 283 284 public AuditModule[] getAuditModule() { 286 return (AuditModule[])this.getValues(AUDIT_MODULE); 287 } 288 289 public int sizeAuditModule() { 291 return this.size(AUDIT_MODULE); 292 } 293 294 public int addAuditModule(AuditModule value) 296 throws ConfigException{ 297 return addAuditModule(value, true); 298 } 299 300 public int addAuditModule(AuditModule value, boolean overwrite) 302 throws ConfigException{ 303 AuditModule old = getAuditModuleByName(value.getName()); 304 if(old != null) { 305 throw new ConfigException(StringManager.getManager(SecurityService.class).getString("cannotAddDuplicate", "AuditModule")); 306 } 307 return this.addValue(AUDIT_MODULE, value, overwrite); 308 } 309 310 public int removeAuditModule(AuditModule value){ 315 return this.removeValue(AUDIT_MODULE, value); 316 } 317 318 public int removeAuditModule(AuditModule value, boolean overwrite) 324 throws StaleWriteConfigException{ 325 return this.removeValue(AUDIT_MODULE, value, overwrite); 326 } 327 328 public AuditModule getAuditModuleByName(String id) { 329 if (null != id) { id = id.trim(); } 330 AuditModule[] o = getAuditModule(); 331 if (o == null) return null; 332 333 for (int i=0; i < o.length; i++) { 334 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 335 return o[i]; 336 } 337 } 338 339 return null; 340 341 } 342 public void setMessageSecurityConfig(int index, MessageSecurityConfig value) { 344 this.setValue(MESSAGE_SECURITY_CONFIG, index, value); 345 } 346 347 public MessageSecurityConfig getMessageSecurityConfig(int index) { 349 return (MessageSecurityConfig)this.getValue(MESSAGE_SECURITY_CONFIG, index); 350 } 351 352 public void setMessageSecurityConfig(MessageSecurityConfig[] value) { 354 this.setValue(MESSAGE_SECURITY_CONFIG, value); 355 } 356 357 public MessageSecurityConfig[] getMessageSecurityConfig() { 359 return (MessageSecurityConfig[])this.getValues(MESSAGE_SECURITY_CONFIG); 360 } 361 362 public int sizeMessageSecurityConfig() { 364 return this.size(MESSAGE_SECURITY_CONFIG); 365 } 366 367 public int addMessageSecurityConfig(MessageSecurityConfig value) 369 throws ConfigException{ 370 return addMessageSecurityConfig(value, true); 371 } 372 373 public int addMessageSecurityConfig(MessageSecurityConfig value, boolean overwrite) 375 throws ConfigException{ 376 MessageSecurityConfig old = getMessageSecurityConfigByAuthLayer(value.getAuthLayer()); 377 if(old != null) { 378 throw new ConfigException(StringManager.getManager(SecurityService.class).getString("cannotAddDuplicate", "MessageSecurityConfig")); 379 } 380 return this.addValue(MESSAGE_SECURITY_CONFIG, value, overwrite); 381 } 382 383 public int removeMessageSecurityConfig(MessageSecurityConfig value){ 388 return this.removeValue(MESSAGE_SECURITY_CONFIG, value); 389 } 390 391 public int removeMessageSecurityConfig(MessageSecurityConfig value, boolean overwrite) 397 throws StaleWriteConfigException{ 398 return this.removeValue(MESSAGE_SECURITY_CONFIG, value, overwrite); 399 } 400 401 public MessageSecurityConfig getMessageSecurityConfigByAuthLayer(String id) { 402 if (null != id) { id = id.trim(); } 403 MessageSecurityConfig[] o = getMessageSecurityConfig(); 404 if (o == null) return null; 405 406 for (int i=0; i < o.length; i++) { 407 if(o[i].getAttributeValue(Common.convertName(ServerTags.AUTH_LAYER)).equals(id)) { 408 return o[i]; 409 } 410 } 411 412 return null; 413 414 } 415 public void setElementProperty(int index, ElementProperty value) { 417 this.setValue(ELEMENT_PROPERTY, index, value); 418 } 419 420 public ElementProperty getElementProperty(int index) { 422 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 423 } 424 425 public void setElementProperty(ElementProperty[] value) { 427 this.setValue(ELEMENT_PROPERTY, value); 428 } 429 430 public ElementProperty[] getElementProperty() { 432 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 433 } 434 435 public int sizeElementProperty() { 437 return this.size(ELEMENT_PROPERTY); 438 } 439 440 public int addElementProperty(ElementProperty value) 442 throws ConfigException{ 443 return addElementProperty(value, true); 444 } 445 446 public int addElementProperty(ElementProperty value, boolean overwrite) 448 throws ConfigException{ 449 ElementProperty old = getElementPropertyByName(value.getName()); 450 if(old != null) { 451 throw new ConfigException(StringManager.getManager(SecurityService.class).getString("cannotAddDuplicate", "ElementProperty")); 452 } 453 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 454 } 455 456 public int removeElementProperty(ElementProperty value){ 461 return this.removeValue(ELEMENT_PROPERTY, value); 462 } 463 464 public int removeElementProperty(ElementProperty value, boolean overwrite) 470 throws StaleWriteConfigException{ 471 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 472 } 473 474 public ElementProperty getElementPropertyByName(String id) { 475 if (null != id) { id = id.trim(); } 476 ElementProperty[] o = getElementProperty(); 477 if (o == null) return null; 478 479 for (int i=0; i < o.length; i++) { 480 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 481 return o[i]; 482 } 483 } 484 485 return null; 486 487 } 488 492 public String getDefaultRealm() { 493 return getAttributeValue(ServerTags.DEFAULT_REALM); 494 } 495 500 public void setDefaultRealm(String v, boolean overwrite) throws StaleWriteConfigException { 501 setAttributeValue(ServerTags.DEFAULT_REALM, v, overwrite); 502 } 503 507 public void setDefaultRealm(String v) { 508 setAttributeValue(ServerTags.DEFAULT_REALM, v); 509 } 510 513 public static String getDefaultDefaultRealm() { 514 return "file".trim(); 515 } 516 520 public String getDefaultPrincipal() { 521 return getAttributeValue(ServerTags.DEFAULT_PRINCIPAL); 522 } 523 528 public void setDefaultPrincipal(String v, boolean overwrite) throws StaleWriteConfigException { 529 setAttributeValue(ServerTags.DEFAULT_PRINCIPAL, v, overwrite); 530 } 531 535 public void setDefaultPrincipal(String v) { 536 setAttributeValue(ServerTags.DEFAULT_PRINCIPAL, v); 537 } 538 542 public String getDefaultPrincipalPassword() { 543 return getAttributeValue(ServerTags.DEFAULT_PRINCIPAL_PASSWORD); 544 } 545 550 public void setDefaultPrincipalPassword(String v, boolean overwrite) throws StaleWriteConfigException { 551 setAttributeValue(ServerTags.DEFAULT_PRINCIPAL_PASSWORD, v, overwrite); 552 } 553 557 public void setDefaultPrincipalPassword(String v) { 558 setAttributeValue(ServerTags.DEFAULT_PRINCIPAL_PASSWORD, v); 559 } 560 564 public String getAnonymousRole() { 565 return getAttributeValue(ServerTags.ANONYMOUS_ROLE); 566 } 567 572 public void setAnonymousRole(String v, boolean overwrite) throws StaleWriteConfigException { 573 setAttributeValue(ServerTags.ANONYMOUS_ROLE, v, overwrite); 574 } 575 579 public void setAnonymousRole(String v) { 580 setAttributeValue(ServerTags.ANONYMOUS_ROLE, v); 581 } 582 585 public static String getDefaultAnonymousRole() { 586 return "ANYONE".trim(); 587 } 588 592 public boolean isAuditEnabled() { 593 return toBoolean(getAttributeValue(ServerTags.AUDIT_ENABLED)); 594 } 595 600 public void setAuditEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 601 setAttributeValue(ServerTags.AUDIT_ENABLED, ""+(v==true), overwrite); 602 } 603 607 public void setAuditEnabled(boolean v) { 608 setAttributeValue(ServerTags.AUDIT_ENABLED, ""+(v==true)); 609 } 610 613 public static String getDefaultAuditEnabled() { 614 return "false".trim(); 615 } 616 620 public String getJacc() { 621 return getAttributeValue(ServerTags.JACC); 622 } 623 628 public void setJacc(String v, boolean overwrite) throws StaleWriteConfigException { 629 setAttributeValue(ServerTags.JACC, v, overwrite); 630 } 631 635 public void setJacc(String v) { 636 setAttributeValue(ServerTags.JACC, v); 637 } 638 641 public static String getDefaultJacc() { 642 return "default".trim(); 643 } 644 648 public String getAuditModules() { 649 return getAttributeValue(ServerTags.AUDIT_MODULES); 650 } 651 656 public void setAuditModules(String v, boolean overwrite) throws StaleWriteConfigException { 657 setAttributeValue(ServerTags.AUDIT_MODULES, v, overwrite); 658 } 659 663 public void setAuditModules(String v) { 664 setAttributeValue(ServerTags.AUDIT_MODULES, v); 665 } 666 669 public static String getDefaultAuditModules() { 670 return "default".trim(); 671 } 672 676 public boolean isActivateDefaultPrincipalToRoleMapping() { 677 return toBoolean(getAttributeValue(ServerTags.ACTIVATE_DEFAULT_PRINCIPAL_TO_ROLE_MAPPING)); 678 } 679 684 public void setActivateDefaultPrincipalToRoleMapping(boolean v, boolean overwrite) throws StaleWriteConfigException { 685 setAttributeValue(ServerTags.ACTIVATE_DEFAULT_PRINCIPAL_TO_ROLE_MAPPING, ""+(v==true), overwrite); 686 } 687 691 public void setActivateDefaultPrincipalToRoleMapping(boolean v) { 692 setAttributeValue(ServerTags.ACTIVATE_DEFAULT_PRINCIPAL_TO_ROLE_MAPPING, ""+(v==true)); 693 } 694 697 public static String getDefaultActivateDefaultPrincipalToRoleMapping() { 698 return "false".trim(); 699 } 700 704 public String getMappedPrincipalClass() { 705 return getAttributeValue(ServerTags.MAPPED_PRINCIPAL_CLASS); 706 } 707 712 public void setMappedPrincipalClass(String v, boolean overwrite) throws StaleWriteConfigException { 713 setAttributeValue(ServerTags.MAPPED_PRINCIPAL_CLASS, v, overwrite); 714 } 715 719 public void setMappedPrincipalClass(String v) { 720 setAttributeValue(ServerTags.MAPPED_PRINCIPAL_CLASS, v); 721 } 722 726 public AuthRealm newAuthRealm() { 727 return new AuthRealm(); 728 } 729 730 734 public JaccProvider newJaccProvider() { 735 return new JaccProvider(); 736 } 737 738 742 public AuditModule newAuditModule() { 743 return new AuditModule(); 744 } 745 746 750 public MessageSecurityConfig newMessageSecurityConfig() { 751 return new MessageSecurityConfig(); 752 } 753 754 758 public ElementProperty newElementProperty() { 759 return new ElementProperty(); 760 } 761 762 767 protected String getRelativeXPath() { 768 String ret = null; 769 ret = "security-service"; 770 return (null != ret ? ret.trim() : null); 771 } 772 773 776 public static String getDefaultAttributeValue(String attr) { 777 if(attr == null) return null; 778 attr = attr.trim(); 779 if(attr.equals(ServerTags.DEFAULT_REALM)) return "file".trim(); 780 if(attr.equals(ServerTags.ANONYMOUS_ROLE)) return "ANYONE".trim(); 781 if(attr.equals(ServerTags.AUDIT_ENABLED)) return "false".trim(); 782 if(attr.equals(ServerTags.JACC)) return "default".trim(); 783 if(attr.equals(ServerTags.AUDIT_MODULES)) return "default".trim(); 784 if(attr.equals(ServerTags.ACTIVATE_DEFAULT_PRINCIPAL_TO_ROLE_MAPPING)) return "false".trim(); 785 return null; 786 } 787 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 789 comparators.add(c); 790 } 791 792 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 794 comparators.remove(c); 795 } 796 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 797 } 798 799 public void dump(StringBuffer str, String indent){ 801 String s; 802 Object o; 803 org.netbeans.modules.schema2beans.BaseBean n; 804 str.append(indent); 805 str.append("AuthRealm["+this.sizeAuthRealm()+"]"); for(int i=0; i<this.sizeAuthRealm(); i++) 807 { 808 str.append(indent+"\t"); 809 str.append("#"+i+":"); 810 n = (org.netbeans.modules.schema2beans.BaseBean) this.getAuthRealm(i); 811 if (n != null) 812 n.dump(str, indent + "\t"); else 814 str.append(indent+"\tnull"); this.dumpAttributes(AUTH_REALM, i, str, indent); 816 } 817 818 str.append(indent); 819 str.append("JaccProvider["+this.sizeJaccProvider()+"]"); for(int i=0; i<this.sizeJaccProvider(); i++) 821 { 822 str.append(indent+"\t"); 823 str.append("#"+i+":"); 824 n = (org.netbeans.modules.schema2beans.BaseBean) this.getJaccProvider(i); 825 if (n != null) 826 n.dump(str, indent + "\t"); else 828 str.append(indent+"\tnull"); this.dumpAttributes(JACC_PROVIDER, i, str, indent); 830 } 831 832 str.append(indent); 833 str.append("AuditModule["+this.sizeAuditModule()+"]"); for(int i=0; i<this.sizeAuditModule(); i++) 835 { 836 str.append(indent+"\t"); 837 str.append("#"+i+":"); 838 n = (org.netbeans.modules.schema2beans.BaseBean) this.getAuditModule(i); 839 if (n != null) 840 n.dump(str, indent + "\t"); else 842 str.append(indent+"\tnull"); this.dumpAttributes(AUDIT_MODULE, i, str, indent); 844 } 845 846 str.append(indent); 847 str.append("MessageSecurityConfig["+this.sizeMessageSecurityConfig()+"]"); for(int i=0; i<this.sizeMessageSecurityConfig(); i++) 849 { 850 str.append(indent+"\t"); 851 str.append("#"+i+":"); 852 n = (org.netbeans.modules.schema2beans.BaseBean) this.getMessageSecurityConfig(i); 853 if (n != null) 854 n.dump(str, indent + "\t"); else 856 str.append(indent+"\tnull"); this.dumpAttributes(MESSAGE_SECURITY_CONFIG, i, str, indent); 858 } 859 860 str.append(indent); 861 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 863 { 864 str.append(indent+"\t"); 865 str.append("#"+i+":"); 866 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 867 if (n != null) 868 n.dump(str, indent + "\t"); else 870 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 872 } 873 874 } 875 public String dumpBeanNode(){ 876 StringBuffer str = new StringBuffer (); 877 str.append("SecurityService\n"); this.dump(str, "\n "); return str.toString(); 880 }} 881 882 884 | Popular Tags |