@Override
    public Optional<ErrorResponse> filter(DiscFilterRequest request) {
        try {
            Optional<AthenzPrincipal> certificatePrincipal = getClientCertificate(request)
                    .map(AthenzIdentities::from)
                    .map(AthenzPrincipal::new);
            if (certificatePrincipal.isEmpty()) {
                String errorMessage = "Unable to authenticate Athenz identity. " +
                                      "Either client certificate or principal token is required.";
                return createResponse(request, Response.Status.UNAUTHORIZED, errorMessage);
            }
            AthenzPrincipal principal = certificatePrincipal.get();
            request.setUserPrincipal(principal);
            request.setRemoteUser(principal.getName());
            request.setAttribute(RESULT_PRINCIPAL, principal);
            return Optional.empty();
        } catch (Exception e) {
            return createResponse(request, Response.Status.UNAUTHORIZED, e.getMessage());
        }
    }
@Test
    void certificate_is_accepted() {
        DiscFilterRequest request = FilterTestUtils.newRequestBuilder().withClientCertificate(CERTIFICATE).build();

        ResponseHandlerMock responseHandler = new ResponseHandlerMock();

        AthenzPrincipalFilter filter = createFilter(false);
        filter.filter(request, responseHandler);

        AthenzPrincipal expectedPrincipal = new AthenzPrincipal(IDENTITY);
        assertAuthenticated(request, expectedPrincipal);
    }