public static int getOrCreateCertificateProfile(Admin admin, int templateIndex, CertificateProfileSession certificateProfileSession) {
String certProfileName = "Autoenroll-" + SUPPORTEDCERTIFICATETEMPLATES[templateIndex];
// Create certificate profile if neccesary
boolean newCertificateProfile = false;
CertificateProfile certProfile = certificateProfileSession.getCertificateProfile(admin, certProfileName);
if (certProfile == null) {
certProfile = new CertificateProfile();
try {
certificateProfileSession.addCertificateProfile(admin, certProfileName, certProfile);
newCertificateProfile = true;
} catch (CertificateProfileExistsException e) {
throw new EJBException(e); // We just checked for this so this cannot happen
}
}
// Add User-specifics to profiles if nessesary
int[] keyUsages = KEYUSAGES[templateIndex];
String[] extendedKeyUsages = EXTENDEDKEYUSAGES[templateIndex];
if (newCertificateProfile) {
certProfile.setUseKeyUsage(true);
certProfile.setKeyUsageCritical(true);
certProfile.setKeyUsage(new boolean[9]);
for (int i=0; i<keyUsages.length; i++) {
certProfile.setKeyUsage(keyUsages[i], true);
}
certProfile.setUseExtendedKeyUsage(true);
certProfile.setExtendedKeyUsageCritical(true);
ArrayList<String> eku = new ArrayList<String>();
for (int i=0; i<extendedKeyUsages.length; i++) {
eku.add(extendedKeyUsages[i]);
}
certProfile.setExtendedKeyUsage(eku);
if (USE_CA_CDP[templateIndex]) {
certProfile.setUseCRLDistributionPoint(true);
certProfile.setUseDefaultCRLDistributionPoint(true);
}
if (MS_TEMPLATE_VALUE[templateIndex] != null) {
certProfile.setUseMicrosoftTemplate(true);
certProfile.setMicrosoftTemplate(MS_TEMPLATE_VALUE[templateIndex]);
}
}
certificateProfileSession.changeCertificateProfile(admin, certProfileName, certProfile);
return certificateProfileSession.getCertificateProfileId(admin, certProfileName);
}