### Question:
AtzProviderSync extends SynchronousProvider implements AuthorizationProvider { @Override protected AuthorizationResponse syncAuthorize(ProviderRequest providerRequest) { return providerRequest.env().path() .map(path -> { if (path.contains("public")) { return AuthorizationResponse.permit(); } if (providerRequest.securityContext().isAuthenticated()) { return AuthorizationResponse.permit(); } else { return AuthorizationResponse.deny(); } }).orElse(AuthorizationResponse.abstain()); }    }### Answer:
@Test public void testPublic() { SecurityEnvironment se = SecurityEnvironment.builder() .path("/public/some/path") .build(); EndpointConfig ep = EndpointConfig.create(); ProviderRequest request = mock(ProviderRequest.class); when(request.env()).thenReturn(se); when(request.endpointConfig()).thenReturn(ep); AtzProviderSync provider = new AtzProviderSync(); AuthorizationResponse response = provider.syncAuthorize(request); assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS)); }
@Test public void testAbstain() { SecurityEnvironment se = SecurityEnvironment.create(); EndpointConfig ep = EndpointConfig.create(); ProviderRequest request = mock(ProviderRequest.class); when(request.env()).thenReturn(se); when(request.endpointConfig()).thenReturn(ep); AtzProviderSync provider = new AtzProviderSync(); AuthorizationResponse response = provider.syncAuthorize(request); assertThat(response.status(), is(SecurityResponse.SecurityStatus.ABSTAIN)); }
@Test public void testDenied() { SecurityContext context = mock(SecurityContext.class); when(context.isAuthenticated()).thenReturn(false); SecurityEnvironment se = SecurityEnvironment.builder() .path("/private/some/path") .build(); EndpointConfig ep = EndpointConfig.create(); ProviderRequest request = mock(ProviderRequest.class); when(request.securityContext()).thenReturn(context); when(request.env()).thenReturn(se); when(request.endpointConfig()).thenReturn(ep); AtzProviderSync provider = new AtzProviderSync(); AuthorizationResponse response = provider.syncAuthorize(request); assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE)); }
@Test public void testPermitted() { SecurityContext context = mock(SecurityContext.class); when(context.isAuthenticated()).thenReturn(true); SecurityEnvironment se = SecurityEnvironment.builder() .path("/private/some/path") .build(); EndpointConfig ep = EndpointConfig.create(); ProviderRequest request = mock(ProviderRequest.class); when(request.securityContext()).thenReturn(context); when(request.env()).thenReturn(se); when(request.endpointConfig()).thenReturn(ep); AtzProviderSync provider = new AtzProviderSync(); AuthorizationResponse response = provider.syncAuthorize(request); assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS)); }