KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > CreateSecurityMapCommand


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.Attribute JavaDoc;
30 import javax.management.AttributeList JavaDoc;
31 import javax.management.MBeanServerConnection JavaDoc;
32 import com.sun.enterprise.admin.common.ObjectNames;
33
34
35 // jdk imports
36
import java.io.File JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.ArrayList JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40
41 public class CreateSecurityMapCommand extends SecurityMapCommand{
42     
43     
44     /**
45      * An abstract method that Executes the command
46      * @throws CommandException
47      */

48     public void runCommand()throws CommandException, CommandValidationException
49     {
50         if (!validateOptions())
51             throw new CommandValidationException("Validation failed");
52         
53         
54            String JavaDoc objectName = getObjectName();
55             Object JavaDoc[] params = getParamsInfo();
56             String JavaDoc operationName = getOperationName();
57             String JavaDoc[] types = getTypesInfo();
58             String JavaDoc[] map = null;
59             String JavaDoc[] principals = null;
60             String JavaDoc[] usergroups = null;
61             AttributeList JavaDoc list = null;
62     
63              list =(AttributeList JavaDoc) 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 JavaDoc attribute =(Attribute JavaDoc)list.get(i);
70                     if(attribute.getName().equalsIgnoreCase("principal"))
71                     {
72                         String JavaDoc principal = (String JavaDoc)attribute.getValue();
73                         principals =((String JavaDoc[]) getListOfValues(principal));
74                         list.set(i,new Attribute JavaDoc("principal",principals));
75                      }
76                      if ((attribute.getName().equalsIgnoreCase("user_group")))
77                      {
78                          String JavaDoc usergroup = (String JavaDoc)attribute.getValue();
79                          usergroups = ((String JavaDoc[])getListOfValues(usergroup));
80                          list.set(i,new Attribute JavaDoc("user_group",usergroups));
81                     }
82                        
83                 }
84             }
85                
86              
87            MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
88                                     getUser(), getPassword());
89         try
90         {
91          ObjectName JavaDoc object =(ObjectName JavaDoc)mbsc.invoke(new ObjectName JavaDoc(objectName),
92                      operationName, params, types);
93              CLILogger.getInstance().printDetailMessage(getLocalizedString(
94                                "CommandSuccessful",
95                                        new Object JavaDoc[] {name}));
96         }
97         catch(Exception JavaDoc e)
98         {
99     
100         if (e.getLocalizedMessage() != null)
101         CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
102             throw new CommandException(getLocalizedString("CommandUnSuccessful",
103                              new Object JavaDoc[] {name} ), e);
104         }
105     }
106     
107                 
108         
109     private String JavaDoc[] getListOfValues(String JavaDoc sOptions){
110         StringTokenizer JavaDoc optionTokenizer = new StringTokenizer JavaDoc(sOptions,",");
111         int size = optionTokenizer.countTokens();
112         String JavaDoc [] sOptionsList = new String JavaDoc[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