}
if (keyalgstring != null) {
keyalg = keyalgstring;
}
Admin administrator = new Admin(Admin.TYPE_PUBLIC_WEB_USER, request.getRemoteAddr());
RequestHelper helper = new RequestHelper(administrator, debug);
log.info(intres.getLocalizedMessage("certreq.receivedcertreq", username, request.getRemoteAddr()));
debug.print("Username: " + username);
// 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));
}