KickJava   Java API By Example, From Geeks To Geeks.

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


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.raadmin.UserDoesntFullfillEndEntityProfile;
18
19
20
21 /**
22  * Set the (hashed) password for a user in the database.
23  *
24  * @version $Id: RaSetPwdCommand.java,v 1.1 2006/01/17 20:28:05 anatom Exp $
25  */

26 public class RaSetPwdCommand extends BaseRaAdminCommand {
27     /**
28      * Creates a new instance of RaSetPwdCommand
29      *
30      * @param args command line arguments
31      */

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

42     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
43         try {
44             if (args.length < 3) {
45                 getOutputStream().println("Usage: RA setpwd <username> <password>");
46
47                 return;
48             }
49
50             String JavaDoc username = args[1];
51             String JavaDoc password = args[2];
52             getOutputStream().println("Setting password (hashed only) " + password + " for user " +
53                 username);
54
55             try {
56                 getAdminSession().setPassword(administrator, username, password);
57             } catch (AuthorizationDeniedException e) {
58                 getOutputStream().println("Error : Not authorized to change userdata.");
59             } catch (UserDoesntFullfillEndEntityProfile e) {
60                 getOutputStream().println("Error : Given userdata doesn't fullfill profile.");
61             }
62         } catch (Exception JavaDoc e) {
63             throw new ErrorAdminCommandException(e);
64         }
65     }
66
67     // execute
68
}
69
Popular Tags