if (password != null) { if (clearpwd) { setClearTextPassword(admin, username, newpassword); } else { setPassword(admin, username, newpassword); } }
    public void changeUser(Admin admin, String username, String password, String subjectdn, String subjectaltname, String email, boolean clearpwd, int endentityprofileid, int certificateprofileid,                           int type, int tokentype, int hardwaretokenissuerid, int status, int caid)            throws AuthorizationDeniedException, UserDoesntFullfillEndEntityProfile {        // String used in SQL so strip it        String dn = CertTools.stringToBCDNString(subjectdn);        dn = StringTools.strip(dn);        String newpassword = password;        boolean statuschanged = false;        debug(">changeUser(" + username + ", " + dn + ", " + email + ")");        int oldstatus;        EndEntityProfile profile = raadminsession.getEndEntityProfile(admin, endentityprofileid);        if (profile.useAutoGeneratedPasswd() && password != null) {            // special case used to signal regeneraton of password            newpassword = profile.getAutoGeneratedPasswd();        }        // Check if user fulfills it's profile.        if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {            try {                profile.doesUserFullfillEndEntityProfileWithoutPassword(username, dn, subjectaltname, email, certificateprofileid,                        (type & SecConst.USER_ADMINISTRATOR) != 0, (type & SecConst.USER_KEYRECOVERABLE) != 0, (type & SecConst.USER_SENDNOTIFICATION) != 0,                        tokentype, hardwaretokenissuerid, caid);            } catch (UserDoesntFullfillEndEntityProfile udfp) {                logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_ERROR_CHANGEDENDENTITY, "Userdata didn'nt fullfill end entity profile. + " + udfp.getMessage());                throw new UserDoesntFullfillEndEntityProfile(udfp.getMessage());            }            // Check if administrator is authorized to edit user.            if (!authorizedToEndEntityProfile(admin, endentityprofileid, AvailableAccessRules.EDIT_RIGHTS)) {                logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_ERROR_CHANGEDENDENTITY, "Administrator not authorized");                throw new AuthorizationDeniedException("Administrator not authorized to edit user.");            }        }        // Check if administrator is authorized to edit user to CA.        if (!authorizedToCA(admin, caid)) {            logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_ERROR_CHANGEDENDENTITY, "Administrator not authorized to edit user with this CA.");            throw new AuthorizationDeniedException("Administrator not authorized to edit user with given CA.");        }        try {            UserDataPK pk = new UserDataPK(username);            UserDataLocal data1 = home.findByPrimaryKey(pk);            if (password != null) {                if (clearpwd) {                    setClearTextPassword(admin, username, newpassword);                } else {                    setPassword(admin, username, newpassword);                }            }            data1.setDN(dn);            if (subjectaltname != null)                data1.setSubjectAltName(subjectaltname);            if (email != null)                data1.setSubjectEmail(email);            data1.setCAId(caid);            data1.setType(type);            data1.setEndEntityProfileId(endentityprofileid);            data1.setCertificateProfileId(certificateprofileid);            data1.setTokenType(tokentype);            data1.setHardTokenIssuerId(hardwaretokenissuerid);            oldstatus = data1.getStatus();            statuschanged = status != oldstatus;            data1.setStatus(status);            data1.setTimeModified((new java.util.Date()).getTime());            if ((type & SecConst.USER_SENDNOTIFICATION) != 0 && statuschanged && (status == UserDataLocal.STATUS_NEW || status == UserDataLocal.STATUS_KEYRECOVERY)) {                sendNotification(admin, profile, username, newpassword, dn, subjectaltname, email, caid);            }            if (statuschanged)                logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_INFO_CHANGEDENDENTITY, "New status: " + status);            else                logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_INFO_CHANGEDENDENTITY, "");        } catch (Exception e) {            logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_ERROR_CHANGEDENDENTITY, "");            error("ChangeUser:", e);            throw new EJBException(e);        }        debug("<changeUser(" + username + ", password, " + dn + ", " + email + ")");    } // changeUser