class EndpointPersonalCertificateAuthorizationFilter implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {

        try {

            byte[] certificate = extractPersonalCertificate(requestContext);

            if (certificate != null) {
                VitamThreadUtils.getVitamSession()
                    .setPersonalCertificate(ParsedCertificate.parseCertificate(certificate).getCertificateHash());
            }

            boolean isPersonalCertificateRequired = getIsPersonalCertificateRequired();

            if (!isPersonalCertificateRequired) {
                LOGGER.debug("Personal certificate check skipped for permission {0}", permission);
                return;
            }
            LOGGER.debug("Personal certificate check required for permission {0}", permission);
            internalSecurityClient.checkPersonalCertificate(certificate, permission);

        } catch (InternalSecurityException |
            VitamClientInternalException |
            VitamSecurityException | PersonalCertificateException e) {
            LOGGER.error("An error occured during authorization filter check", e);
            final VitamError vitamError = generateVitamError(e);

            requestContext.abortWith(
                Response.status(vitamError.getHttpCode()).entity(vitamError).type(MediaType.APPLICATION_JSON_TYPE)
                    .build());
            return;
        }
    }

    public  EndpointPersonalCertificateAuthorizationFilter(String permission);
    @VisibleForTesting public  EndpointPersonalCertificateAuthorizationFilter(String permission,
        InternalSecurityClient internalSecurityClient);

}