@Test @RunWithCustomExecutor public void testBasicAuthentication_case_sensitive() throws Exception { setup("adminuserName", "adminpassword"); MultivaluedMap<String, String> headers = new MultivaluedHashMap<>(); headers.add(HttpHeaders.AUTHORIZATION, "Basic YWRtaW5Vc2VyTmFtZTphZG1pblBhc3N3b3Jk"); when(containerRequestContext.getHeaders()) .thenReturn(headers); assertThatThrownBy(() -> instance.filter(containerRequestContext)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("VitamAuthentication failed: Wrong credentials"); }
@Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { ParametersChecker .checkParameter("VitamAuthentication failed! The service needs user authentication.", containerRequestContext.getHeaders().get(HttpHeaders.AUTHORIZATION)); MultivaluedMap<String, String> headers = containerRequestContext.getHeaders(); String authorization = headers.get(HttpHeaders.AUTHORIZATION).iterator().next(); if (!authorization.startsWith(BASIC)) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } String decodedAuthent = ""; String[] credentials = authorization.split("\\s"); if (credentials.length != 2) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } byte[] bytes = Base64.getDecoder().decode(credentials[1]); decodedAuthent = new String(bytes); List<String> decodedAuthentgInfos = Arrays.asList(decodedAuthent.split(":")); List<BasicAuthModel> basicAuthConfig = configuration.getAdminBasicAuth(); if (decodedAuthentgInfos.isEmpty() || (basicAuthConfig != null && (!basicAuthConfig.get(0).getUserName().equals(decodedAuthentgInfos.get(0)) || !basicAuthConfig.get(0).getPassword() .equals(decodedAuthentgInfos.get(1))))) { throw new IllegalArgumentException("VitamAuthentication failed: Wrong credentials."); } }
EndpointAuthenticationFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { ParametersChecker .checkParameter("VitamAuthentication failed! The service needs user authentication.", containerRequestContext.getHeaders().get(HttpHeaders.AUTHORIZATION)); MultivaluedMap<String, String> headers = containerRequestContext.getHeaders(); String authorization = headers.get(HttpHeaders.AUTHORIZATION).iterator().next(); if (!authorization.startsWith(BASIC)) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } String decodedAuthent = ""; String[] credentials = authorization.split("\\s"); if (credentials.length != 2) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } byte[] bytes = Base64.getDecoder().decode(credentials[1]); decodedAuthent = new String(bytes); List<String> decodedAuthentgInfos = Arrays.asList(decodedAuthent.split(":")); List<BasicAuthModel> basicAuthConfig = configuration.getAdminBasicAuth(); if (decodedAuthentgInfos.isEmpty() || (basicAuthConfig != null && (!basicAuthConfig.get(0).getUserName().equals(decodedAuthentgInfos.get(0)) || !basicAuthConfig.get(0).getPassword() .equals(decodedAuthentgInfos.get(1))))) { throw new IllegalArgumentException("VitamAuthentication failed: Wrong credentials."); } } }
EndpointAuthenticationFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { ParametersChecker .checkParameter("VitamAuthentication failed! The service needs user authentication.", containerRequestContext.getHeaders().get(HttpHeaders.AUTHORIZATION)); MultivaluedMap<String, String> headers = containerRequestContext.getHeaders(); String authorization = headers.get(HttpHeaders.AUTHORIZATION).iterator().next(); if (!authorization.startsWith(BASIC)) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } String decodedAuthent = ""; String[] credentials = authorization.split("\\s"); if (credentials.length != 2) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } byte[] bytes = Base64.getDecoder().decode(credentials[1]); decodedAuthent = new String(bytes); List<String> decodedAuthentgInfos = Arrays.asList(decodedAuthent.split(":")); List<BasicAuthModel> basicAuthConfig = configuration.getAdminBasicAuth(); if (decodedAuthentgInfos.isEmpty() || (basicAuthConfig != null && (!basicAuthConfig.get(0).getUserName().equals(decodedAuthentgInfos.get(0)) || !basicAuthConfig.get(0).getPassword() .equals(decodedAuthentgInfos.get(1))))) { throw new IllegalArgumentException("VitamAuthentication failed: Wrong credentials."); } } EndpointAuthenticationFilter(AuthenticationLevel authentLevel,
        DefaultVitamApplicationConfiguration configuration); }
EndpointAuthenticationFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { ParametersChecker .checkParameter("VitamAuthentication failed! The service needs user authentication.", containerRequestContext.getHeaders().get(HttpHeaders.AUTHORIZATION)); MultivaluedMap<String, String> headers = containerRequestContext.getHeaders(); String authorization = headers.get(HttpHeaders.AUTHORIZATION).iterator().next(); if (!authorization.startsWith(BASIC)) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } String decodedAuthent = ""; String[] credentials = authorization.split("\\s"); if (credentials.length != 2) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } byte[] bytes = Base64.getDecoder().decode(credentials[1]); decodedAuthent = new String(bytes); List<String> decodedAuthentgInfos = Arrays.asList(decodedAuthent.split(":")); List<BasicAuthModel> basicAuthConfig = configuration.getAdminBasicAuth(); if (decodedAuthentgInfos.isEmpty() || (basicAuthConfig != null && (!basicAuthConfig.get(0).getUserName().equals(decodedAuthentgInfos.get(0)) || !basicAuthConfig.get(0).getPassword() .equals(decodedAuthentgInfos.get(1))))) { throw new IllegalArgumentException("VitamAuthentication failed: Wrong credentials."); } } EndpointAuthenticationFilter(AuthenticationLevel authentLevel,
        DefaultVitamApplicationConfiguration configuration); @Override void filter(ContainerRequestContext containerRequestContext); AuthenticationLevel getAuthentLevel(); }
EndpointAuthenticationFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { ParametersChecker .checkParameter("VitamAuthentication failed! The service needs user authentication.", containerRequestContext.getHeaders().get(HttpHeaders.AUTHORIZATION)); MultivaluedMap<String, String> headers = containerRequestContext.getHeaders(); String authorization = headers.get(HttpHeaders.AUTHORIZATION).iterator().next(); if (!authorization.startsWith(BASIC)) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } String decodedAuthent = ""; String[] credentials = authorization.split("\\s"); if (credentials.length != 2) { throw new IllegalArgumentException( "VitamAuthentication failed: VitamAuthentication informations are missing."); } byte[] bytes = Base64.getDecoder().decode(credentials[1]); decodedAuthent = new String(bytes); List<String> decodedAuthentgInfos = Arrays.asList(decodedAuthent.split(":")); List<BasicAuthModel> basicAuthConfig = configuration.getAdminBasicAuth(); if (decodedAuthentgInfos.isEmpty() || (basicAuthConfig != null && (!basicAuthConfig.get(0).getUserName().equals(decodedAuthentgInfos.get(0)) || !basicAuthConfig.get(0).getPassword() .equals(decodedAuthentgInfos.get(1))))) { throw new IllegalArgumentException("VitamAuthentication failed: Wrong credentials."); } } EndpointAuthenticationFilter(AuthenticationLevel authentLevel,
        DefaultVitamApplicationConfiguration configuration); @Override void filter(ContainerRequestContext containerRequestContext); AuthenticationLevel getAuthentLevel();  }