getAdminSession().setUserStatus(administrator, username, UserDataConstants.STATUS_GENERATED,false);
getAdminSession().setUserStatus(administrator, username, UserDataConstants.STATUS_GENERATED);
	public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {		//getOutputStream().println("Certificate import tool. V 1.1, (c) 2005 CSITA - University of Genoa (Italy)");		debug(">execute()");		if ((args.length < 6) || (args.length > 8)) {			usage();			return;		}				try {			int type = SecConst.USER_ENDUSER;			int status;			if ("ACTIVE".equalsIgnoreCase(args[4])) {				status = CertificateDataBean.CERT_ACTIVE;			}			else if ("REVOKED".equalsIgnoreCase(args[4])) {				status = CertificateDataBean.CERT_REVOKED;			}			else {				throw new Exception("Invalid certificate status.");			}						X509Certificate certificate = loadcert(args[5]);			String fingerprint = CertTools.getFingerprintAsString(certificate);			if (getCertificateStoreSession().findCertificateByFingerprint(administrator, fingerprint) != null) {				throw new Exception("Certificate number '" + certificate.getSerialNumber().toString() + "' is already present.");			}			if (certificate.getNotAfter().compareTo(new java.util.Date()) < 0) {				status = CertificateDataBean.CERT_EXPIRED;			}						String username = args[1];			// Check if username already exists.			UserDataVO userdata = getAdminSession().findUser(administrator, username);			if (userdata != null) {				if (userdata.getStatus() != UserDataConstants.STATUS_REVOKED) {					throw new Exception("User " + username +					" already exists; only revoked user can be overwrite.");				}			}			String password = args[2];			CAInfo cainfo = getCAInfo(args[3]);						CertTools.verify(certificate, cainfo.getCertificateChain());						String email = CertTools.getEMailAddress(certificate);						int endentityprofileid = SecConst.EMPTY_ENDENTITYPROFILE;			if (args.length > 6) {				debug("Searching for End Entity Profile " + args[6]);				endentityprofileid = getRaAdminSession().getEndEntityProfileId(administrator, args[6]);				if (endentityprofileid == 0) {					error("End Entity Profile " + args[6] + " doesn't exists.");					throw new Exception("End Entity Profile '" + args[6] + "' doesn't exists.");				}			}						int certificateprofileid = SecConst.CERTPROFILE_FIXED_ENDUSER;			if (args.length > 7) {				debug("Searching for Certificate Profile " + args[7]);				certificateprofileid = getCertificateStoreSession().getCertificateProfileId(administrator, args[7]);				if (certificateprofileid == SecConst.PROFILE_NO_PROFILE) {					error("Certificate Profile " + args[7] + " doesn't exists.");					throw new Exception("Certificate Profile '" + args[7] + "' doesn't exists.");				}			}						getOutputStream().println("Trying to add user:");			getOutputStream().println("Username: " + username);			getOutputStream().println("Password (hashed only): " + password);			getOutputStream().println("DN: " + certificate.getSubjectDN());			getOutputStream().println("CA Name: " + args[3]);			getOutputStream().println("Certificate Profile: " + getCertificateStoreSession().getCertificateProfileName(administrator, certificateprofileid));			getOutputStream().println("End Entity Profile: " +					getRaAdminSession().getEndEntityProfileName(administrator, endentityprofileid));						String subjectAltName = CertTools.getSubjectAlternativeName(certificate);			if (subjectAltName != null) {				getOutputStream().println("SubjectAltName: " + subjectAltName);			}			getOutputStream().println("Type: " + type);						debug("Loading/updating user " + username);			if (userdata == null) {				getAdminSession().addUser(administrator,						username, password,						certificate.getSubjectDN().getName(),						subjectAltName, email,						false,						endentityprofileid,						certificateprofileid,						type,						SecConst.TOKEN_SOFT_BROWSERGEN,						SecConst.NO_HARDTOKENISSUER,						cainfo.getCAId());				if (status == CertificateDataBean.CERT_ACTIVE) {					getAdminSession().setUserStatus(administrator, username, UserDataConstants.STATUS_GENERATED,false);				}				else {					getAdminSession().setUserStatus(administrator, username, UserDataConstants.STATUS_REVOKED,false);				}				getOutputStream().println("User '" + args[1] + "' has been added.");			}			else {				getAdminSession().changeUser(administrator,						username, password,						certificate.getSubjectDN().getName(),						subjectAltName, email,						false,						endentityprofileid,						certificateprofileid,						type,						SecConst.TOKEN_SOFT_BROWSERGEN,						SecConst.NO_HARDTOKENISSUER,						(status == CertificateDataBean.CERT_ACTIVE ?								UserDataConstants.STATUS_GENERATED :									UserDataConstants.STATUS_REVOKED),									cainfo.getCAId());				getOutputStream().println("User '" + args[1] + "' has been updated.");			}						getCertificateStoreSession().storeCertificate(administrator,					certificate, username,					fingerprint,					status, type);						getOutputStream().println("Certificate number '" + certificate.getSerialNumber().toString() + "' has been added.");		}		catch (Exception e) {			getOutputStream().println("Error: " + e.getMessage());			usage();		}		debug("<execute()");	}