AbstractO2AuthenticationFilter implements ContainerRequestFilter { protected final void setPrincipal(final O2Principal newPrincipal) { SecurityContext context = getSecurityContext(); O2Principal principal = Optional.ofNullable(context) .map(c -> newPrincipal.merge(c.getUserPrincipal())) .orElse(newPrincipal); O2SecurityContext newContext = new O2SecurityContext(principal); getRequest().setSecurityContext(newContext); } AbstractO2AuthenticationFilter(
            final Provider<ContainerRequest> requestProvider,
            final Provider<Session> sessionProvider);   }
@Test public void setPrincipal() { ArgumentCaptor<SecurityContext> scCaptor = ArgumentCaptor.forClass(SecurityContext.class); mockContainerRequest = spy(mockContainerRequest); Client c = new Client(); c.setId(IdUtil.next()); c.setClientSecret("secret"); O2Principal p = new O2Principal(c); assertFalse(testFilter.getSecurityContext() instanceof O2SecurityContext); testFilter.setPrincipal(p); verify(mockContainerRequest).setSecurityContext(scCaptor.capture()); SecurityContext setContext = scCaptor.getValue(); assertNotNull(setContext); assertTrue(setContext instanceof O2SecurityContext); O2Principal setPrincipal = (O2Principal) setContext.getUserPrincipal(); assertEquals(p, setPrincipal); }