1 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 30 public class RaSetSubjDirAttrCommand extends BaseRaAdminCommand { 31 36 public RaSetSubjDirAttrCommand(String [] args) { 37 super(args); 38 } 39 40 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 username = args[1]; 55 String 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 e) { 74 throw new ErrorAdminCommandException(e); 75 } 76 } 77 78 } 80 | Popular Tags |