String getProfileUserId() { if (endpointProfile != null) { return endpointProfile.getEndpointUserId(); } else { return null; } }
boolean isValidForUser() { return endpointProfile != null && endpointProfile.getEndpointUserId() != null && !endpointProfile.getEndpointUserId().isEmpty(); }
boolean isValidForEvents() { return endpointProfile != null && endpointProfile.getEndpointUserId() != null && !endpointProfile.getEndpointUserId().isEmpty() && endpointProfile.getEcfVersionStates() != null && !endpointProfile.getEcfVersionStates().isEmpty(); }
@Override public byte[] fetchUcfHash(String appToken, EndpointProfileDto profile) { if (profile.getEndpointUserId() == null || profile.getEndpointUserId().isEmpty()) { return null; } EndpointUserConfigurationDto ucfDto = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion( profile.getEndpointUserId(), appToken, profile.getConfigurationVersion()); if (ucfDto != null) { return EndpointObjectHash.fromString(ucfDto.getBody()).getData(); } return null; }
response.setResult(SyncStatus.FAILURE); if (isValid(endpointDetachRequest) && isNotEmpty(profile.getEndpointUserId())) { try { byte[] endpointKeyHash = Base64Util.decode(endpointDetachRequest.getEndpointKeyHash()); endpointKeyHash); if (detachEndpoint != null) { if (detachEndpoint.getEndpointUserId() != null && detachEndpoint.getEndpointUserId().equals(profile.getEndpointUserId())) { endpointService.detachEndpointFromUser(detachEndpoint); response.setResult(SyncStatus.SUCCESS); + "but requested {} and current {} user mismatch.", Base64Util.encode(profile.getEndpointKeyHash()), profile.getEndpointUserId(), detachEndpoint.getEndpointUserId());
private void sendDisconnectFromOldUser(ActorContext context, EndpointProfileDto endpointProfile) { LOG.debug("[{}][{}] Detected user change from [{}] to [{}]", endpointKey, actorKey, state.getUserId(), endpointProfile.getEndpointUserId()); EndpointUserDisconnectMessage userDisconnectMessage = new EndpointUserDisconnectMessage( state.getUserId(), key, appToken, context.self()); context.parent().tell(userDisconnectMessage, context.self()); }
@Override public ConfigurationCacheEntry getConfiguration(String appToken, String endpointId, EndpointProfileDto profile) throws GetDeltaException { LOG.debug("[{}][{}] Calculating new configuration", appToken, endpointId); AppVersionKey appConfigVersionKey = new AppVersionKey(appToken, profile.getConfigurationVersion()); EndpointObjectHash userConfHash = EndpointObjectHash.fromBytes(profile .getUserConfigurationHash()); EndpointObjectHash epsConfHash = EndpointObjectHash.fromBytes(profile .getEpsConfigurationHash()); DeltaCacheKey deltaKey = new DeltaCacheKey(appConfigVersionKey, profile.getGroupState(), userConfHash, epsConfHash, null, profile.isUseConfigurationRawSchema(), true); LOG.debug("[{}][{}] Built resync delta key {}", appToken, endpointId, deltaKey); return getDelta(endpointId, profile.getEndpointUserId(), deltaKey, profile.isUseConfigurationRawSchema()); }
@Override public void detachEndpointFromUser(EndpointProfileDto endpoint) { String endpointUserId = endpoint.getEndpointUserId(); validateString(endpointUserId, "Incorrect endpointUserId " + endpointUserId);
String appToken, EventListenersRequest request) { if (profile.getEndpointUserId() == null || profile.getEndpointUserId().isEmpty()) { LOG.info("Can't find listeners for unassigned endpoint!"); return new EventListenersResponse(request.getRequestId(), null, SyncStatus.FAILURE); profile.getEndpointUserId()); if (endpointProfiles.size() <= 1) { LOG.info("There is only one endpoint(current) assigned to this user!");
@Override public EndpointAttachResponse attachEndpoint(EndpointProfileDto profile, EndpointAttachRequest endpointAttachRequest) { EndpointAttachResponse response = new EndpointAttachResponse(); response.setRequestId(endpointAttachRequest.getRequestId()); response.setResult(SyncStatus.FAILURE); String endpointUserId = profile.getEndpointUserId(); if (isNotEmpty(endpointUserId)) { try { EndpointProfileDto attachedEndpoint = endpointService.attachEndpointToUser( endpointUserId, endpointAttachRequest.getEndpointAccessToken()); response.setResult(SyncStatus.SUCCESS); response.setEndpointKeyHash(Base64Util.encode(attachedEndpoint.getEndpointKeyHash())); } catch (DatabaseProcessingException ex) { LOG.warn("[{}] failed to attach endpoint with access token {} and " + "user {}, exception catched: {}", Base64Util.encode(profile.getEndpointKeyHash()), endpointAttachRequest.getEndpointAccessToken(), profile.getEndpointUserId(), ex); } } else { LOG.warn("[{}] received attach endpoint request, but there is no user to attach.", Base64Util.encode(profile.getEndpointKeyHash())); } return response; }
validateString(userExternalId, "Incorrect userExternalId " + userExternalId); EndpointUser endpointUser = endpointUserDao.findByExternalIdAndTenantId(userExternalId, tenantId); String currentEndpointUserId = profile.getEndpointUserId(); String endpointId = profile.getId(); if (endpointUser == null) {
@Test public void attachEndpointToNewUserByExternalIdTest() { TenantDto tenant = generateTenantDto(); String endpointGroupId = "124"; EndpointProfileDto endpointProfile = generateEndpointProfileWithGroupIdDto(endpointGroupId); String userExternalId = UUID.randomUUID().toString(); String tenantId = tenant.getId(); EndpointProfileDto savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId, tenantId, endpointProfile); Assert.assertNotNull(savedEndpointProfile); Assert.assertNotNull(savedEndpointProfile.getEndpointUserId()); EndpointUserDto attachedEndpointUser = endpointService.findEndpointUserById(savedEndpointProfile.getEndpointUserId()); Assert.assertNotNull(attachedEndpointUser); Assert.assertEquals(userExternalId, attachedEndpointUser.getExternalId()); Assert.assertEquals(userExternalId, attachedEndpointUser.getUsername()); Assert.assertEquals(tenantId, attachedEndpointUser.getTenantId()); List<String> endpointIds = attachedEndpointUser.getEndpointIds(); Assert.assertNotNull(endpointIds); Assert.assertEquals(1, endpointIds.size()); Assert.assertEquals(endpointProfile.getId(), endpointIds.get(0)); }
@Test public void attachEndpointToExistingUserByExternalIdTest() { TenantDto tenant = generateTenantDto(); String endpointGroupId = "124"; EndpointProfileDto endpointProfile = generateEndpointProfileWithGroupIdDto(endpointGroupId); String tenantId = tenant.getId(); EndpointUserDto endpointUserDto = generateEndpointUserDto(tenantId); String userExternalId = endpointUserDto.getExternalId(); EndpointProfileDto savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId, tenantId, endpointProfile); Assert.assertNotNull(savedEndpointProfile); Assert.assertNotNull(savedEndpointProfile.getEndpointUserId()); EndpointUserDto attachedEndpointUser = endpointService.findEndpointUserById(savedEndpointProfile.getEndpointUserId()); Assert.assertNotNull(attachedEndpointUser); Assert.assertEquals(userExternalId, attachedEndpointUser.getExternalId()); Assert.assertEquals(tenantId, attachedEndpointUser.getTenantId()); List<String> endpointIds = attachedEndpointUser.getEndpointIds(); Assert.assertNotNull(endpointIds); Assert.assertEquals(1, endpointIds.size()); Assert.assertEquals(endpointProfile.getId(), endpointIds.get(0)); }
@Test public void attachEndpointAlreadyAttachedToAnotherUserByExternalIdTest() { TenantDto tenant = generateTenantDto(); String endpointGroupId = "124"; EndpointProfileDto endpointProfile = generateEndpointProfileWithGroupIdDto(endpointGroupId); String tenantId = tenant.getId(); EndpointUserDto endpointUser1 = generateEndpointUserDto(tenantId); String userExternalId1 = endpointUser1.getExternalId(); EndpointUserDto endpointUser2 = generateEndpointUserDto(tenantId); String userExternalId2 = endpointUser2.getExternalId(); EndpointProfileDto savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId1, tenantId, endpointProfile); savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId2, tenantId, savedEndpointProfile); EndpointUserDto attachedUser = endpointService.findEndpointUserById(savedEndpointProfile.getEndpointUserId()); endpointUser1 = endpointService.findEndpointUserByExternalIdAndTenantId(userExternalId1, tenantId); endpointUser2 = endpointService.findEndpointUserByExternalIdAndTenantId(userExternalId2, tenantId); Assert.assertNotNull(attachedUser); Assert.assertEquals(endpointUser2, attachedUser); List<String> user1EndpointIds = endpointUser1.getEndpointIds(); List<String> user2EndpointIds = endpointUser2.getEndpointIds(); Assert.assertTrue(CollectionUtils.isEmpty(user1EndpointIds)); Assert.assertFalse(CollectionUtils.isEmpty(user2EndpointIds)); Assert.assertEquals(1, user2EndpointIds.size()); Assert.assertEquals(endpointProfile.getId(), user2EndpointIds.get(0)); Assert.assertEquals(endpointUser2.getId(), savedEndpointProfile.getEndpointUserId()); }
@Test public void attachEndpointToAlreadyAttachedUserByExternalIdTest() { TenantDto tenant = generateTenantDto(); String endpointGroupId = "124"; EndpointProfileDto endpointProfile = generateEndpointProfileWithGroupIdDto(endpointGroupId); String tenantId = tenant.getId(); EndpointUserDto endpointUserDto = generateEndpointUserDto(tenantId); String userExternalId = endpointUserDto.getExternalId(); EndpointProfileDto savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId, tenantId, endpointProfile); savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId, tenantId, savedEndpointProfile); Assert.assertNotNull(savedEndpointProfile); Assert.assertNotNull(savedEndpointProfile.getEndpointUserId()); EndpointUserDto attachedEndpointUser = endpointService.findEndpointUserById(savedEndpointProfile.getEndpointUserId()); Assert.assertNotNull(attachedEndpointUser); Assert.assertEquals(userExternalId, attachedEndpointUser.getExternalId()); Assert.assertEquals(tenantId, attachedEndpointUser.getTenantId()); List<String> endpointIds = attachedEndpointUser.getEndpointIds(); Assert.assertNotNull(endpointIds); Assert.assertEquals(1, endpointIds.size()); Assert.assertEquals(endpointProfile.getId(), endpointIds.get(0)); }
endpointProfileView.setSdkProfileDto(controlService.findSdkProfileByToken( endpointProfile.getSdkToken())); if (endpointProfile.getEndpointUserId() != null) { EndpointUserDto endpointUser = controlService.getEndpointUser( endpointProfile.getEndpointUserId()); if (endpointUser != null) { endpointProfileView.setUserId(endpointUser.getId());
this.endpointKey = dto.getEndpointKey(); this.endpointKeyHash = dto.getEndpointKeyHash(); this.endpointUserId = dto.getEndpointUserId(); this.accessToken = dto.getAccessToken(); this.groupState = MongoDaoUtil.convertDtoToModelList(dto.getGroupState());
this.endpointProfileKey = getByteBuffer(dto.getEndpointKey()); this.endpointKeyHash = getByteBuffer(dto.getEndpointKeyHash()); this.endpointUserId = dto.getEndpointUserId(); this.accessToken = dto.getAccessToken(); this.groupStates = convertDtoToModelList(dto.getGroupState());