class EndpointPermissionAuthorizationFilter implements ContainerRequestFilter {

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

        String securityProfileIdentifier = VitamThreadUtils.getVitamSession().getSecurityProfileIdentifier();

        try {

            // Get security profile by identifier stored in VitamSession
            RequestResponse<SecurityProfileModel> securityProfileResponse =
                adminManagementClient.findSecurityProfileByIdentifier(securityProfileIdentifier);

            SecurityProfileModel securityProfile;
            if (securityProfileResponse.isOk()) {
                securityProfile = ((RequestResponseOK<SecurityProfileModel>) securityProfileResponse).getFirstResult();
            } else {
                LOGGER.error("Could not retrieve security profile by identifier " + securityProfileIdentifier);
                VitamError vitamError = (VitamError) securityProfileResponse;
                requestContext.abortWith(
                    Response.status(vitamError.getHttpCode()).entity(vitamError).type(MediaType.APPLICATION_JSON_TYPE)
                        .build());
                return;
            }

            // Check for full access security profile
            if (securityProfile.getFullAccess()) {
                LOGGER.debug("Full access granted.");
                return;
            }

            // Check for matching security profile permission
            if (securityProfile.getPermissions() != null
                && securityProfile.getPermissions().contains(permission)) {
                LOGGER.debug("Access granted with permission " + permission);
                return;
            }

            LOGGER.warn("Access denied for permission " + permission);
            throw new VitamSecurityException("Access denied.");

        } catch (InvalidParseOperationException |
            AdminManagementClientServerException |
            ReferentialNotFoundException |
            VitamSecurityException e) {
            LOGGER.error("An error occured during authorization filter check", e);
            final VitamError vitamError = generateVitamError(e, permission);

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

    public  EndpointPermissionAuthorizationFilter(String permission);
    @VisibleForTesting public  EndpointPermissionAuthorizationFilter(String permission,
        AdminManagementClient adminManagementClient);

}