params.put(SecurityTokenCodec.ACTIVE_URL_NAME, getActiveUrl(request)); return params;
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); } }
@Test public void testOAuth2Param() throws Exception { req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234"); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234&oauth_signature_method=RSA-SHA1"); Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); } }
@Test public void testGetSecurityTokenFromRequest() throws Exception { Assert.assertEquals(authHandler.getName(), AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name()); }
@Before public void setup() throws Exception { expectedToken = new BasicSecurityToken( "owner", "viewer", "app", "domain", "appUrl", "0", "container", "activeUrl", 1000L); // Mock token codec codec = new SecurityTokenCodec() { public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { return tokenParameters == null ? null : "1234".equals(tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME)) ? expectedToken : null; } public String encodeToken(SecurityToken token) throws SecurityTokenException { return null; } public int getTokenTimeToLive() { return 0; // Not used. } public int getTokenTimeToLive(String container) { return 0; // Not used. } }; authHandler = new UrlParameterAuthenticationHandler(codec, true); }
@Test public void testOAuth2Param() throws Exception { req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234"); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234&oauth_signature_method=RSA-SHA1"); Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); } }
@Test public void testGetSecurityTokenFromRequest() throws Exception { Assert.assertEquals(authHandler.getName(), AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name()); }
@Before public void setup() throws Exception { expectedToken = new BasicSecurityToken( "owner", "viewer", "app", "domain", "appUrl", "0", "container", "activeUrl", 1000L); // Mock token codec codec = new SecurityTokenCodec() { public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { return tokenParameters == null ? null : "1234".equals(tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME)) ? expectedToken : null; } public String encodeToken(SecurityToken token) throws SecurityTokenException { return null; } public int getTokenTimeToLive() { return 0; // Not used. } public int getTokenTimeToLive(String container) { return 0; // Not used. } }; authHandler = new UrlParameterAuthenticationHandler(codec, true); }
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); } }
params.put(SecurityTokenCodec.ACTIVE_URL_NAME, getActiveUrl(request)); return params;
@Test public void testOAuth2Param() throws Exception { req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234"); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234&oauth_signature_method=RSA-SHA1"); Assert.assertNull(authHandler.getSecurityTokenFromRequest(req)); } }
@Test public void testGetSecurityTokenFromRequest() throws Exception { Assert.assertEquals(authHandler.getName(), AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name()); }
@Before public void setup() throws Exception { expectedToken = new BasicSecurityToken( "owner", "viewer", "app", "domain", "appUrl", "0", "container", "activeUrl", 1000L); // Mock token codec codec = new SecurityTokenCodec() { public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { return tokenParameters == null ? null : "1234".equals(tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME)) ? expectedToken : null; } public String encodeToken(SecurityToken token) throws SecurityTokenException { return null; } public int getTokenTimeToLive() { return 0; // Not used. } public int getTokenTimeToLive(String container) { return 0; // Not used. } }; authHandler = new UrlParameterAuthenticationHandler(codec, true); }
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); } }
params.put(SecurityTokenCodec.ACTIVE_URL_NAME, getActiveUrl(request)); return params;
@Test public void testSecurityToken() throws Exception { // security token in request req = new FakeHttpServletRequest("http://example.org/rpc?st=1234"); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); }
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); } }
params.put(SecurityTokenCodec.ACTIVE_URL_NAME, getActiveUrl(request)); return params;
@Test public void testSecurityToken() throws Exception { // security token in request req = new FakeHttpServletRequest("http://example.org/rpc?st=1234"); Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req)); }
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); } }