1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2012 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmstools.user;
import org.apache.commons.lang.StringUtils;
import org.jboss.resteasy.plugins.providers.atom.Link;
import com.netscape.certsrv.client.PKIClient;
import com.netscape.certsrv.user.UserClient;
import com.netscape.certsrv.user.UserData;
import com.netscape.certsrv.user.UserResource;
import com.netscape.cmstools.cli.CLI;
import com.netscape.cmstools.cli.MainCLI;
import com.netscape.cmstools.cli.SubsystemCLI;
/**
* @author Endi S. Dewata
*/
public class UserCLI extends CLI {
public UserClient userClient;
public UserCLI(CLI parent) {
super("user", "User management commands", parent);
addModule(new UserFindCLI(this));
addModule(new UserShowCLI(this));
addModule(new UserAddCLI(this));
addModule(new UserModifyCLI(this));
addModule(new UserRemoveCLI(this));
addModule(new UserCertCLI(this));
addModule(new UserMembershipCLI(this));
}
public String getFullName() {
if (parent instanceof MainCLI) {
// do not include MainCLI's name
return name;
} else {
return parent.getFullName() + "-" + name;
}
}
@Override
public String getManPage() {
return "pki-user";
}
public UserClient getUserClient() throws Exception {
if (userClient != null) return userClient;
PKIClient client = getClient();
// determine the subsystem
String subsystem;
if (parent instanceof SubsystemCLI) {
SubsystemCLI subsystemCLI = (SubsystemCLI)parent;
subsystem = subsystemCLI.getName();
} else {
subsystem = "ca";
}
// create new user client
userClient = new UserClient(client, subsystem);
return userClient;
}
public static void printUser(UserData userData) {
System.out.println(" User ID: " + userData.getID());
String fullName = userData.getFullName();
if (!StringUtils.isEmpty(fullName))
System.out.println(" Full name: " + fullName);
String email = userData.getEmail();
if (!StringUtils.isEmpty(email))
System.out.println(" Email: " + email);
String phone = userData.getPhone();
if (!StringUtils.isEmpty(phone))
System.out.println(" Phone: " + phone);
String type = userData.getType();
if (!StringUtils.isEmpty(type))
System.out.println(" Type: " + type);
String state = userData.getState();
if (!StringUtils.isEmpty(state))
System.out.println(" State: " + state);
Link link = userData.getLink();
if (verbose && link != null) {
System.out.println(" Link: " + link.getHref());
}
String tpsProfiles = userData.getAttribute(UserResource.ATTR_TPS_PROFILES);
if (tpsProfiles != null) {
System.out.println(" TPS Profiles:");
for (String profile: tpsProfiles.split(",")) {
System.out.println(" " + profile);
}
}
}
}
|