@Test void setNewEtherAddress() { final String userId = "agd"; final UserResource userResource = mock(UserResource.class); final UserRepresentation userRepresentation = mock(UserRepresentation.class); final Map<String, List<String>> userAttributes = new HashMap<>(); when(realmResource.users().get(userId)).thenReturn(userResource); when(userResource.toRepresentation()).thenReturn(userRepresentation); when(userRepresentation.getAttributes()).thenReturn(userAttributes); keycloakRepository.updateEtherAddress(userId, "0x13bdf"); assertThat(userAttributes.get(ETHER_ADDRESS_KEY)).isEqualTo(Collections.singletonList("0x13bdf")); assertThat(userAttributes.get(ETHER_ADDRESS_VERIFIED_KEY)).isEqualTo(Collections.singletonList("false")); verify(userResource).update(userRepresentation); }
public void updateEtherAddress(String userId, String newAddress) { final UserResource userResource = resource.users().get(userId); final UserRepresentation userRepresentation = userResource.toRepresentation(); if (userRepresentation.getAttributes() == null) { userRepresentation.setAttributes(new HashMap<>()); } if (!isCurrentAddressSameAsNew(newAddress, userRepresentation)) { userRepresentation.getAttributes().put(ETHER_ADDRESS_KEY, Collections.singletonList(newAddress)); userRepresentation.getAttributes().put(ETHER_ADDRESS_VERIFIED_KEY, Collections.singletonList(String.valueOf(Boolean.FALSE))); userResource.update(userRepresentation); } }
KeycloakRepositoryImpl implements KeycloakRepository { public void updateEtherAddress(String userId, String newAddress) { final UserResource userResource = resource.users().get(userId); final UserRepresentation userRepresentation = userResource.toRepresentation(); if (userRepresentation.getAttributes() == null) { userRepresentation.setAttributes(new HashMap<>()); } if (!isCurrentAddressSameAsNew(newAddress, userRepresentation)) { userRepresentation.getAttributes().put(ETHER_ADDRESS_KEY, Collections.singletonList(newAddress)); userRepresentation.getAttributes().put(ETHER_ADDRESS_VERIFIED_KEY, Collections.singletonList(String.valueOf(Boolean.FALSE))); userResource.update(userRepresentation); } } }
KeycloakRepositoryImpl implements KeycloakRepository { public void updateEtherAddress(String userId, String newAddress) { final UserResource userResource = resource.users().get(userId); final UserRepresentation userRepresentation = userResource.toRepresentation(); if (userRepresentation.getAttributes() == null) { userRepresentation.setAttributes(new HashMap<>()); } if (!isCurrentAddressSameAsNew(newAddress, userRepresentation)) { userRepresentation.getAttributes().put(ETHER_ADDRESS_KEY, Collections.singletonList(newAddress)); userRepresentation.getAttributes().put(ETHER_ADDRESS_VERIFIED_KEY, Collections.singletonList(String.valueOf(Boolean.FALSE))); userResource.update(userRepresentation); } } KeycloakRepositoryImpl(RealmResource resource, @Value("${keycloak.auth-server-url}") String keycloakUrl); }
KeycloakRepositoryImpl implements KeycloakRepository { public void updateEtherAddress(String userId, String newAddress) { final UserResource userResource = resource.users().get(userId); final UserRepresentation userRepresentation = userResource.toRepresentation(); if (userRepresentation.getAttributes() == null) { userRepresentation.setAttributes(new HashMap<>()); } if (!isCurrentAddressSameAsNew(newAddress, userRepresentation)) { userRepresentation.getAttributes().put(ETHER_ADDRESS_KEY, Collections.singletonList(newAddress)); userRepresentation.getAttributes().put(ETHER_ADDRESS_VERIFIED_KEY, Collections.singletonList(String.valueOf(Boolean.FALSE))); userResource.update(userRepresentation); } } KeycloakRepositoryImpl(RealmResource resource, @Value("${keycloak.auth-server-url}") String keycloakUrl); Stream<UserIdentity> getUserIdentities(String userId); UserRepresentation getUser(String userId); void updateEtherAddress(String userId, String newAddress); @Override void updateEtherAddressVerified(final String userId, final Boolean isVerified); void updateTelegramName(String userId, String telegramName); void updateHeadline(String userId, String headline); void updateVerifiedDeveloper(String userId, Boolean isVerified); @Override boolean isEtherAddressVerified(final UserRepresentation userRepresentation); boolean isVerifiedDeveloper(UserRepresentation userRepresentation); boolean isVerifiedDeveloper(final String userId); String getAttribute(UserRepresentation userRepresentation, String property); String getTelegramName(UserRepresentation userRepresentation); String getPicture(UserRepresentation userRepresentation); String getHeadline(UserRepresentation userRepresentation); String getAccessToken(@NonNull KeycloakAuthenticationToken token, @NonNull Provider provider); boolean userExists(String userId); }
KeycloakRepositoryImpl implements KeycloakRepository { public void updateEtherAddress(String userId, String newAddress) { final UserResource userResource = resource.users().get(userId); final UserRepresentation userRepresentation = userResource.toRepresentation(); if (userRepresentation.getAttributes() == null) { userRepresentation.setAttributes(new HashMap<>()); } if (!isCurrentAddressSameAsNew(newAddress, userRepresentation)) { userRepresentation.getAttributes().put(ETHER_ADDRESS_KEY, Collections.singletonList(newAddress)); userRepresentation.getAttributes().put(ETHER_ADDRESS_VERIFIED_KEY, Collections.singletonList(String.valueOf(Boolean.FALSE))); userResource.update(userRepresentation); } } KeycloakRepositoryImpl(RealmResource resource, @Value("${keycloak.auth-server-url}") String keycloakUrl); Stream<UserIdentity> getUserIdentities(String userId); UserRepresentation getUser(String userId); void updateEtherAddress(String userId, String newAddress); @Override void updateEtherAddressVerified(final String userId, final Boolean isVerified); void updateTelegramName(String userId, String telegramName); void updateHeadline(String userId, String headline); void updateVerifiedDeveloper(String userId, Boolean isVerified); @Override boolean isEtherAddressVerified(final UserRepresentation userRepresentation); boolean isVerifiedDeveloper(UserRepresentation userRepresentation); boolean isVerifiedDeveloper(final String userId); String getAttribute(UserRepresentation userRepresentation, String property); String getTelegramName(UserRepresentation userRepresentation); String getPicture(UserRepresentation userRepresentation); String getHeadline(UserRepresentation userRepresentation); String getAccessToken(@NonNull KeycloakAuthenticationToken token, @NonNull Provider provider); boolean userExists(String userId);  }