KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > cli > RaFindUserCommand


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.cli;
15
16 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
17 import org.ejbca.core.model.ra.UserDataVO;
18
19
20
21
22
23 /**
24  * Find details of a user in the database.
25  *
26  * @version $Id: RaFindUserCommand.java,v 1.3 2006/06/03 18:10:46 anatom Exp $
27  */

28 public class RaFindUserCommand extends BaseRaAdminCommand {
29     /**
30      * Creates a new instance of RaFindUserCommand
31      *
32      * @param args command line arguments
33      */

34     public RaFindUserCommand(String JavaDoc[] args) {
35         super(args);
36     }
37
38     /**
39      * Runs the command
40      *
41      * @throws IllegalAdminCommandException Error in command args
42      * @throws ErrorAdminCommandException Error running command
43      */

44     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
45         try {
46             if (args.length < 2) {
47                 getOutputStream().println("Usage: RA finduser <username>");
48
49                 return;
50             }
51
52             String JavaDoc username = args[1];
53
54             try {
55                 UserDataVO data = getAdminSession().findUser(administrator, username);
56
57                 if (data != null) {
58                     getOutputStream().println("Found user:");
59                     getOutputStream().println("username=" + data.getUsername());
60                     getOutputStream().println("password=" + data.getPassword());
61                     getOutputStream().println("dn: \"" + data.getDN() + "\"");
62                     getOutputStream().println("altName: \"" + data.getSubjectAltName() + "\"");
63                     getOutputStream().println("directoryAttributes: \"" + data.getExtendedinformation().getSubjectDirectoryAttributes() + "\"");
64                     getOutputStream().println("email=" + data.getEmail());
65                     getOutputStream().println("status=" + data.getStatus());
66                     getOutputStream().println("type=" + data.getType());
67                     getOutputStream().println("token type=" + data.getTokenType());
68                     getOutputStream().println("end entity profile id=" + data.getEndEntityProfileId());
69                     getOutputStream().println("certificate entity profile id=" +
70                         data.getCertificateProfileId());
71                     getOutputStream().println("hard token issuer id=" + data.getHardTokenIssuerId());
72                     getOutputStream().println("created=" + data.getTimeCreated());
73                     getOutputStream().println("modified=" + data.getTimeModified());
74                 } else {
75                     getOutputStream().println("User '" + username + "' does not exist.");
76                 }
77             } catch (AuthorizationDeniedException e) {
78                 getOutputStream().println("Error : Not authorized to view user.");
79             }
80         } catch (Exception JavaDoc e) {
81             throw new ErrorAdminCommandException(e);
82         }
83     }
84
85     // execute
86
}
87
Popular Tags