@Test @RunWithCustomExecutor public void should_abort_when_personal_certificate_is_required_and_certificate_ko() throws Exception { when(internalSecurityClient.isPersonalCertificateRequiredByPermission(PERMISSION)) .thenReturn(new IsPersonalCertificateRequiredModel(REQUIRED_PERSONAL_CERTIFICATE)); when(context.getHeaderString(GlobalDataRest.X_PERSONAL_CERTIFICATE)).thenReturn(BASE64_CERTIFICATE); doThrow(InternalSecurityException.class).when(internalSecurityClient) .checkPersonalCertificate(eq(CERTIFICATE), eq(PERMISSION)); instance.filter(context); verify(internalSecurityClient).isPersonalCertificateRequiredByPermission(PERMISSION); verify(context).getHeaderString(GlobalDataRest.X_PERSONAL_CERTIFICATE); verify(internalSecurityClient).checkPersonalCertificate(eq(CERTIFICATE), eq(PERMISSION)); verify(context).abortWith(any()); }
@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; } }
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; } } }
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; } } EndpointPersonalCertificateAuthorizationFilter(String permission); @VisibleForTesting  EndpointPersonalCertificateAuthorizationFilter(String permission,
        InternalSecurityClient internalSecurityClient); }
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; } } EndpointPersonalCertificateAuthorizationFilter(String permission); @VisibleForTesting  EndpointPersonalCertificateAuthorizationFilter(String permission,
        InternalSecurityClient internalSecurityClient); @Override void filter(ContainerRequestContext requestContext); String getPermission(); }
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; } } EndpointPersonalCertificateAuthorizationFilter(String permission); @VisibleForTesting  EndpointPersonalCertificateAuthorizationFilter(String permission,
        InternalSecurityClient internalSecurityClient); @Override void filter(ContainerRequestContext requestContext); String getPermission();  }