public boolean authenticate ( HttpServletRequest request ) throws MnoException { String authHeader = request . getHeader ( "Authorization" ) ; if ( authHeader == null || authHeader . isEmpty ( ) ) { return false ; } String [ ] auth = authHeader . trim ( ) . split ( "\\s+" ) ; if ( auth == null || auth . length != 2 || ! auth [ 0 ] . equalsIgnoreCase ( "basic" ) ) { return false ; } byte [ ] decodedStr = DatatypeConverter . parseBase64Binary ( auth [ 1 ] ) ; String [ ] creds ; try { creds = ( new String ( decodedStr , "UTF-8" ) ) . split ( ":" ) ; } catch ( UnsupportedEncodingException e ) { throw new MnoException ( "Could not decode basic authentication" + Arrays . toString ( auth ) , e ) ; } if ( creds . length == 2 ) { return authenticate ( creds [ 0 ] , creds [ 1 ] ) ; } else { return false ; } }
Authenticate a Maestrano request by reading the Authorization header