KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Collection JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 import org.ejbca.core.model.ra.UserDataVO;
20
21
22
23
24
25 /**
26  * List users with specified status in the database.
27  *
28  * @version $Id: RaListUsersCommand.java,v 1.2 2006/01/26 14:17:57 anatom Exp $
29  *
30  * @see org.ejbca.core.ejb.ra.UserDataLocal
31  */

32 public class RaListUsersCommand extends BaseRaAdminCommand {
33     /**
34      * Creates a new instance of RaListUsersCommand
35      *
36      * @param args command line arguments
37      */

38     public RaListUsersCommand(String JavaDoc[] args) {
39         super(args);
40     }
41
42     /**
43      * Runs the command
44      *
45      * @throws IllegalAdminCommandException Error in command args
46      * @throws ErrorAdminCommandException Error running command
47      */

48     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
49         try {
50             if (args.length < 2) {
51                 getOutputStream().println("Usage: RA listusers <status>");
52                 getOutputStream().println(
53                     "Status: NEW=10; FAILED=11; INITIALIZED=20; INPROCESS=30; GENERATED=40; HISTORICAL=50");
54
55                 return;
56             }
57
58             int status = Integer.parseInt(args[1]);
59             Collection JavaDoc coll = getAdminSession().findAllUsersByStatus(administrator, status);
60             Iterator JavaDoc iter = coll.iterator();
61
62             while (iter.hasNext()) {
63                 UserDataVO data = (UserDataVO) iter.next();
64                 getOutputStream().println("User: " + data.getUsername() + ", \"" + data.getDN() +
65                     "\", \"" + data.getSubjectAltName() + "\", " + data.getEmail() + ", " +
66                     data.getStatus() + ", " + data.getType() + ", " + data.getTokenType() + ", " + data.getHardTokenIssuerId());
67             }
68         } catch (Exception JavaDoc e) {
69             throw new ErrorAdminCommandException(e);
70         }
71     }
72
73     // execute
74
}
75
Popular Tags