SecurityPolicyResolver extends AbstractPolicyResolver { @Override public List<Policy> resolve(StreamType streamType, ExecutionContext context) { final AuthenticationHandler authenticationHandler = handlerSelector.select(context.request()); if (authenticationHandler == null) { logger.debug("No authentication handler has been selected to process request {}. Returning an unauthorized status (401)", context.request().id()); return null; } logger.debug("Authentication handler [{}] has been selected to secure incoming request {}", authenticationHandler.name(), context.request().id()); List<AuthenticationPolicy> policies = authenticationHandler.handle(context); return createAuthenticationChain(policies); }  @Override List<Policy> resolve(StreamType streamType, ExecutionContext context); void setAuthenticationHandlerSelector(AuthenticationHandlerSelector handlerSelector);  }
@Test public void shouldReturnRequestPolicyChain_onRequest() { AuthenticationHandler securityProvider = mock(AuthenticationHandler.class); when(securityProvider.name()).thenReturn("my-provider"); when(securityProvider.handle(executionContext)).thenReturn(Collections.emptyList()); Policy policy = mock(Policy.class); when(policyManager.create(StreamType.ON_REQUEST, "my-policy", null)).thenReturn(policy); when(handlerSelector.select(request)).thenReturn(securityProvider); List<Policy> policies = securityPolicyResolver.resolve(StreamType.ON_REQUEST, executionContext); assertNotNull(policies); }