@Test public void getUserProfileReturnsCreationDate() { UserRepresentation userRepresentation = new UserRepresentation(); Date creationDate = DateUtil.parse("2018-01-31"); userRepresentation.setCreatedTimestamp(creationDate.getTime()); userRepresentation.setEmail("davy.van.roy@gmail.com"); when(keycloakRepository.getUser("davy")).thenReturn(userRepresentation); when(keycloakRepository.getUserIdentities("davy")).thenReturn(Stream.empty()); UserProfile userProfile = profileService.getUserProfile(() -> "davy"); assertThat(userProfile.getCreatedAt()).isEqualTo(creationDate.getTime()); }
@Override @Cacheable(value = "user_profile", key = "#principal.name") public UserProfile getUserProfile(Principal principal) { final Map<Provider, UserProfileProvider> providers = keycloakRepository.getUserIdentities(principal.getName()) .collect(Collectors.toMap(UserIdentity::getProvider, x -> UserProfileProvider.builder() .userId(x.getUserId()) .username(x.getUsername()) .build())); final UserRepresentation user = keycloakRepository.getUser(principal.getName()); List<Wallet> wallets = new ArrayList<>(); if (principal.getClass().isAssignableFrom(KeycloakAuthenticationToken.class)) { wallets = providers.containsKey(Provider.ARKANE) ? getWallets(principal, providers, getArkaneAccessTokenWithoutCheck((KeycloakAuthenticationToken) principal)) : Collections.emptyList(); } return UserProfile.builder() .id(user.getId()) .name(user.getFirstName() + " " + user.getLastName()) .createdAt(user.getCreatedTimestamp()) .email(user.getEmail()) .picture(getPicture(user)) .wallets(wallets) .etherAddresses(wallets.stream().map(Wallet::getAddress).collect(Collectors.toList())) .verifiedDeveloper(keycloakRepository.isVerifiedDeveloper(user)) .telegramName(keycloakRepository.getTelegramName(user)) .headline(keycloakRepository.getHeadline(user)) .github(providers.get(Provider.GITHUB)) .arkane(providers.get(Provider.ARKANE)) .linkedin(providers.get(Provider.LINKEDIN)) .twitter(providers.get(Provider.TWITTER)) .google(providers.get(Provider.GOOGLE)) .stackoverflow(providers.get(Provider.STACKOVERFLOW)) .emailSignedVerification(getEmailSignedVerification(user.getEmail())) .build(); }
ProfileServiceImpl implements ProfileService { @Override @Cacheable(value = "user_profile", key = "#principal.name") public UserProfile getUserProfile(Principal principal) { final Map<Provider, UserProfileProvider> providers = keycloakRepository.getUserIdentities(principal.getName()) .collect(Collectors.toMap(UserIdentity::getProvider, x -> UserProfileProvider.builder() .userId(x.getUserId()) .username(x.getUsername()) .build())); final UserRepresentation user = keycloakRepository.getUser(principal.getName()); List<Wallet> wallets = new ArrayList<>(); if (principal.getClass().isAssignableFrom(KeycloakAuthenticationToken.class)) { wallets = providers.containsKey(Provider.ARKANE) ? getWallets(principal, providers, getArkaneAccessTokenWithoutCheck((KeycloakAuthenticationToken) principal)) : Collections.emptyList(); } return UserProfile.builder() .id(user.getId()) .name(user.getFirstName() + " " + user.getLastName()) .createdAt(user.getCreatedTimestamp()) .email(user.getEmail()) .picture(getPicture(user)) .wallets(wallets) .etherAddresses(wallets.stream().map(Wallet::getAddress).collect(Collectors.toList())) .verifiedDeveloper(keycloakRepository.isVerifiedDeveloper(user)) .telegramName(keycloakRepository.getTelegramName(user)) .headline(keycloakRepository.getHeadline(user)) .github(providers.get(Provider.GITHUB)) .arkane(providers.get(Provider.ARKANE)) .linkedin(providers.get(Provider.LINKEDIN)) .twitter(providers.get(Provider.TWITTER)) .google(providers.get(Provider.GOOGLE)) .stackoverflow(providers.get(Provider.STACKOVERFLOW)) .emailSignedVerification(getEmailSignedVerification(user.getEmail())) .build(); } }
ProfileServiceImpl implements ProfileService { @Override @Cacheable(value = "user_profile", key = "#principal.name") public UserProfile getUserProfile(Principal principal) { final Map<Provider, UserProfileProvider> providers = keycloakRepository.getUserIdentities(principal.getName()) .collect(Collectors.toMap(UserIdentity::getProvider, x -> UserProfileProvider.builder() .userId(x.getUserId()) .username(x.getUsername()) .build())); final UserRepresentation user = keycloakRepository.getUser(principal.getName()); List<Wallet> wallets = new ArrayList<>(); if (principal.getClass().isAssignableFrom(KeycloakAuthenticationToken.class)) { wallets = providers.containsKey(Provider.ARKANE) ? getWallets(principal, providers, getArkaneAccessTokenWithoutCheck((KeycloakAuthenticationToken) principal)) : Collections.emptyList(); } return UserProfile.builder() .id(user.getId()) .name(user.getFirstName() + " " + user.getLastName()) .createdAt(user.getCreatedTimestamp()) .email(user.getEmail()) .picture(getPicture(user)) .wallets(wallets) .etherAddresses(wallets.stream().map(Wallet::getAddress).collect(Collectors.toList())) .verifiedDeveloper(keycloakRepository.isVerifiedDeveloper(user)) .telegramName(keycloakRepository.getTelegramName(user)) .headline(keycloakRepository.getHeadline(user)) .github(providers.get(Provider.GITHUB)) .arkane(providers.get(Provider.ARKANE)) .linkedin(providers.get(Provider.LINKEDIN)) .twitter(providers.get(Provider.TWITTER)) .google(providers.get(Provider.GOOGLE)) .stackoverflow(providers.get(Provider.STACKOVERFLOW)) .emailSignedVerification(getEmailSignedVerification(user.getEmail())) .build(); } ProfileServiceImpl(final KeycloakRepository keycloakRepository,
                              final @Value("${keycloak.auth-server-url}") String keycloakUrl,
                              final @Value("${io.fundrequest.intercom.secret}") String intercomHmacKey,
                              final ApplicationEventPublisher eventPublisher, ArkaneRepository arkaneRepository); }
ProfileServiceImpl implements ProfileService { @Override @Cacheable(value = "user_profile", key = "#principal.name") public UserProfile getUserProfile(Principal principal) { final Map<Provider, UserProfileProvider> providers = keycloakRepository.getUserIdentities(principal.getName()) .collect(Collectors.toMap(UserIdentity::getProvider, x -> UserProfileProvider.builder() .userId(x.getUserId()) .username(x.getUsername()) .build())); final UserRepresentation user = keycloakRepository.getUser(principal.getName()); List<Wallet> wallets = new ArrayList<>(); if (principal.getClass().isAssignableFrom(KeycloakAuthenticationToken.class)) { wallets = providers.containsKey(Provider.ARKANE) ? getWallets(principal, providers, getArkaneAccessTokenWithoutCheck((KeycloakAuthenticationToken) principal)) : Collections.emptyList(); } return UserProfile.builder() .id(user.getId()) .name(user.getFirstName() + " " + user.getLastName()) .createdAt(user.getCreatedTimestamp()) .email(user.getEmail()) .picture(getPicture(user)) .wallets(wallets) .etherAddresses(wallets.stream().map(Wallet::getAddress).collect(Collectors.toList())) .verifiedDeveloper(keycloakRepository.isVerifiedDeveloper(user)) .telegramName(keycloakRepository.getTelegramName(user)) .headline(keycloakRepository.getHeadline(user)) .github(providers.get(Provider.GITHUB)) .arkane(providers.get(Provider.ARKANE)) .linkedin(providers.get(Provider.LINKEDIN)) .twitter(providers.get(Provider.TWITTER)) .google(providers.get(Provider.GOOGLE)) .stackoverflow(providers.get(Provider.STACKOVERFLOW)) .emailSignedVerification(getEmailSignedVerification(user.getEmail())) .build(); } ProfileServiceImpl(final KeycloakRepository keycloakRepository,
                              final @Value("${keycloak.auth-server-url}") String keycloakUrl,
                              final @Value("${io.fundrequest.intercom.secret}") String intercomHmacKey,
                              final ApplicationEventPublisher eventPublisher, ArkaneRepository arkaneRepository); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name", beforeInvocation = true) void userProviderIdentityLinked(Principal principal, Provider provider); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void walletsManaged(Principal principal); @Override @Cacheable(value = "other_user_profile", key = "#userId") UserProfile getNonLoggedInUserProfile(String userId); @Override @Cacheable(value = "user_profile", key = "#principal.name") UserProfile getUserProfile(Principal principal); @EventListener @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#event.userId") void onDeveloperVerified(DeveloperVerified event); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void updateEtherAddress(Principal principal, String etherAddress); @Override String getArkaneAccessToken(KeycloakAuthenticationToken principal); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void updateTelegramName(Principal principal, String telegramName); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void updateHeadline(Principal principal, String headline); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void logout(Principal principal); @Override String createSignupLink(HttpServletRequest request, Principal principal, Provider providerEnum, String redirectUrl); }
ProfileServiceImpl implements ProfileService { @Override @Cacheable(value = "user_profile", key = "#principal.name") public UserProfile getUserProfile(Principal principal) { final Map<Provider, UserProfileProvider> providers = keycloakRepository.getUserIdentities(principal.getName()) .collect(Collectors.toMap(UserIdentity::getProvider, x -> UserProfileProvider.builder() .userId(x.getUserId()) .username(x.getUsername()) .build())); final UserRepresentation user = keycloakRepository.getUser(principal.getName()); List<Wallet> wallets = new ArrayList<>(); if (principal.getClass().isAssignableFrom(KeycloakAuthenticationToken.class)) { wallets = providers.containsKey(Provider.ARKANE) ? getWallets(principal, providers, getArkaneAccessTokenWithoutCheck((KeycloakAuthenticationToken) principal)) : Collections.emptyList(); } return UserProfile.builder() .id(user.getId()) .name(user.getFirstName() + " " + user.getLastName()) .createdAt(user.getCreatedTimestamp()) .email(user.getEmail()) .picture(getPicture(user)) .wallets(wallets) .etherAddresses(wallets.stream().map(Wallet::getAddress).collect(Collectors.toList())) .verifiedDeveloper(keycloakRepository.isVerifiedDeveloper(user)) .telegramName(keycloakRepository.getTelegramName(user)) .headline(keycloakRepository.getHeadline(user)) .github(providers.get(Provider.GITHUB)) .arkane(providers.get(Provider.ARKANE)) .linkedin(providers.get(Provider.LINKEDIN)) .twitter(providers.get(Provider.TWITTER)) .google(providers.get(Provider.GOOGLE)) .stackoverflow(providers.get(Provider.STACKOVERFLOW)) .emailSignedVerification(getEmailSignedVerification(user.getEmail())) .build(); } ProfileServiceImpl(final KeycloakRepository keycloakRepository,
                              final @Value("${keycloak.auth-server-url}") String keycloakUrl,
                              final @Value("${io.fundrequest.intercom.secret}") String intercomHmacKey,
                              final ApplicationEventPublisher eventPublisher, ArkaneRepository arkaneRepository); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name", beforeInvocation = true) void userProviderIdentityLinked(Principal principal, Provider provider); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void walletsManaged(Principal principal); @Override @Cacheable(value = "other_user_profile", key = "#userId") UserProfile getNonLoggedInUserProfile(String userId); @Override @Cacheable(value = "user_profile", key = "#principal.name") UserProfile getUserProfile(Principal principal); @EventListener @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#event.userId") void onDeveloperVerified(DeveloperVerified event); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void updateEtherAddress(Principal principal, String etherAddress); @Override String getArkaneAccessToken(KeycloakAuthenticationToken principal); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void updateTelegramName(Principal principal, String telegramName); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void updateHeadline(Principal principal, String headline); @Override @CacheEvict(value = {"user_profile", "other_user_profile"}, key = "#principal.name") void logout(Principal principal); @Override String createSignupLink(HttpServletRequest request, Principal principal, Provider providerEnum, String redirectUrl);  }