// special case used to signal regeneraton of password
newpassword = profile.getAutoGeneratedPasswd();
}
final int type = userDataVO.getType();
final ExtendedInformation ei = userDataVO.getExtendedinformation();
// Check if user fulfills it's profile.
if (globalConfiguration.getEnableEndEntityProfileLimitations()) {
try {
String dirattrs = null;
if (ei != null) {
dirattrs = ei.getSubjectDirectoryAttributes();
}
// It is only meaningful to verify the password if we change it in some way, and if we are not autogenerating it
if (!profile.useAutoGeneratedPasswd() && StringUtils.isNotEmpty(newpassword)) {
profile.doesUserFullfillEndEntityProfile(username, userDataVO.getPassword(), dn, altName, dirattrs, userDataVO.getEmail(),
userDataVO.getCertificateProfileId(), clearpwd, (type & SecConst.USER_KEYRECOVERABLE) != 0, (type & SecConst.USER_SENDNOTIFICATION) != 0,
userDataVO.getTokenType(), userDataVO.getHardTokenIssuerId(), caid, ei);
} else {
profile.doesUserFullfillEndEntityProfileWithoutPassword(username, dn, altName, dirattrs, userDataVO.getEmail(),
userDataVO.getCertificateProfileId(), (type & SecConst.USER_KEYRECOVERABLE) != 0, (type & SecConst.USER_SENDNOTIFICATION) != 0,
userDataVO.getTokenType(), userDataVO.getHardTokenIssuerId(), caid, ei);
}
} catch (UserDoesntFullfillEndEntityProfile e) {
final String msg = intres.getLocalizedMessage("ra.errorfullfillprofile", Integer.valueOf(endEntityProfileId), dn, e.getMessage());
logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null, LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
throw e;
}
}
// Check if approvals is required.
final int numOfApprovalsRequired = getNumOfApprovalRequired(admin, CAInfo.REQ_APPROVAL_ADDEDITENDENTITY, caid, userDataVO.getCertificateProfileId());
if (numOfApprovalsRequired > 0) {
final UserDataVO orguserdata = userData.toUserDataVO();
final EditEndEntityApprovalRequest ar = new EditEndEntityApprovalRequest(userDataVO, clearpwd, orguserdata, admin, null, numOfApprovalsRequired, caid, endEntityProfileId);
if (ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_CHANGEUSER)) {
approvalSession.addApprovalRequest(admin, ar, getGlobalConfiguration(admin));
throw new WaitingForApprovalException(intres.getLocalizedMessage("ra.approvaledit"));
}
}
// Check if the subjectDN serialnumber already exists.
if (caAdminSession.getCAInfoOrThrowException(admin, caid).isDoEnforceUniqueSubjectDNSerialnumber()) {
if (!isSubjectDnSerialnumberUnique(caid, dn, username)) {
throw new EjbcaException(ErrorCode.SUBJECTDN_SERIALNUMBER_ALREADY_EXISTS, "Error: SubjectDN Serialnumber already exists.");
}
}
try {
userData.setDN(dn);
userData.setSubjectAltName(altName);
userData.setSubjectEmail(userDataVO.getEmail());
userData.setCaId(caid);
userData.setType(type);
userData.setEndEntityProfileId(endEntityProfileId);
userData.setCertificateProfileId(userDataVO.getCertificateProfileId());
userData.setTokenType(userDataVO.getTokenType());
userData.setHardTokenIssuerId(userDataVO.getHardTokenIssuerId());
userData.setCardNumber(userDataVO.getCardNumber());
final int newstatus = userDataVO.getStatus();
final int oldstatus = userData.getStatus();
if (oldstatus == UserDataConstants.STATUS_KEYRECOVERY && newstatus != UserDataConstants.STATUS_KEYRECOVERY && newstatus != UserDataConstants.STATUS_INPROCESS) {
keyRecoverySession.unmarkUser(admin, username);
}
if (ei != null) {
final String requestCounter = ei.getCustomData(ExtendedInformation.CUSTOM_REQUESTCOUNTER);
if (StringUtils.equals(requestCounter, "0") && newstatus == UserDataConstants.STATUS_NEW && oldstatus != UserDataConstants.STATUS_NEW) {
// If status is set to new, we should re-set the allowed request counter to the default values
// But we only do this if no value is specified already, i.e. 0 or null
resetRequestCounter(admin, false, ei, username, endEntityProfileId);
} else {