@Test public void getLoggedInUserProfile_noUserProfile() { final Authentication authentication = mock(Authentication.class); final String userId = "fdsgzdg"; final Principal principal = mock(Principal.class); when(authentication.isAuthenticated()).thenReturn(true); when(authentication.getPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn(userId); when(profileService.getUserProfile(principal)).thenReturn(null); when(securityContextHolder.getContext().getAuthentication()).thenReturn(authentication); final Optional<UserProfile> result = securityContextService.getLoggedInUserProfile(); assertThat(result).isEmpty(); }
@Override public Optional<UserProfile> getLoggedInUserProfile() { return getLoggedInUser().filter(this::isUserFullyAuthenticated) .map(authentication -> (Principal) authentication.getPrincipal()) .map(profileService::getUserProfile); }
SecurityContextServiceImpl implements SecurityContextService { @Override public Optional<UserProfile> getLoggedInUserProfile() { return getLoggedInUser().filter(this::isUserFullyAuthenticated) .map(authentication -> (Principal) authentication.getPrincipal()) .map(profileService::getUserProfile); } }
SecurityContextServiceImpl implements SecurityContextService { @Override public Optional<UserProfile> getLoggedInUserProfile() { return getLoggedInUser().filter(this::isUserFullyAuthenticated) .map(authentication -> (Principal) authentication.getPrincipal()) .map(profileService::getUserProfile); } SecurityContextServiceImpl(final SecurityContextHolderSpringDelegate securityContextHolder, final ProfileService profileService); }
SecurityContextServiceImpl implements SecurityContextService { @Override public Optional<UserProfile> getLoggedInUserProfile() { return getLoggedInUser().filter(this::isUserFullyAuthenticated) .map(authentication -> (Principal) authentication.getPrincipal()) .map(profileService::getUserProfile); } SecurityContextServiceImpl(final SecurityContextHolderSpringDelegate securityContextHolder, final ProfileService profileService); @Override Optional<Authentication> getLoggedInUser(); @Override boolean isUserFullyAuthenticated(); @Override Optional<UserProfile> getLoggedInUserProfile(); }
SecurityContextServiceImpl implements SecurityContextService { @Override public Optional<UserProfile> getLoggedInUserProfile() { return getLoggedInUser().filter(this::isUserFullyAuthenticated) .map(authentication -> (Principal) authentication.getPrincipal()) .map(profileService::getUserProfile); } SecurityContextServiceImpl(final SecurityContextHolderSpringDelegate securityContextHolder, final ProfileService profileService); @Override Optional<Authentication> getLoggedInUser(); @Override boolean isUserFullyAuthenticated(); @Override Optional<UserProfile> getLoggedInUserProfile();  }