@Override public PublicKey compute(EndpointObjectHash key) { LOG.debug("Fetching result for getEndpointKey"); PublicKey result = null; EndpointProfileDto endpointProfile = endpointService.findEndpointProfileByKeyHash( key.getData()); if (endpointProfile != null) { try { X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec( endpointProfile.getEndpointKey()); KeyFactory keyFact = KeyFactory.getInstance(ALGORITHM); result = keyFact.generatePublic(x509KeySpec); } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { LOG.error("failed to decode key", ex); } } else { LOG.error("failed to find key by hash {}", key); } return result; } });
} catch (KaaOptimisticLockingFailureException ex) { LOG.warn("Optimistic lock detected in endpoint profile ", Arrays.toString(profile .getEndpointKey()), ex); profile = findEndpointProfileByKeyHash(profile.getEndpointKeyHash()); profile.setEndpointUserId(newEndpointUserId);
dto = getDto(endpointProfileDao.save(endpointProfileDto)); } else { if (Arrays.equals(storedProfile.getEndpointKey(), endpointProfileDto.getEndpointKey())) { LOG.debug("Got register profile for already existing profile {}. Will overwrite " + "existing profile!", keyHash);
} catch (KaaOptimisticLockingFailureException ex) { LOG.warn("Optimistic lock detected in endpoint profile ", Arrays.toString(endpoint .getEndpointKey()), ex); endpoint = getDto(endpointProfileDao.findByKeyHash(Sha1HashUtils.hashToBytes(endpoint .getEndpointKey())));
@Test public void testFindEndpointIdByKeyHash() throws Exception { EndpointProfileDto endpointProfile = generateEndpointProfile(null, null, null, null); EndpointProfile ep = endpointProfileDao.findEndpointIdByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertEquals(endpointProfile.getId(), ep.getId()); Assert.assertNull(endpointProfile.getEndpointKey()); Assert.assertNull(ep.getEndpointKey()); Assert.assertNull(ep.getEndpointUserId()); Assert.assertNull(ep.getSubscriptions()); }
if (endpointRegistrationLookup.isPresent()) { LOG.debug("Endpoint registration information found {}: {}", dto.getEndpointKey(), endpointRegistrationLookup.get()); EndpointRegistrationDto endpointRegistration = endpointRegistrationLookup.get(); if (endpointRegistration.getServerProfileBody() != null LOG.debug("Endpoint registration information not found {}", dto.getEndpointKey()); dto.getEndpointKey(), ex); throw new RuntimeException(ex); cacheService.putEndpointKey(keyHash, KeyUtil.getPublic(dto.getEndpointKey())); } catch (InvalidKeyException ex) { LOG.error("Can't generate public key for endpoint key: {}. Reason: {}", dto.getEndpointKey(), ex); throw new RuntimeException(ex);
@Test public void testFindEndpointIdByKeyHash() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); EndpointProfile ep = endpointProfileDao.findEndpointIdByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertEquals(endpointProfile.getId(), ep.getId()); Assert.assertNull(endpointProfile.getEndpointKey()); Assert.assertNull(ep.getEndpointKey()); Assert.assertNull(ep.getEndpointUserId()); Assert.assertNull(ep.getSubscriptions()); }
this.id = dto.getId(); this.applicationId = dto.getApplicationId(); this.endpointKey = dto.getEndpointKey(); this.endpointKeyHash = dto.getEndpointKeyHash(); this.endpointUserId = dto.getEndpointUserId();
this.id = dto.getId(); this.applicationId = dto.getApplicationId(); this.endpointProfileKey = getByteBuffer(dto.getEndpointKey()); this.endpointKeyHash = getByteBuffer(dto.getEndpointKeyHash()); this.endpointUserId = dto.getEndpointUserId();