@ Nullable private BasicCredentials getCredentials ( String header ) { if ( header == null ) { return null ; } final int space = header . indexOf ( ' ' ) ; if ( space <= 0 ) { return null ; } final String method = header . substring ( 0 , space ) ; if ( ! prefix . equalsIgnoreCase ( method ) ) { return null ; } final String decoded ; try { decoded = new String ( Base64 . getDecoder ( ) . decode ( header . substring ( space + 1 ) ) , StandardCharsets . UTF_8 ) ; } catch ( IllegalArgumentException e ) { logger . warn ( "Error decoding credentials" , e ) ; return null ; } // Decoded credentials is 'username:password' final int i = decoded . indexOf ( ' ' ) ; if ( i <= 0 ) { return null ; } final String username = decoded . substring ( 0 , i ) ; final String password = decoded . substring ( i + 1 ) ; return new BasicCredentials ( username , password ) ; }
Parses a Base64 - encoded value of the Authorization header in the form of Basic dXNlcm5hbWU6cGFzc3dvcmQ = .