KickJava   Java API By Example, From Geeks To Geeks.

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


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
18
19 /**
20  * Deletes a user from the database.
21  *
22  * @version $Id: RaDelUserCommand.java,v 1.1 2006/01/17 20:28:05 anatom Exp $
23  */

24 public class RaDelUserCommand extends BaseRaAdminCommand {
25     /**
26      * Creates a new instance of RaDelUserCommand
27      *
28      * @param args command line arguments
29      */

30     public RaDelUserCommand(String JavaDoc[] args) {
31         super(args);
32     }
33
34     /**
35      * Runs the command
36      *
37      * @throws IllegalAdminCommandException Error in command args
38      * @throws ErrorAdminCommandException Error running command
39      */

40     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
41         if (args.length < 2) {
42             throw new IllegalAdminCommandException("Usage: RA deluser <username>");
43         }
44
45         try {
46             String JavaDoc username = args[1];
47             getOutputStream().print("Have you revoked the user [y/N]? ");
48
49             int inp = System.in.read();
50
51             if ((inp == 121) || (inp == 89)) {
52                 try {
53                     getAdminSession().deleteUser(administrator, username);
54                     getOutputStream().println("Deleted user " + username);
55                 } catch (AuthorizationDeniedException e) {
56                     getOutputStream().println("Error : Not authorized to remove user.");
57                 }
58             } else {
59                 getOutputStream().println("Delete aborted!");
60                 getOutputStream().println("Please run 'ra revokeuser " + username + "'.");
61             }
62         } catch (Exception JavaDoc e) {
63             throw new ErrorAdminCommandException(e);
64         }
65     }
66
67     // execute
68
}
69
Popular Tags