### Question:
UrlParameterAuthenticationHandler implements AuthenticationHandler { public SecurityToken getSecurityTokenFromRequest(HttpServletRequest request) throws InvalidAuthenticationException { Map<String, String> parameters = getMappedParameters(request); try { if (parameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME) == null) { return null; } return securityTokenCodec.createToken(parameters); } catch (SecurityTokenException e) { throw new InvalidAuthenticationException("Malformed security token " + parameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME), e); } } @Inject  UrlParameterAuthenticationHandler(SecurityTokenCodec securityTokenCodec,
                                           @Named("org.apache.shindig.auth.oauth2-require-ssl")
                                           Boolean oauthSSLrequired); String getName(); SecurityToken getSecurityTokenFromRequest(HttpServletRequest request); String getWWWAuthenticateHeader(String realm);  }### Answer:
@Test public void testGetSecurityTokenFromRequest() throws Exception { Assert.assertEquals(authHandler.getName(), AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name()); }
@Test public void testInvalidRequests() throws Exception { req = new FakeHttpServletRequest(); Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest().setHeader("Authorization", "Token token=\"1234\""); Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest().setHeader("Authorization", "OAuth 1234"); Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); }
@Test public void testSecurityToken() throws Exception { req = new FakeHttpServletRequest("http: Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); }
@Test public void testOAuth1() throws Exception { req = new FakeHttpServletRequest() .setHeader("Authorization", "OAuth oauth_signature_method=\"RSA-SHA1\""); SecurityToken token = authHandler.getSecurityTokenFromRequest(req); Assert.assertNull(token); }
@Test public void testOAuth2Header() throws Exception { req = new FakeHttpServletRequest("https: .setHeader("Authorization", "OAuth2 1234"); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest("https: .setHeader("Authorization", " OAuth2 1234 "); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest("https: .setHeader("Authorization", "OAuth2 1234 x=1,y=\"2 2 2\""); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest("http: .setHeader("Authorization", "OAuth2 1234"); Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); }
@Test public void testOAuth2Param() throws Exception { req = new FakeHttpServletRequest("https: Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest("https: Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); }