1 23 24 28 29 package com.sun.enterprise.admin.mbeans; 30 31 import java.util.Properties ; 33 import java.util.Set ; 34 import java.util.StringTokenizer ; 35 import java.util.ArrayList ; 36 37 38 import javax.management.Attribute ; 40 import javax.management.AttributeList ; 41 import javax.management.ObjectName ; 42 import javax.management.MBeanException ; 43 import javax.management.MBeanServerFactory ; 44 import javax.management.MBeanServer ; 45 import javax.management.modelmbean.ModelMBeanOperationInfo ; 46 import javax.management.MBeanInfo ; 47 48 import com.sun.enterprise.config.ConfigContext; 50 import com.sun.enterprise.config.ConfigBeansFactory; 51 import com.sun.enterprise.config.ConfigException; 52 import com.sun.enterprise.config.serverbeans.SecurityMap; 53 import com.sun.enterprise.config.serverbeans.BackendPrincipal; 54 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 55 import com.sun.enterprise.config.serverbeans.Resources; 56 57 import com.sun.enterprise.admin.MBeanHelper; 58 import com.sun.enterprise.admin.config.BaseConfigMBean; 59 import com.sun.enterprise.admin.config.ConfigBeanHelper; 60 import com.sun.enterprise.admin.server.core.AdminService; 61 import com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor; 62 import com.sun.enterprise.config.serverbeans.ServerTags; 63 import com.sun.enterprise.admin.meta.MBeanRegistry; 64 import com.sun.enterprise.util.i18n.StringManager; 65 66 import com.sun.enterprise.admin.mbeanapi.IConnectorConnectionPoolMBean; 67 68 import com.sun.enterprise.admin.target.Target; 69 import com.sun.enterprise.admin.target.ConfigTarget; 70 71 public class ConnectorConnectionPoolMBean extends BaseConfigMBean 72 implements IConnectorConnectionPoolMBean 73 { 74 75 private static final String USER_NAME = "user_name"; 76 private static final String PASSWORD = "password"; 77 private static final String NAME = "name"; 78 private static final String PRINCIPAL = "principal"; 79 private static final String USER_GROUP = "user_group"; 80 private static final String POOL_NAME = "pool_name"; 81 private static final String MAP_NAME = "map_name"; 82 private static final String VERBOSE = "verbose"; 83 84 private static final String ADD_PRINCIPALS = "add_principals"; 85 private static final String REMOVE_PRINCIPALS = "remove_principals"; 86 private static final String ADD_USER_GROUPS = "add_user_groups"; 87 private static final String REMOVE_USER_GROUPS = "remove_user_groups"; 88 89 private static final String CREATE_SECURITY_MAP = "createSecurityMap"; 91 private static final String CREATE_BACKEND_PRINCIPAL 92 ="createBackendPrincipal"; 93 private static final String GET_SECURITY_MAP = "getSecurityMap"; 94 private static final String GET_SECURITY_MAP_BY_NAME = "getSecurityMapByName"; 95 private static final String GET_BACKEND_PRINCIPAL = "getBackendPrincipal"; 96 private static final String GET_POOL_BY_NAME 97 = "getConnectorConnectionPoolByName"; 98 private static final String DEFAULT_TARGET = "domain"; 99 private static final String GET_CONNECTOR_POOLS 100 = "getConnectorConnectionPool"; 101 102 private static final String CONFIG = "config"; 103 private static final String POOL_TYPE = "connector-connection-pool"; 104 private static final String MAP_TYPE = "security-map"; 105 private static final String RES_TYPE = "resources"; 106 107 private static final String POOL_DOES_NOT_EXISTS 109 ="admin.mbeans.ccpmb.pool_does_not_exists"; 110 private static final String MAP_DOES_NOT_EXISTS 111 ="admin.mbeans.ccpmb.map_does_not_exists"; 112 private static final String MAP_NAME_EXISTS 113 ="admin.mbeans.ccpmb.map_name_exists"; 114 private static final String PRINCIPAL_USERGPS_NULL 115 ="admin.mbeans.ccpmb.principals_usergroups_null"; 116 private static final String PRINCIPAL_EXISTS 117 ="admin.mbeans.ccpmb.principal_exists"; 118 private static final String USERGROUP_EXISTS 119 ="admin.mbeans.ccpmb.usergroup_exists"; 120 private static final String SAME_PRINCIPAL_VALUES 121 ="admin.mbeans.ccpmb.same_principal_values"; 122 private static final String SAME_USERGROUP_VALUES 123 ="admin.mbeans.ccpmb.same_usergroup_values"; 124 private static final String PRINCIPAL_DOES_NOT_EXISTS 125 ="admin.mbeans.ccpmb.principal_does_not_exists"; 126 private static final String USERGROUP_DOES_NOT_EXISTS 127 ="admin.mbeans.ccpmb.usergroup_does_not_exists"; 128 private static final String OPERATION_NOT_SUPPORTED 129 ="admin.mbeans.ccpmb.operation_not_supported"; 130 private static final String USER_NAME_NULL 131 ="admin.mbeans.ccpmb.user_name_null"; 132 private static final String PRINCIPALS_USERGROUPS_NULL 133 ="admin.mbeans.ccpmb.principals_usergroups_will_be_null"; 134 135 private static StringManager localStrings = 136 StringManager.getManager( ConnectorConnectionPoolMBean.class ); 137 138 139 141 142 public ConnectorConnectionPoolMBean() { 143 super(); 144 145 } 146 147 public void createSecurityMap(AttributeList attrList) 148 throws Exception { 149 String msg = localStrings.getString(OPERATION_NOT_SUPPORTED); 153 throw new Exception (msg); 154 } 155 156 157 161 public ObjectName createSecurityMap(AttributeList attrList,String userName, 162 String password ,String tgtName ) throws MBeanException { 163 ObjectName mbean = null; 164 String poolName = null; 165 String mapname = null; 166 167 try { 168 if (tgtName == null || tgtName.equals("")) tgtName = DEFAULT_TARGET; 169 170 MBeanServer server = getMBeanServer(); 171 String principals[] = null; 172 String usergroups[] = null; 173 174 if(attrList != null){ 175 int s = attrList.size(); 176 for(int i=0;i<s;i++){ 177 try { 178 Attribute attribute =(Attribute )attrList.get(i); 179 if(isAttrNameMatch(attribute, NAME)){ 180 mapname =(String ) attribute.getValue(); 181 continue; 182 } 183 if (isAttrNameMatch(attribute, PRINCIPAL)) 184 principals = (String [])attribute.getValue(); 185 if (isAttrNameMatch(attribute, USER_GROUP)) 186 usergroups =(String []) attribute.getValue(); 187 if (isAttrNameMatch(attribute, POOL_NAME)) 188 poolName = (String )attribute.getValue(); 189 } catch(Exception e){ 190 throw new Exception ("failed while getting attribute" + 191 "names and values"); 192 } 193 } 194 } 195 196 if(!doesPoolNameExists(poolName)){ 197 String msg = localStrings.getString(POOL_DOES_NOT_EXISTS,poolName); 198 throw new Exception (msg); 199 } 200 201 if(doesMapNameExists(poolName,mapname)){ 202 String msg = localStrings.getString(MAP_NAME_EXISTS 203 ,mapname,poolName); 204 throw new Exception (msg); 205 206 } 207 208 if(userName == null){ 210 String msg = localStrings.getString(USER_NAME_NULL); 211 throw new Exception (msg); 212 } 213 214 if(principals == null && usergroups == null){ 217 String msg = localStrings.getString(PRINCIPAL_USERGPS_NULL); 218 throw new Exception (msg); 219 } 220 221 ObjectName [] maps = getAllSecurityMapsForPool(poolName); 223 224 if(principals != null){ 225 for(int i=0;i<principals.length;i++){ 226 if (isPrincipalExisting(principals[i],maps)){ 227 String msg = localStrings.getString 228 (PRINCIPAL_EXISTS,principals[i],poolName); 229 throw new Exception (msg); 230 231 } 232 } 233 } 234 if(usergroups != null){ 235 for(int i=0;i<usergroups.length;i++){ 236 if (isUserGroupExisting(usergroups[i],maps)){ 237 String msg = localStrings.getString 238 (USERGROUP_EXISTS,usergroups[i],poolName); 239 throw new Exception (msg); 240 } 241 } 242 } 243 244 ConfigContext serverContext = getConfigContext(); 253 com.sun.enterprise.config.serverbeans.Resources resourcesBean = 254 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 255 ServerXPathHelper.XPATH_RESOURCES); 256 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool connPool = 257 resourcesBean.getConnectorConnectionPoolByName(poolName); 258 com.sun.enterprise.config.serverbeans.BackendPrincipal backEndPrincipal 259 = new com.sun.enterprise.config.serverbeans.BackendPrincipal(); 260 261 backEndPrincipal.setUserName(userName); 262 263 if(password != null) 264 backEndPrincipal.setPassword(password); 265 266 com.sun.enterprise.config.serverbeans.SecurityMap securityMap = 267 new com.sun.enterprise.config.serverbeans.SecurityMap(); 268 269 if(backEndPrincipal != null) 270 securityMap.setBackendPrincipal(backEndPrincipal); 271 272 if(mapname !=null) 273 securityMap.setName(mapname); 274 275 if(principals != null) 276 securityMap.setPrincipal(principals); 277 278 if(usergroups != null) 279 securityMap.setUserGroup(usergroups); 280 281 connPool.addSecurityMap(securityMap); 282 }catch (Exception e) { 285 e.printStackTrace(); 286 throw new MBeanException (e); 287 } 288 return mbean; 289 } 290 291 295 296 public boolean updateSecurityMap(AttributeList attrList,String tgtName ) 297 throws MBeanException { 298 299 String mapname = null; 300 String poolname = null; 301 String username = null; 302 String password = null; 303 String [] addPrincipals = null; 304 String [] addUserGroups = null; 305 String [] removePrincipals = null; 306 String [] removeUserGroups = null; 307 boolean status = false; 308 310 try { 311 if (tgtName == null || tgtName.equals("")) tgtName = DEFAULT_TARGET; 312 313 if(attrList != null){ 315 int s = attrList.size(); 316 for(int i=0;i<s;i++){ 317 try{ 318 Attribute attribute =(Attribute )attrList.get(i); 319 if((isAttrNameMatch(attribute, POOL_NAME))) 320 poolname = (String )attribute.getValue(); 321 if((isAttrNameMatch(attribute, NAME))) 322 mapname = (String )attribute.getValue(); 323 if((isAttrNameMatch(attribute, USER_NAME))) 324 username = (String )attribute.getValue(); 325 if((isAttrNameMatch(attribute, PASSWORD))) 326 password = (String )attribute.getValue(); 327 if((isAttrNameMatch(attribute, ADD_PRINCIPALS))) 328 addPrincipals = 329 getOptionsList((String )attribute.getValue()); 330 if((isAttrNameMatch(attribute, ADD_USER_GROUPS))) 331 addUserGroups = 332 getOptionsList((String )attribute.getValue()); 333 if((isAttrNameMatch(attribute, REMOVE_PRINCIPALS))) 334 removePrincipals = 335 getOptionsList((String )attribute.getValue()); 336 if((isAttrNameMatch(attribute, REMOVE_USER_GROUPS))) 337 removeUserGroups = 338 getOptionsList((String )attribute.getValue()); 339 }catch(Exception e){ 340 e.printStackTrace(); 341 } 342 } 343 } 344 if(!doesPoolNameExists(poolname)){ 345 String msg = localStrings.getString(POOL_DOES_NOT_EXISTS,poolname); 346 throw new Exception (msg); 347 } 348 349 if(!doesMapNameExists(poolname,mapname)){ 350 String msg = localStrings.getString(MAP_DOES_NOT_EXISTS 351 ,mapname,poolname); 352 throw new Exception (msg); 353 } 354 ObjectName [] maps = getAllSecurityMapsForPool(poolname); 356 357 if(addPrincipals != null && removePrincipals != null){ 359 for(int i=0; i < addPrincipals.length ; i++) { 360 for (int j=0; j < removePrincipals.length; j++) { 361 if(removePrincipals[j].equals(addPrincipals[i])){ 362 String msg = localStrings.getString( 363 SAME_PRINCIPAL_VALUES,addPrincipals[i]); 364 throw new Exception (msg); 365 } 366 367 } 368 } 369 } 370 371 if(addUserGroups != null && removeUserGroups != null){ 373 for(int i=0; i < addUserGroups.length ; i++) { 374 for (int j=0; j < removeUserGroups.length; j++) { 375 if(removeUserGroups[j].equals(addUserGroups[i])){ 376 String msg = localStrings.getString( 377 SAME_USERGROUP_VALUES,addUserGroups[i]); 378 throw new Exception (msg); 379 } 380 381 } 382 } 383 } 384 if(addPrincipals != null){ 386 for(int i=0;i<addPrincipals.length;i++){ 387 if (isPrincipalExisting(addPrincipals[i],maps)){ 388 String msg = localStrings.getString(PRINCIPAL_EXISTS, 389 addPrincipals[i],poolname); 390 throw new Exception (msg); 391 } 392 } 393 } 394 if(addUserGroups != null){ 396 for(int i=0;i<addUserGroups.length;i++){ 397 if (isUserGroupExisting(addUserGroups[i],maps)){ 398 String msg = localStrings.getString(USERGROUP_EXISTS 399 ,addUserGroups[i],poolname); 400 throw new Exception (msg); 401 } 402 } 403 } 404 MBeanServer server = getMBeanServer(); 406 ObjectName mbean = getSecurityMapObjectName(mapname,poolname); 407 String existingPrincipals[] = null; 408 String existingUserGroups[] = null; 409 410 existingPrincipals =(String []) server.getAttribute(mbean,PRINCIPAL); 411 existingUserGroups =(String []) server.getAttribute(mbean,USER_GROUP); 412 413 ArrayList source = null; 414 ArrayList source1 = null; 415 416 if(existingPrincipals != null){ 417 source = new ArrayList (existingPrincipals.length); 418 for(int i=0; i<existingPrincipals.length ; i++) 419 source.add(existingPrincipals[i]); 420 } 421 if(existingUserGroups != null){ 422 source1 = new ArrayList (existingUserGroups.length); 423 for(int i=0; i<existingUserGroups.length ; i++) 424 source1.add(existingUserGroups[i]); 425 } 426 if(removePrincipals != null){ 428 for(int i=0;i<removePrincipals.length;i++){ 429 String s = removePrincipals[i]; 430 if (!source.contains(s)){ 431 String msg = 432 localStrings.getString(PRINCIPAL_DOES_NOT_EXISTS,s,poolname); 433 throw new Exception (msg); 434 } 435 } 436 } 437 if(removeUserGroups != null){ 439 for(int i=0;i<removeUserGroups.length;i++){ 440 String s = removeUserGroups[i]; 441 if (!source1.contains(s)){ 442 String msg = 443 localStrings.getString(USERGROUP_DOES_NOT_EXISTS,s,poolname); 444 throw new Exception (msg); 445 } 446 } 447 } 448 449 453 if(addPrincipals == null && addUserGroups == null ) { 454 boolean principalsEmpty = false; 455 boolean userGroupsEmpty = false; 456 457 if(removePrincipals == null && existingPrincipals.length==0) 458 principalsEmpty = true; 459 if(removeUserGroups == null && existingUserGroups.length==0) 460 userGroupsEmpty = true; 461 462 if (( removePrincipals != null )&& 463 (removePrincipals.length== existingPrincipals.length)) 464 principalsEmpty = true; 465 466 if (( removeUserGroups != null ) && 467 (removeUserGroups.length== existingUserGroups.length)) 468 userGroupsEmpty = true; 469 if (userGroupsEmpty && principalsEmpty) { 470 String msg = localStrings.getString(PRINCIPALS_USERGROUPS_NULL); 471 throw new Exception (msg); 472 473 } 474 } 475 476 if(addPrincipals != null){ 478 for(int i=0; i < addPrincipals.length; i++) { 479 String s= addPrincipals[i]; 480 if (!source.contains(s)) 481 source.add(s); 482 else{ 483 String msg = localStrings.getString(PRINCIPAL_EXISTS 484 ,s,poolname); 485 throw new Exception (msg); 486 } 487 } 488 } 489 if(removePrincipals != null){ 491 for(int i=0; i <removePrincipals.length ;i++) { 492 String s = removePrincipals[i]; 493 source.remove(s); 494 } 495 } 496 497 String newPrincipals[] = new String [source.size()]; 498 for(int i=0; i< source.size(); i++) 499 newPrincipals[i]=(String ) source.get(i); 500 501 if(addUserGroups != null){ 503 for(int i=0; i < addUserGroups.length; i++) { 504 String s= addUserGroups[i]; 505 if (!source1.contains(s)) 506 source1.add(s); 507 else{ 508 String msg = localStrings.getString 509 (USERGROUP_EXISTS,s,poolname); 510 throw new Exception (msg); 511 } 512 } 513 } 514 516 if(removeUserGroups != null){ 517 for(int i=0; i <removeUserGroups.length ;i++) { 518 String s = removeUserGroups[i]; 519 source1.remove(s); 520 } 521 } 522 523 String newUserGroups[] = new String [source1.size()]; 524 for(int i=0; i< source1.size(); i++) 525 newUserGroups[i]=(String ) source1.get(i); 526 527 528 Attribute princ =null; 530 Attribute ug = null; 531 if(newPrincipals != null){ 532 princ = new Attribute (PRINCIPAL,newPrincipals); 533 server.setAttribute(mbean,princ); 534 } 535 if(newUserGroups != null){ 536 ug = new Attribute (USER_GROUP,newUserGroups); 537 server.setAttribute(mbean,ug); 538 } 539 540 ObjectName backendPrincipal =(ObjectName ) getMBeanServer().invoke( 543 mbean, GET_BACKEND_PRINCIPAL,null,null); 544 545 if(username != null){ 546 if(!((String )(server.getAttribute(backendPrincipal, 547 USER_NAME))).equals(username)) 548 server.setAttribute(backendPrincipal, 549 new Attribute (USER_NAME,username)); 550 } 551 552 if(password != null){ 553 if(!((String )(server.getAttribute(backendPrincipal, 554 PASSWORD))).equals(password)) 555 server.setAttribute(backendPrincipal, 556 new Attribute (PASSWORD,password)); 557 } 558 status = true; 559 } catch (Exception e) { 560 status = false; 561 e.printStackTrace(); 562 throw new MBeanException (e); 563 } 564 return status; 565 } 566 567 568 569 public ArrayList listSecurityMap(String mapName,Boolean verb,String poolName, 570 String tgtName) throws MBeanException { 571 572 ObjectName mbean = null; 573 StringBuffer strf = new StringBuffer (); 574 boolean verbose = false; 575 ArrayList list = new ArrayList (); 576 577 try { 578 if (tgtName == null || tgtName.equals("")) tgtName = DEFAULT_TARGET; 579 if(!doesPoolNameExists(poolName)){ 580 String msg = localStrings.getString(POOL_DOES_NOT_EXISTS,poolName); 581 throw new Exception (msg); 582 } 583 if(mapName != null){ 584 if(!doesMapNameExists(poolName,mapName)){ 585 String msg = localStrings.getString(MAP_DOES_NOT_EXISTS 586 ,mapName,poolName); 587 throw new Exception (msg); 588 } 589 } 590 591 592 verbose = verb.booleanValue(); 593 ObjectName [] maps =(ObjectName []) super.invoke(GET_SECURITY_MAP,null,null); 595 if(mapName == null && verbose){ 596 if(maps != null && maps.length >0){ 597 for(int i=0;i<maps.length;i++){ 598 String map = (String )getMBeanServer().getAttribute( 599 maps[i],NAME); 600 ObjectName mapRef =(ObjectName )super.invoke( 601 GET_SECURITY_MAP_BY_NAME, new Object []{map}, 602 new String [] {"java.lang.String"}); 603 list.add(createMapInfo(mapRef)); 604 605 } 606 } 607 }else if( mapName == null && !verbose ){ 608 if(maps != null && maps.length >0){ 609 for(int i=0;i<maps.length;i++){ 610 String map = (String ) 611 getMBeanServer().getAttribute(maps[i],NAME); 612 AttributeList attr = new AttributeList (); 613 if(map != null) 614 attr.add(new Attribute (NAME,map)); 615 616 ObjectName mapRef =(ObjectName ) 618 super.invoke(GET_SECURITY_MAP_BY_NAME,new Object []{map}, 619 new String [] {"java.lang.String"}); 620 String mapname = (String )getMBeanServer().getAttribute(mapRef,NAME); 621 list.add(new String []{mapname,null,null,null,null}); 622 } 623 } 624 }else { 625 ObjectName mapRef =(ObjectName )super.invoke(GET_SECURITY_MAP_BY_NAME, 627 new Object []{mapName}, new String [] {"java.lang.String"}); 628 if(mapRef != null) { 629 if (verbose) { 630 list.add(createMapInfo(mapRef)); 631 } else { 632 list.add(new String []{mapName,null,null,null,null}); 633 } 634 } 635 636 } 637 }catch (Exception e) { 638 e.printStackTrace(); 639 throw new MBeanException (e); 640 } 641 642 return list; 643 } 644 645 646 648 public AttributeList getAttributes(String mapName,String poolName) 650 throws Exception { 651 String mapname = null; 652 String [] existingPrincipals = null; 653 String [] existingUserGroups = null; 654 String username = null; 655 String password = null; 656 657 if(mapName != null){ 658 if(!doesMapNameExists(poolName,mapName)){ 659 String msg = localStrings.getString(MAP_DOES_NOT_EXISTS 660 ,mapName,poolName); 661 throw new Exception (msg); 662 } 663 } 664 665 ObjectName mapRef =(ObjectName )super.invoke( 666 GET_SECURITY_MAP_BY_NAME, new Object []{mapName}, 667 new String [] {"java.lang.String"}); 668 if(mapRef != null) { 669 mapname = (String )getMBeanServer().getAttribute(mapRef,NAME); 670 existingPrincipals = 671 (String [])getMBeanServer().getAttribute(mapRef,PRINCIPAL); 672 existingUserGroups = 673 (String [])getMBeanServer().getAttribute(mapRef,USER_GROUP); 674 } 675 676 ObjectName backEndPrincipal = (ObjectName )getMBeanServer().invoke( 677 mapRef,GET_BACKEND_PRINCIPAL,null,null); 678 if(backEndPrincipal != null){ 679 username = (String ) 680 getMBeanServer().getAttribute(backEndPrincipal,USER_NAME); 681 password = (String ) 682 getMBeanServer().getAttribute(backEndPrincipal,PASSWORD); 683 } 684 AttributeList attributes = new AttributeList (); 686 if(mapname != null) 687 attributes.add(new Attribute (NAME,mapname)); 688 if(existingPrincipals != null) 689 attributes.add(new Attribute (PRINCIPAL,existingPrincipals)); 690 if(existingUserGroups != null) 691 attributes.add(new Attribute (USER_GROUP,existingUserGroups)); 692 if(username != null) 693 attributes.add(new Attribute (USER_NAME,username)); 694 if(password != null) 695 attributes.add(new Attribute (PASSWORD,password)); 696 697 return attributes; 698 } 699 700 private ObjectName getConnectorConnObjectName(String poolName)throws Exception { 701 return m_registry.getMbeanObjectName(POOL_TYPE, 702 new String []{getDomainName(),poolName,CONFIG}); 703 } 704 705 private ObjectName getSecurityMapObjectName(String mapName,String poolName) 706 throws Exception { 707 return m_registry.getMbeanObjectName(MAP_TYPE, 708 new String []{getDomainName(),poolName,mapName,CONFIG}); 709 } 710 private boolean isPrincipalExisting(String principal,ObjectName [] maps) 711 throws Exception { 712 boolean exists =false; 713 String [] existingPrincipals = null; 714 715 if (maps!= null && maps.length > 0){ 716 for (int k=0; k<maps.length && !exists ; k++){ 717 existingPrincipals = 718 (String [])getMBeanServer().getAttribute(maps[k],PRINCIPAL); 719 if(existingPrincipals != null && principal != null){ 720 for(int i=0; i < existingPrincipals.length ; i++) { 721 if(existingPrincipals[i].equals(principal)){ 722 exists = true; 723 break; 724 } 725 } 726 } 727 } 728 } 729 return exists ; 730 } 731 732 private boolean isUserGroupExisting(String usergroup,ObjectName [] maps) 733 throws Exception { 734 boolean exists =false; 735 String [] existingUserGroups = null; 736 if (maps!= null && maps.length > 0){ 737 for (int k=0; k<maps.length && !exists ; k++){ 738 existingUserGroups = 739 (String [])getMBeanServer().getAttribute(maps[k],USER_GROUP); 740 if(existingUserGroups != null && usergroup != null){ 741 for(int i=0; i < existingUserGroups.length ; i++) { 742 if(existingUserGroups[i].equals(usergroup)){ 743 exists = true; 744 break; 745 } 746 } 747 } 748 } 749 } 750 return exists ; 751 } 752 753 protected ObjectName getConfigMBean(Target target) throws Exception { 754 ConfigTarget ct = target.getConfigTarget(); 755 return new ObjectName ( 756 ct.getTargetObjectName(new String [] {getDomainName()})); 757 } 758 759 private ObjectName [] getAllSecurityMapsForPool(String poolName )throws Exception { 760 ObjectName poolObj = getConnectorConnObjectName(poolName); 761 return (ObjectName [])getMBeanServer().invoke(poolObj, 762 GET_SECURITY_MAP, null, null); 763 } 764 765 private boolean doesPoolNameExists(String poolName )throws Exception { 766 ObjectName resObj = m_registry.getMbeanObjectName(RES_TYPE, 768 new String []{getDomainName(),CONFIG}); 769 ObjectName [] pools =(ObjectName [])getMBeanServer().invoke(resObj, 770 GET_CONNECTOR_POOLS,null,null); 771 boolean doesPoolExists = false; 772 if (pools!= null && pools.length > 0){ 773 for (int i=0; i<pools.length; i++){ 774 String pool = (String )getMBeanServer().getAttribute(pools[i],NAME); 775 if (pool.equals(poolName)) 776 doesPoolExists = true; 777 } 778 } 779 return doesPoolExists; 780 } 781 782 private boolean doesMapNameExists(String poolName,String mapname )throws Exception { 783 ObjectName poolObj = getConnectorConnObjectName(poolName); 785 ObjectName [] maps =(ObjectName [])getMBeanServer().invoke(poolObj, 786 GET_SECURITY_MAP, null, null); 787 788 boolean doesMapNameExists = false; 789 if (maps!= null && maps.length > 0){ 790 for (int i=0; i<maps.length; i++){ 791 String mapName = 792 (String )getMBeanServer().getAttribute(maps[i],NAME); 793 if (mapName.equals(mapname)) 794 doesMapNameExists = true; 795 } 796 } 797 return doesMapNameExists; 798 } 799 800 private String [] createMapInfo(ObjectName mapRef )throws Exception { 801 String [] existingPrincipals = null; 802 String [] existingUserGroups = null; 803 StringBuffer buf1= new StringBuffer (); 804 StringBuffer buf2= new StringBuffer (); 805 String mapname = null; 806 String username = null; 807 String password = null; 808 809 if(mapRef != null) { 810 mapname = (String )getMBeanServer().getAttribute(mapRef,NAME); 811 existingPrincipals = 812 (String [])getMBeanServer().getAttribute(mapRef,PRINCIPAL); 813 existingUserGroups = 814 (String [])getMBeanServer().getAttribute(mapRef,USER_GROUP); 815 if(existingPrincipals != null){ 816 for(int j=0;j<existingPrincipals.length;j++){ 817 buf1.append(existingPrincipals[j]); 818 buf1.append(","); 819 } 820 } 821 if(existingUserGroups != null){ 822 for(int j=0;j<existingUserGroups.length;j++){ 823 buf2.append(existingUserGroups[j]); 824 buf2.append(","); 825 } 826 } 827 ObjectName backEndPrincipal = (ObjectName )getMBeanServer().invoke( 828 mapRef,GET_BACKEND_PRINCIPAL,null,null); 829 if(backEndPrincipal != null){ 830 username = 831 (String )getMBeanServer().getAttribute(backEndPrincipal,USER_NAME); 832 password = 833 (String )getMBeanServer().getAttribute(backEndPrincipal,PASSWORD); 834 835 } 836 } 837 return new String []{mapname,buf1.toString(),buf2.toString(),username,password}; 838 839 } 840 841 private String [] getOptionsList(Object sOptions){ 842 StringTokenizer optionTokenizer = new StringTokenizer ((String )sOptions,","); 843 int size = optionTokenizer.countTokens(); 844 String [] sOptionsList = new String [size]; 845 for (int ii=0; ii<size; ii++){ 846 sOptionsList[ii] = optionTokenizer.nextToken(); 847 } 848 return sOptionsList; 849 } 850 851 protected MBeanServer getMBeanServer() { 852 return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer(); 853 } 854 855 private static boolean isAttrNameMatch(Attribute attr, String name) 856 { 857 return attr.getName().replace('_','-').equals(name.replace('_','-')); 860 } 861 862 863 } 864 | Popular Tags |