@Override
public HardTokenData getHardToken(Admin admin, String tokensn, boolean includePUK) throws AuthorizationDeniedException {
if (log.isTraceEnabled()) {
log.trace("<getHardToken(tokensn :" + tokensn + ")");
}
HardTokenData returnval = null;
org.ejbca.core.ejb.hardtoken.HardTokenData htd = org.ejbca.core.ejb.hardtoken.HardTokenData.findByTokenSN(entityManager, tokensn);
if (htd != null) {
// Find Copyof
String copyof = null;
HardTokenPropertyData htpd = HardTokenPropertyData.findByProperty(entityManager, tokensn, HardTokenPropertyData.PROPERTY_COPYOF);
if (htpd != null) {
copyof = htpd.getValue();
}
ArrayList<String> copies = null;
if (copyof == null) {
// Find Copies
Collection<HardTokenPropertyData> copieslocal = HardTokenPropertyData.findIdsByPropertyAndValue(entityManager,
HardTokenPropertyData.PROPERTY_COPYOF, tokensn);
if (copieslocal.size() > 0) {
copies = new ArrayList<String>();
Iterator<HardTokenPropertyData> iter = copieslocal.iterator();
while (iter.hasNext()) {
copies.add(iter.next().getId());
}
}
}
if (htd != null) {
returnval = new HardTokenData(htd.getTokenSN(), htd.getUsername(), htd.getCreateTime(), htd.getModifyTime(), htd.getTokenType(), htd
.getSignificantIssuerDN(), getHardToken(admin, globalConfigurationSession.getCachedGlobalConfiguration(admin).getHardTokenEncryptCA(),
includePUK, htd.getData()), copyof, copies);
String msg = intres.getLocalizedMessage("hardtoken.viewedtoken", tokensn);
logSession.log(admin, htd.getSignificantIssuerDN().hashCode(), LogConstants.MODULE_HARDTOKEN, new java.util.Date(), htd.getUsername(), null,
LogConstants.EVENT_INFO_HARDTOKENVIEWED, msg);