profileid = newprofileid;
}
}
if (!error) {
CertificateProfile cprofile = null;
EndEntityProfile eprofile = null;
FileInputStream is = new FileInputStream(infiles[i]);
XMLDecoder decoder = new XMLDecoder( is );
if (entityprofile) {
eprofile = new EndEntityProfile();
eprofile.loadData(decoder.readObject());
// Translate cert profile ids that have changed after import
String availableCertProfiles = "";
String defaultCertProfile = eprofile.getValue(EndEntityProfile.DEFAULTCERTPROFILE,0);
//getLogger().debug("Debug: Org - AVAILCERTPROFILES " + eprofile.getValue(EndEntityProfile.AVAILCERTPROFILES,0) + " DEFAULTCERTPROFILE "+defaultCertProfile);
for (String currentCertProfile : (Collection<String>) eprofile.getAvailableCertificateProfileIds()) {
Integer currentCertProfileId = Integer.parseInt(currentCertProfile);
Integer replacementCertProfileId = certificateProfileIdMapping.get(currentCertProfileId);
if ( replacementCertProfileId != null ) {
if (!replacementCertProfileId.toString().equals(currentCertProfile)) {
getLogger().warn("Replacing cert profile with id "+currentCertProfile+" with " + replacementCertProfileId + ".");
}
availableCertProfiles += (availableCertProfiles.equals("") ? "" : ";" ) + replacementCertProfileId;
if (currentCertProfile.equals(defaultCertProfile)) {
defaultCertProfile = ""+replacementCertProfileId;
}
} else {
if (ejb.getCertificateProfileSession().getCertificateProfile(getAdmin(), currentCertProfileId) != null ||
SecConst.isFixedCertificateProfile(currentCertProfileId)) {
availableCertProfiles += (availableCertProfiles.equals("") ? "" : ";" ) + currentCertProfile;
} else {
getLogger().warn("End Entity Profile '"+profilename+"' references certificate profile " + currentCertProfile + " that does not exist.");
if (currentCertProfile.equals(defaultCertProfile)) {
defaultCertProfile = "";
}
}
}
}
if (availableCertProfiles.equals("")) {
getLogger().warn("End Entity Profile only references certificate profile(s) that does not exist. Using ENDUSER profile.");
availableCertProfiles = "1"; // At least make sure the default profile is available
}
if (defaultCertProfile.equals("")) {
defaultCertProfile = availableCertProfiles.split(";")[0]; // Use first available profile from list as default if original default was missing
}
eprofile.setValue(EndEntityProfile.AVAILCERTPROFILES, 0, availableCertProfiles);
eprofile.setValue(EndEntityProfile.DEFAULTCERTPROFILE,0, defaultCertProfile);
// Remove any unknown CA and break if none is left
String defaultCA = eprofile.getValue(EndEntityProfile.DEFAULTCA,0);
String availableCAs = eprofile.getValue(EndEntityProfile.AVAILCAS,0);
//getOutputStream().println("Debug: Org - AVAILCAS " + availableCAs + " DEFAULTCA "+defaultCA);
List<String> cas = Arrays.asList(availableCAs.split(";"));
availableCAs = "";
for ( String currentCA : cas ) {
Integer currentCAInt = Integer.parseInt(currentCA);
// The constant ALLCAS will not be searched for among available CAs
if ( (currentCAInt.intValue() != SecConst.ALLCAS) && (ejb.getCAAdminSession().getCAInfo(getAdmin(), currentCAInt) == null) ) {
getLogger().warn("CA with id " + currentCA + " was not found and will not be used in end entity profile '" + profilename + "'.");
if (defaultCA.equals(currentCA)) {
defaultCA = "";
}
} else {
availableCAs += (availableCAs.equals("") ? "" : ";" ) + currentCA;
}
}
if (availableCAs.equals("")) {
if (caid == null) {
getLogger().error("No CAs left in end entity profile '" + profilename + "' and no CA specified on command line. Using ALLCAs.");
availableCAs = Integer.toString(SecConst.ALLCAS);
} else {
availableCAs = Integer.toString(caid);
getLogger().warn("No CAs left in end entity profile '" + profilename + "'. Using CA supplied on command line with id '"+caid+"'.");
}
}
if (defaultCA.equals("")) {
defaultCA = availableCAs.split(";")[0]; // Use first available
getLogger().warn("Changing default CA in end entity profile '" + profilename + "' to "+defaultCA+".");
}
//getLogger().debug("New - AVAILCAS " + availableCAs + " DEFAULTCA "+defaultCA);
eprofile.setValue(EndEntityProfile.AVAILCAS, 0, availableCAs);
eprofile.setValue(EndEntityProfile.DEFAULTCA, 0, defaultCA);
try{
ejb.getEndEntityProfileSession().addEndEntityProfile(getAdmin(),profileid,profilename,eprofile);
getLogger().info("Added entity profile '"+profilename+"' to database.");
}catch(EndEntityProfileExistsException eepee){
getLogger().error("Error adding entity profile '"+profilename+"' to database.");