* Method used to convert a HardToken data to a WS version
* @param data
* @throws EjbcaException
*/
protected HardTokenDataWS convertHardTokenToWS(HardTokenData data, Collection<java.security.cert.Certificate> certificates, boolean includePUK) throws EjbcaException {
HardTokenDataWS retval = new HardTokenDataWS();
retval.setHardTokenSN(data.getTokenSN());
retval.setLabel(data.getHardToken().getLabel());
retval.setCopyOfSN(data.getCopyOf());
ArrayList<String> copies = new ArrayList<String>();
if(data.getCopies() != null){
Iterator<String> iter = data.getCopies().iterator();
while(iter.hasNext()){
copies.add(iter.next());
}
}
retval.setCopies(copies);
try{
retval.setModifyTime(dateToXMKGregorianCalendar(data.getModifyTime()));
retval.setCreateTime(dateToXMKGregorianCalendar(data.getCreateTime()));
retval.setEncKeyKeyRecoverable(false);
Iterator<java.security.cert.Certificate> iter = certificates.iterator();
while(iter.hasNext()){
retval.getCertificates().add(new Certificate(iter.next()));
}
}catch(DatatypeConfigurationException e){
log.error("EJBCA WebService error, getHardToken: ",e);
throw new EjbcaException(ErrorCode.INTERNAL_ERROR, e.getMessage());
}catch(CertificateEncodingException e){
log.error("EJBCA WebService error, getHardToken: ",e);
throw new EjbcaException(ErrorCode.INTERNAL_ERROR, e.getMessage());
}
if(data.getHardToken() instanceof SwedishEIDHardToken){
SwedishEIDHardToken ht = (SwedishEIDHardToken) data.getHardToken();
if(includePUK){
retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_SIGNATURE,ht.getInitialSignaturePIN(),ht.getSignaturePUK()));
retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_BASIC,ht.getInitialAuthEncPIN(),ht.getAuthEncPUK()));
}
retval.setTokenType(HardTokenConstants.TOKENTYPE_SWEDISHEID);
return retval;
}
if(data.getHardToken() instanceof EnhancedEIDHardToken){
EnhancedEIDHardToken ht = (EnhancedEIDHardToken) data.getHardToken();
retval.setEncKeyKeyRecoverable(ht.getEncKeyRecoverable());
if(includePUK){
retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_SIGNATURE,ht.getInitialSignaturePIN(),ht.getSignaturePUK()));
retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_BASIC,ht.getInitialAuthPIN(),ht.getAuthPUK()));
}
retval.setTokenType(HardTokenConstants.TOKENTYPE_ENHANCEDEID);
return retval;
}
if(data.getHardToken() instanceof TurkishEIDHardToken){
TurkishEIDHardToken ht = (TurkishEIDHardToken) data.getHardToken();
if(includePUK){
retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_BASIC,ht.getInitialPIN(),ht.getPUK()));
}
retval.setTokenType(HardTokenConstants.TOKENTYPE_TURKISHEID);
return retval;
}
throw new EjbcaException(ErrorCode.INTERNAL_ERROR,
"Error: only SwedishEIDHardToken, EnhancedEIDHardToken, TurkishEIDHardToken supported.");
}