@Test public void tryToExtractUsernameAndPasswordFromEmptyHeader() { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getHeader("Authorization")).thenReturn(""); final String[] credentials = HttpBasicHelper.extractUsernameAndPasswordFromBasicHeader(request); assertThat(credentials).isNotNull(); assertThat(credentials[0]).isEqualTo(""); assertThat(credentials[1]).isEqualTo(""); }
public static String[] extractUsernameAndPasswordFromBasicHeader(final HttpServletRequest request) { String username = ""; String password = ""; final String authorizationHeader = getAuthorizationHeader(request); if (authorizationHeader != null && isBasic(authorizationHeader)) { final String base64Token = authorizationHeader.substring(HTTP_BASIC_SCHEME.length()); final String token = new String(Base64.getDecoder().decode(base64Token), StandardCharsets.UTF_8); final int delimiter = token.indexOf(':'); if (delimiter != -1) { username = token.substring(0, delimiter); password = token.substring(delimiter + 1); } } return new String[] { username, password }; }
HttpBasicHelper { public static String[] extractUsernameAndPasswordFromBasicHeader(final HttpServletRequest request) { String username = ""; String password = ""; final String authorizationHeader = getAuthorizationHeader(request); if (authorizationHeader != null && isBasic(authorizationHeader)) { final String base64Token = authorizationHeader.substring(HTTP_BASIC_SCHEME.length()); final String token = new String(Base64.getDecoder().decode(base64Token), StandardCharsets.UTF_8); final int delimiter = token.indexOf(':'); if (delimiter != -1) { username = token.substring(0, delimiter); password = token.substring(delimiter + 1); } } return new String[] { username, password }; } }
HttpBasicHelper { public static String[] extractUsernameAndPasswordFromBasicHeader(final HttpServletRequest request) { String username = ""; String password = ""; final String authorizationHeader = getAuthorizationHeader(request); if (authorizationHeader != null && isBasic(authorizationHeader)) { final String base64Token = authorizationHeader.substring(HTTP_BASIC_SCHEME.length()); final String token = new String(Base64.getDecoder().decode(base64Token), StandardCharsets.UTF_8); final int delimiter = token.indexOf(':'); if (delimiter != -1) { username = token.substring(0, delimiter); password = token.substring(delimiter + 1); } } return new String[] { username, password }; } private  HttpBasicHelper(); }
HttpBasicHelper { public static String[] extractUsernameAndPasswordFromBasicHeader(final HttpServletRequest request) { String username = ""; String password = ""; final String authorizationHeader = getAuthorizationHeader(request); if (authorizationHeader != null && isBasic(authorizationHeader)) { final String base64Token = authorizationHeader.substring(HTTP_BASIC_SCHEME.length()); final String token = new String(Base64.getDecoder().decode(base64Token), StandardCharsets.UTF_8); final int delimiter = token.indexOf(':'); if (delimiter != -1) { username = token.substring(0, delimiter); password = token.substring(delimiter + 1); } } return new String[] { username, password }; } private  HttpBasicHelper(); static String[] extractUsernameAndPasswordFromBasicHeader(final HttpServletRequest request); }
HttpBasicHelper { public static String[] extractUsernameAndPasswordFromBasicHeader(final HttpServletRequest request) { String username = ""; String password = ""; final String authorizationHeader = getAuthorizationHeader(request); if (authorizationHeader != null && isBasic(authorizationHeader)) { final String base64Token = authorizationHeader.substring(HTTP_BASIC_SCHEME.length()); final String token = new String(Base64.getDecoder().decode(base64Token), StandardCharsets.UTF_8); final int delimiter = token.indexOf(':'); if (delimiter != -1) { username = token.substring(0, delimiter); password = token.substring(delimiter + 1); } } return new String[] { username, password }; } private  HttpBasicHelper(); static String[] extractUsernameAndPasswordFromBasicHeader(final HttpServletRequest request);  }