private String getUsernameFromAuth(String authenticationValue, String charSet) throws IOException {
    byte[] base64Token = authenticationValue.substring(6).getBytes("UTF-8");

    byte[] decoded;
    try {
      decoded = Base64.decode(base64Token);
    } catch (IllegalArgumentException ex) {
      throw new BadCredentialsException("Failed to decode basic authentication token");
    }

    String token = new String(decoded, charSet);
    int delimiter = token.indexOf(":");
    if (delimiter == -1) {
      throw new BadCredentialsException("Invalid basic authentication token");
    } else {
      return token.substring(0, delimiter);
    }
  }
Helper function to decode Authorization header

@param authenticationValue the authentication value to parse
@param charSet             the character set of the authentication value
@return the username parsed from the authentication header value
@throws IOException
ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilter.java