public static String [ ] parseAuthorization ( final HttpServletRequest request ) { final String auth = request . getHeader ( "Authorization" ) ; logger . debug ( "Auth header: {}" , auth ) ; if ( auth == null || auth . isEmpty ( ) ) { return null ; } final String [ ] toks = auth . split ( "\\s" ) ; if ( toks . length < 2 ) { return null ; } if ( ! "Basic" . equalsIgnoreCase ( toks [ 0 ] ) ) { return null ; } final byte [ ] authData = Base64 . getDecoder ( ) . decode ( toks [ 1 ] ) ; final String authStr = StandardCharsets . ISO_8859_1 . decode ( ByteBuffer . wrap ( authData ) ) . toString ( ) ; logger . debug ( "Auth String: {}" , authStr ) ; final String [ ] authToks = authStr . split ( ":" , 2 ) ; logger . debug ( "Auth tokens: {}" , new Object [ ] { authToks } ) ; if ( authToks . length != 2 ) { return null ; } return authToks ; }
Parse the basic authentication header