throw new CADoesntExistsException("Error CA " + userdata.getCaName() + " have caid 0, which is impossible.");
}
final int endentityprofileid = endEntityProfileSession.getEndEntityProfileId(admin,userdata.getEndEntityProfileName());
if(endentityprofileid == 0){
throw new EjbcaException(ErrorCode.EE_PROFILE_NOT_EXISTS,
"Error End Entity profile " + userdata.getEndEntityProfileName() + " doesn't exists.");
}
final int certificateprofileid = certificateProfileSession.getCertificateProfileId(admin,userdata.getCertificateProfileName());
if(certificateprofileid == 0){
throw new EjbcaException(ErrorCode.CERT_PROFILE_NOT_EXISTS,
"Error Certificate profile " + userdata.getCertificateProfileName() + " doesn't exists.");
}
final int hardtokenissuerid;
if(userdata.getHardTokenIssuerName() != null){
hardtokenissuerid = hardTokenSession.getHardTokenIssuerId(admin,userdata.getHardTokenIssuerName());
if(hardtokenissuerid == 0){
throw new EjbcaException(ErrorCode.HARD_TOKEN_ISSUER_NOT_EXISTS,
"Error Hard Token Issuer " + userdata.getHardTokenIssuerName() + " doesn't exists.");
}
} else {
hardtokenissuerid = 0;
}
final int tokenid = getTokenId(admin,userdata.getTokenType());
if(tokenid == 0){
throw new EjbcaException(ErrorCode.UNKOWN_TOKEN_TYPE,
"Error Token Type " + userdata.getTokenType() + " doesn't exists.");
}
final ExtendedInformation ei = new ExtendedInformation();
boolean useEI = false;
if(userdata.getStartTime() != null) {
String customStartTime = userdata.getStartTime();
try {
if (customStartTime.length()>0 && !customStartTime.matches("^\\d+:\\d?\\d:\\d?\\d$")) {
if (!customStartTime.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{2}:\\d{2}$")) {
// We use the old absolute time format, so we need to upgrade and log deprecation info
final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US);
final String newCustomStartTime = ValidityDate.formatAsISO8601(oldDateFormat.parse(customStartTime), ValidityDate.TIMEZONE_UTC);
log.info("WS client sent userdata with startTime using US Locale date format. yyyy-MM-dd HH:mm:ssZZ should be used for absolute time and any fetched UserDataVOWS will use this format.");
if (log.isDebugEnabled()) {
log.debug(" Changed startTime \"" + customStartTime + "\" to \"" + newCustomStartTime + "\" in UserDataVOWS.");
}
customStartTime = newCustomStartTime;
}
customStartTime = ValidityDate.getImpliedUTCFromISO8601(customStartTime);
}
ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, customStartTime);
useEI = true;
} catch (ParseException e) {
log.info("WS client supplied invalid startTime in userData. startTime for this request was ignored. Supplied SubjectDN was \"" + userdata.getSubjectDN() + "\"");
throw new EjbcaException(ErrorCode.FIELD_VALUE_NOT_VALID, "Invalid date format in StartTime.");
}
}
if(userdata.getEndTime() != null) {
String customEndTime = userdata.getEndTime();
try {
if (customEndTime.length()>0 && !customEndTime.matches("^\\d+:\\d?\\d:\\d?\\d$")){
if (!customEndTime.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{2}:\\d{2}$")) {
// We use the old absolute time format, so we need to upgrade and log deprecation info
final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US);
final String newCustomStartTime = ValidityDate.formatAsISO8601(oldDateFormat.parse(customEndTime), ValidityDate.TIMEZONE_UTC);
log.info("WS client sent userdata with endTime using US Locale date format. yyyy-MM-dd HH:mm:ssZZ should be used for absolute time and any fetched UserDataVOWS will use this format.");
if (log.isDebugEnabled()) {
log.debug(" Changed endTime \"" + customEndTime + "\" to \"" + newCustomStartTime + "\" in UserDataVOWS.");
}
customEndTime = newCustomStartTime;
}
customEndTime = ValidityDate.getImpliedUTCFromISO8601(customEndTime);
}
ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, customEndTime);
useEI = true;
} catch (ParseException e) {
log.info("WS client supplied invalid endTime in userData. endTime for this request was ignored. Supplied SubjectDN was \"" + userdata.getSubjectDN() + "\"");
throw new EjbcaException(ErrorCode.FIELD_VALUE_NOT_VALID, "Invalid date format in EndTime.");
}
}
if ( userdata.getCertificateSerialNumber()!=null) {
ei.setCertificateSerialNumber(userdata.getCertificateSerialNumber());
useEI = true;