@Test public void get() { CoffeeNetUserDetails principal = new HumanCoffeeNetUser("test", "test@synyx.de", new HashSet<>()); SecurityContextImpl context = new SecurityContextImpl(); context.setAuthentication(new UsernamePasswordAuthenticationToken(principal, null)); SecurityContextHolder.setContext(context); CoffeeNetUserDetails result = sut.get().get(); assertThat(result, is(principal)); }
@Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); } }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }  }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }  @Override Optional<CoffeeNetUserDetails> get(); }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }  @Override Optional<CoffeeNetUserDetails> get();  }