OAuthAuthenticator implements WebappAuthenticator { public boolean canHandle(org.apache.catalina.connector.Request request) { MessageBytes authorization = request.getCoyoteRequest().getMimeHeaders().getValue("Authorization"); if (authorization != null) { authorization.toBytes(); ByteChunk authBC = authorization.getByteChunk(); String tokenValue = authBC.toString(); Matcher matcher = PATTERN.matcher(tokenValue); if (matcher.find()) { return true; } } return false; }  void init(); boolean canHandle(org.apache.catalina.connector.Request request); AuthenticationInfo authenticate(org.apache.catalina.connector.Request request, Response response); String getName(); String getProperty(String name); Properties getProperties(); void setProperties(Properties properties);  }
@Test(description = "This method tests the canHandle method of OAuthAuthenticator") public void testCanHandle() throws IllegalAccessException { Request request = createOauthRequest(BEARER_HEADER); Assert.assertTrue(oAuthAuthenticator.canHandle(request), "The request with the bearer authorization header cannot be handled by OauthAuthenticator"); request = createOauthRequest("test"); Assert.assertFalse(oAuthAuthenticator.canHandle(request), "The request without bearer authorization header can be handled by OauthAuthenticator"); }