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;
}
// Set generic Custom ExtendedInformation from potential data in UserDataVOWS
List<ExtendedInformationWS> userei = userdata.getExtendedInformation();
if (userei != null) {
for (ExtendedInformationWS item : userei) {
String key = item.getName();
String value = item.getValue ();
if ((key != null) && (value != null)) {
if (log.isDebugEnabled()) {
log.debug("Set generic extended information: "+key+", "+value);
}
ei.setMapData(key, value);
useEI = true;
} else {
if (log.isDebugEnabled()) {
log.debug("Key or value is null when trying to set generic extended information.");
}