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.Attribute ; 30 import javax.management.AttributeList ; 31 import javax.management.MBeanServerConnection ; 32 import com.sun.enterprise.admin.common.ObjectNames; 33 34 35 import java.io.File ; 37 import java.util.Iterator ; 38 import java.util.ArrayList ; 39 import java.util.StringTokenizer ; 40 41 public class CreateSecurityMapCommand extends SecurityMapCommand{ 42 43 44 48 public void runCommand()throws CommandException, CommandValidationException 49 { 50 if (!validateOptions()) 51 throw new CommandValidationException("Validation failed"); 52 53 54 String objectName = getObjectName(); 55 Object [] params = getParamsInfo(); 56 String operationName = getOperationName(); 57 String [] types = getTypesInfo(); 58 String [] map = null; 59 String [] principals = null; 60 String [] usergroups = null; 61 AttributeList list = null; 62 63 list =(AttributeList ) params[0]; 64 if(list != null){ 65 int s = list.size(); 66 int i = 0 ; 67 for(i=0;i<s;i++) 68 { 69 Attribute attribute =(Attribute )list.get(i); 70 if(attribute.getName().equalsIgnoreCase("principal")) 71 { 72 String principal = (String )attribute.getValue(); 73 principals =((String []) getListOfValues(principal)); 74 list.set(i,new Attribute ("principal",principals)); 75 } 76 if ((attribute.getName().equalsIgnoreCase("user_group"))) 77 { 78 String usergroup = (String )attribute.getValue(); 79 usergroups = ((String [])getListOfValues(usergroup)); 80 list.set(i,new Attribute ("user_group",usergroups)); 81 } 82 83 } 84 } 85 86 87 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 88 getUser(), getPassword()); 89 try 90 { 91 ObjectName object =(ObjectName )mbsc.invoke(new ObjectName (objectName), 92 operationName, params, types); 93 CLILogger.getInstance().printDetailMessage(getLocalizedString( 94 "CommandSuccessful", 95 new Object [] {name})); 96 } 97 catch(Exception e) 98 { 99 100 if (e.getLocalizedMessage() != null) 101 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 102 throw new CommandException(getLocalizedString("CommandUnSuccessful", 103 new Object [] {name} ), e); 104 } 105 } 106 107 108 109 private String [] getListOfValues(String sOptions){ 110 StringTokenizer optionTokenizer = new StringTokenizer (sOptions,","); 111 int size = optionTokenizer.countTokens(); 112 String [] sOptionsList = new String [size]; 113 for (int ii=0; ii<size; ii++){ 114 sOptionsList[ii] = optionTokenizer.nextToken(); 115 } 116 return sOptionsList; 117 } 118 119 public boolean validateOptions() throws CommandValidationException { 120 return super.validateOptions(); 121 } 122 } 123 | Popular Tags |