KickJava   Java API By Example, From Geeks To Geeks.

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


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.MBeanServerConnection JavaDoc;
30 import com.sun.enterprise.admin.common.ObjectNames;
31
32 // jdk imports
33
import java.io.File JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.StringTokenizer JavaDoc;
37
38 public class ListSecurityMapCommand extends GenericCommand{
39
40     
41     /**
42      * An abstract method that Executes the command
43      * @throws CommandException
44      */

45     public void runCommand()throws CommandException, CommandValidationException{
46         if (!validateOptions())
47             throw new CommandValidationException("Validation failed");
48         
49            String JavaDoc objectName = getObjectName();
50             Object JavaDoc[] params = getParamsInfo();
51             String JavaDoc operationName = getOperationName();
52             String JavaDoc[] types = getTypesInfo();
53             String JavaDoc[] map = null;
54             String JavaDoc[] principals = null;
55             String JavaDoc[] usergroups = null;
56             
57            MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
58                                     getUser(), getPassword());
59         try {
60          ArrayList JavaDoc list =(ArrayList JavaDoc)mbsc.invoke(new ObjectName JavaDoc(objectName),
61                          operationName, params, types);
62              
63              Iterator JavaDoc iterator= list.iterator();
64              while (iterator.hasNext()){
65                 map = (String JavaDoc[]) 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 JavaDoc 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 JavaDoc 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 JavaDoc[] {name}));
103         }catch(Exception JavaDoc e){
104         if (e.getLocalizedMessage() != null)
105         CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
106             throw new CommandException(getLocalizedString("CommandUnSuccessful",
107                              new Object JavaDoc[] {name} ), e);
108         }
109     }
110         
111     private String JavaDoc[] getOptionsList(Object JavaDoc sOptions){
112         StringTokenizer JavaDoc optionTokenizer = new StringTokenizer JavaDoc((String JavaDoc)sOptions,",");
113         int size = optionTokenizer.countTokens();
114         String JavaDoc [] sOptionsList = new String JavaDoc[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