KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.commons.lang.StringUtils;
17 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
18 import org.ejbca.core.model.ra.ExtendedInformation;
19 import org.ejbca.core.model.ra.UserDataVO;
20 import org.ejbca.core.model.ra.raadmin.UserDoesntFullfillEndEntityProfile;
21
22
23
24 /**
25  * Set the clear text password for a user in the database. Clear text passwords are used for batch
26  * generation of keystores (pkcs12/pem).
27  *
28  * @version $Id: RaSetSubjDirAttrCommand.java,v 1.1 2006/06/03 18:10:46 anatom Exp $
29  */

30 public class RaSetSubjDirAttrCommand extends BaseRaAdminCommand {
31     /**
32      * Creates a new instance of RaSetClearPwdCommand
33      *
34      * @param args command line arguments
35      */

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

46     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
47         try {
48             if (args.length < 3) {
49                 getOutputStream().println("Usage: RA setsubjectdirattr <username> \"subject directory attributes\"");
50                 getOutputStream().println("Attributes are: dateOfBirth=<19590927>, placeOfBirth=<string>, gender=<M/F>, countryOfCitizenship=<two letter ISO3166>, countryOfResidence=<two letter ISO3166>");
51                 return;
52             }
53
54             String JavaDoc username = args[1];
55             String JavaDoc attributes = args[2];
56             if (StringUtils.isEmpty(attributes)) {
57                 getOutputStream().println("Subject directory attributes must be supplied.");
58                 return;
59             }
60             getOutputStream().println("Setting subject directory attributes '" + attributes + "' for user " + username);
61
62             try {
63                 UserDataVO uservo = getAdminSession().findUser(administrator, username);
64                 ExtendedInformation ext = uservo.getExtendedinformation();
65                 ext.setSubjectDirectoryAttributes(attributes);
66                 uservo.setExtendedinformation(ext);
67                 getAdminSession().changeUser(administrator, uservo, false);
68             } catch (AuthorizationDeniedException e) {
69                 getOutputStream().println("Error : Not authorized to change userdata.");
70             } catch (UserDoesntFullfillEndEntityProfile e) {
71                 getOutputStream().println("Error : Given userdata doesn't fullfill end entity profile. : " + e.getMessage());
72             }
73         } catch (Exception JavaDoc e) {
74             throw new ErrorAdminCommandException(e);
75         }
76     }
77
78     // execute
79
}
80
Popular Tags