1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 28 import javax.management.ObjectName ; 29 import javax.management.MBeanServerConnection ; 30 import com.sun.enterprise.admin.common.ObjectNames; 31 32 import java.io.File ; 34 import java.util.Iterator ; 35 import java.util.ArrayList ; 36 import java.util.StringTokenizer ; 37 38 public class ListSecurityMapCommand extends GenericCommand{ 39 40 41 45 public void runCommand()throws CommandException, CommandValidationException{ 46 if (!validateOptions()) 47 throw new CommandValidationException("Validation failed"); 48 49 String objectName = getObjectName(); 50 Object [] params = getParamsInfo(); 51 String operationName = getOperationName(); 52 String [] types = getTypesInfo(); 53 String [] map = null; 54 String [] principals = null; 55 String [] usergroups = null; 56 57 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 58 getUser(), getPassword()); 59 try { 60 ArrayList list =(ArrayList )mbsc.invoke(new ObjectName (objectName), 61 operationName, params, types); 62 63 Iterator iterator= list.iterator(); 64 while (iterator.hasNext()){ 65 map = (String []) iterator.next(); 66 CLILogger.getInstance().printMessage(" ===================================="); 67 CLILogger.getInstance().printMessage(" Security Map Name is :" +map[0]); 68 CLILogger.getInstance().printMessage(" ====================================="); 69 if(map[1] != null) 70 principals = getOptionsList(map[1]); 71 if(map[2] != null) 72 usergroups = getOptionsList(map[2]); 73 74 if(principals != null){ 75 CLILogger.getInstance().printMessage("Principals for Security Map :"+ map[0] +" are :"); 76 for(int i = 0;i<principals.length;i++) 77 CLILogger.getInstance().printMessage("<principal> " +principals[i]); 78 } 79 CLILogger.getInstance().printMessage("\n"); 80 if(usergroups != null ){ 81 CLILogger.getInstance().printMessage("UserGroups for Security Map :"+ map[0] +" are :"); 82 for(int i = 0;i<usergroups.length;i++) 83 CLILogger.getInstance().printMessage("<user-group> "+usergroups[i]); 84 } 85 CLILogger.getInstance().printMessage("\n"); 86 if(map[3] != null){ 87 String username = map[3]; 88 CLILogger.getInstance().printMessage("Backend Principal User Name for :"+map[0] +" is :"+username); 89 CLILogger.getInstance().printMessage(" \n"); 90 } 91 if(map[4] != null){ 92 String password = map[4]; 93 CLILogger.getInstance().printMessage("Backend Principal Password for :"+map[0] +" is :"+password); 94 CLILogger.getInstance().printMessage("\n"); 95 } 96 97 98 } 99 100 CLILogger.getInstance().printDetailMessage(getLocalizedString( 101 "CommandSuccessful", 102 new Object [] {name})); 103 }catch(Exception e){ 104 if (e.getLocalizedMessage() != null) 105 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 106 throw new CommandException(getLocalizedString("CommandUnSuccessful", 107 new Object [] {name} ), e); 108 } 109 } 110 111 private String [] getOptionsList(Object sOptions){ 112 StringTokenizer optionTokenizer = new StringTokenizer ((String )sOptions,","); 113 int size = optionTokenizer.countTokens(); 114 String [] sOptionsList = new String [size]; 115 for (int ii=0; ii<size; ii++){ 116 sOptionsList[ii] = optionTokenizer.nextToken(); 117 } 118 return sOptionsList; 119 } 120 121 public boolean validateOptions() throws CommandValidationException { 122 return super.validateOptions(); 123 } 124 } 125 | Popular Tags |