// Check user
int tokentype = SecConst.TOKEN_SOFT_BROWSERGEN;
usekeyrecovery = globalConfigurationSession.getCachedGlobalConfiguration(administrator).getEnableKeyRecovery();
UserDataVO data = userAdminSession.findUser(administrator, username);
if (data == null) {
throw new ObjectNotFoundException();
}
boolean savekeys = data.getKeyRecoverable() && usekeyrecovery && (data.getStatus() != UserDataConstants.STATUS_KEYRECOVERY);
boolean loadkeys = (data.getStatus() == UserDataConstants.STATUS_KEYRECOVERY) && usekeyrecovery;
int endEntityProfileId = data.getEndEntityProfileId();
int certificateProfileId = data.getCertificateProfileId();
EndEntityProfile endEntityProfile = endEntityProfileSession.getEndEntityProfile(administrator, endEntityProfileId);
boolean reusecertificate = endEntityProfile.getReUseKeyRecoveredCertificate();
// Set a new certificate profile, if we have requested one specific
if (StringUtils.isNotEmpty(certprofile)) {
boolean clearpwd = StringUtils.isNotEmpty(data.getPassword());
int id = certificateProfileSession.getCertificateProfileId(administrator, certprofile);
// Change the value if there exists a certprofile with the requested name, and it is not the same as
// the one already registered to be used by default
if ( (id > 0) ) {
if (id != certificateProfileId) {
// Check if it is in allowed profiles in the entity profile
Collection c = endEntityProfile.getAvailableCertificateProfileIds();
if (c.contains(String.valueOf(id))) {
data.setCertificateProfileId(id);
// This admin can be the public web user, which may not be allowed to change status,
// this is a bit ugly, but what can a man do...
Admin tempadmin = Admin.getInternalAdmin();
userAdminSession.changeUser(tempadmin, data, clearpwd);
} else {
String defaultCertificateProfileName = certificateProfileSession.getCertificateProfileName(administrator, certificateProfileId);
log.info(intres.getLocalizedMessage("certreq.badcertprofile", certprofile, defaultCertificateProfileName));
}
}
} else {
String defaultCertificateProfileName = certificateProfileSession.getCertificateProfileName(administrator, certificateProfileId);
log.info(intres.getLocalizedMessage("certreq.nosuchcertprofile", certprofile, defaultCertificateProfileName));
}
}
// get users Token Type.
tokentype = data.getTokenType();
GenerateToken tgen = new GenerateToken(authenticationSession, userAdminSession, caAdminSession, keyRecoverySession, signSession);
if(tokentype == SecConst.TOKEN_SOFT_P12){
KeyStore ks = tgen.generateOrKeyRecoverToken(administrator, username, password, data.getCAId(), keylength, keyalg, false, loadkeys, savekeys, reusecertificate, endEntityProfileId);
if (StringUtils.equals(openvpn, "on")) {
sendOpenVPNToken(ks, username, password, response);
} else {
sendP12Token(ks, username, password, response);
}
}
if(tokentype == SecConst.TOKEN_SOFT_JKS){
KeyStore ks = tgen.generateOrKeyRecoverToken(administrator, username, password, data.getCAId(), keylength, keyalg, true, loadkeys, savekeys, reusecertificate, endEntityProfileId);
sendJKSToken(ks, username, password, response);
}
if(tokentype == SecConst.TOKEN_SOFT_PEM){
KeyStore ks = tgen.generateOrKeyRecoverToken(administrator, username, password, data.getCAId(), keylength, keyalg, false, loadkeys, savekeys, reusecertificate, endEntityProfileId);
sendPEMTokens(ks, username, password, response);
}
if(tokentype == SecConst.TOKEN_SOFT_BROWSERGEN){
// first check if it is a Firefox request,