@Inject public DefaultSecurityTokenCodec(ContainerConfig config) { String tokenType = config.getString(ContainerConfig.DEFAULT_CONTAINER, SECURITY_TOKEN_TYPE); if ("insecure".equals(tokenType)) { codec = new BasicSecurityTokenCodec(config); } else if ("secure".equals(tokenType)) { codec = new BlobCrypterSecurityTokenCodec(config); } else { throw new RuntimeException("Unknown security token type specified in " + ContainerConfig.DEFAULT_CONTAINER + " container configuration. " + SECURITY_TOKEN_TYPE + ": " + tokenType); } }
public int getTokenTimeToLive(String container) { Integer tokenTTL = this.tokenTTLs.get(container); if (tokenTTL == null) { return getTokenTimeToLive(); } return tokenTTL; }
@Inject public DefaultSecurityTokenCodec(ContainerConfig config) { String tokenType = config.getString(ContainerConfig.DEFAULT_CONTAINER, SECURITY_TOKEN_TYPE); if ("insecure".equals(tokenType)) { codec = new BasicSecurityTokenCodec(); } else if ("secure".equals(tokenType)) { codec = new BlobCrypterSecurityTokenCodec(config); } else { throw new RuntimeException("Unknown security token type specified in " + ContainerConfig.DEFAULT_CONTAINER + " container configuration. " + SECURITY_TOKEN_TYPE + ": " + tokenType); } }
public int getTokenTimeToLive(String container) { Integer tokenTTL = this.tokenTTLs.get(container); if (tokenTTL == null) { return getTokenTimeToLive(); } return tokenTTL; }
@Inject public DefaultSecurityTokenCodec(ContainerConfig config) { String tokenType = config.getString(ContainerConfig.DEFAULT_CONTAINER, SECURITY_TOKEN_TYPE); if ("insecure".equals(tokenType)) { codec = new BasicSecurityTokenCodec(config); } else if ("secure".equals(tokenType)) { codec = new BlobCrypterSecurityTokenCodec(config); } else { throw new RuntimeException("Unknown security token type specified in " + ContainerConfig.DEFAULT_CONTAINER + " container configuration. " + SECURITY_TOKEN_TYPE + ": " + tokenType); } }
public int getTokenTimeToLive(String container) { Integer tokenTTL = this.tokenTTLs.get(container); if (tokenTTL == null) { return getTokenTimeToLive(); } return tokenTTL; }
@Inject public DefaultSecurityTokenCodec(ContainerConfig config) { String tokenType = config.getString(ContainerConfig.DEFAULT_CONTAINER, SECURITY_TOKEN_TYPE); if ("insecure".equals(tokenType)) { codec = new BasicSecurityTokenCodec(config); } else if ("secure".equals(tokenType)) { codec = new BlobCrypterSecurityTokenCodec(config); } else { throw new RuntimeException("Unknown security token type specified in " + ContainerConfig.DEFAULT_CONTAINER + " container configuration. " + SECURITY_TOKEN_TYPE + ": " + tokenType); } }
@Test public void testGetTokenTimeToLive() throws Exception { Builder<String, Object> builder = ImmutableMap.builder(); Map<String, Object> container = builder .put(ContainerConfig.CONTAINER_KEY, ImmutableList.of("default", "tokenTest")) .put(SecurityTokenCodec.SECURITY_TOKEN_TTL_CONFIG, Integer.valueOf(300)).build(); config.newTransaction().addContainer(container).commit(); assertEquals("Token TTL matches what is set in the container config", 300, codec.getTokenTimeToLive("tokenTest")); assertEquals("Token TTL matches the default TTL", AbstractSecurityToken.DEFAULT_MAX_TOKEN_TTL, codec.getTokenTimeToLive()); } }
@Inject public DefaultSecurityTokenCodec(ContainerConfig config) { String tokenType = config.getString(ContainerConfig.DEFAULT_CONTAINER, SECURITY_TOKEN_TYPE); if ("insecure".equals(tokenType)) { codec = new BasicSecurityTokenCodec(); } else if ("secure".equals(tokenType)) { codec = new BlobCrypterSecurityTokenCodec(config); } else { throw new RuntimeException("Unknown security token type specified in " + ContainerConfig.DEFAULT_CONTAINER + " container configuration. " + SECURITY_TOKEN_TYPE + ": " + tokenType); } }
@Test public void testGetTokenTimeToLive() throws Exception { Builder<String, Object> builder = ImmutableMap.builder(); Map<String, Object> container = builder .put(ContainerConfig.CONTAINER_KEY, ImmutableList.of("default", "tokenTest")) .put(SecurityTokenCodec.SECURITY_TOKEN_TTL_CONFIG, Integer.valueOf(300)).build(); config.newTransaction().addContainer(container).commit(); assertEquals("Token TTL matches what is set in the container config", 300, codec.getTokenTimeToLive("tokenTest")); assertEquals("Token TTL matches the default TTL", AbstractSecurityToken.DEFAULT_MAX_TOKEN_TTL, codec.getTokenTimeToLive()); } }
@Before public void setUp() throws Exception { config = new BasicContainerConfig(); codec = new BasicSecurityTokenCodec(config); }
@Test public void testGetTokenTimeToLive() throws Exception { Builder<String, Object> builder = ImmutableMap.builder(); Map<String, Object> container = builder .put(ContainerConfig.CONTAINER_KEY, ImmutableList.of("default", "tokenTest")) .put(SecurityTokenCodec.SECURITY_TOKEN_TTL_CONFIG, Integer.valueOf(300)).build(); config.newTransaction().addContainer(container).commit(); assertEquals("Token TTL matches what is set in the container config", 300, codec.getTokenTimeToLive("tokenTest")); assertEquals("Token TTL matches the default TTL", AbstractSecurityToken.DEFAULT_MAX_TOKEN_TTL, codec.getTokenTimeToLive()); } }
@Before public void setUp() throws Exception { config = new BasicContainerConfig(); codec = new BasicSecurityTokenCodec(config); }
@Before public void setUp() throws Exception { config = new BasicContainerConfig(); codec = new BasicSecurityTokenCodec(config); }
@Test public void testReadConfigWithValidEndpoints() throws Exception { List<String> endPoint1Services = ImmutableList.of("do.something", "delete.someting"); JSONObject service1 = new JSONObject(); service1.put("result", endPoint1Services); List<String> endPoint2Services = ImmutableList.of("weather.get"); JSONObject service2 = new JSONObject(); service2.put("result", endPoint2Services); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service1.toString())); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service2.toString())); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); Multimap<String, String> mergedServices = LinkedHashMultimap.create(configuredServices); mergedServices.putAll(endPoint1, endPoint1Services); mergedServices.putAll(endPoint2, endPoint2Services); assertEquals(mergedServices, LinkedHashMultimap.create(services)); }
@Test public void testReadConfigWithValidEndpoints() throws Exception { List<String> endPoint1Services = ImmutableList.of("do.something", "delete.someting"); JSONObject service1 = new JSONObject(); service1.put("result", endPoint1Services); List<String> endPoint2Services = ImmutableList.of("weather.get"); JSONObject service2 = new JSONObject(); service2.put("result", endPoint2Services); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service1.toString())); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service2.toString())); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); Multimap<String, String> mergedServices = LinkedHashMultimap.create(configuredServices); mergedServices.putAll(endPoint1, endPoint1Services); mergedServices.putAll(endPoint2, endPoint2Services); assertEquals(mergedServices, LinkedHashMultimap.create(services)); }
@Test public void testReadConfigRequestMarkedInternal() throws Exception { JSONObject config = createConfig(); config.getJSONObject("default"). getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) .getJSONObject(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG) .put(DefaultServiceFetcher.OSAPI_BASE_ENDPOINTS, new JSONArray(ImmutableList.of(endPoint1))); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); CapturingHttpFetcher httpFetcher = new CapturingHttpFetcher(); fetcher = new DefaultServiceFetcher(containerConfig, httpFetcher); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); assertEquals(configuredServices, services); assertNotNull( httpFetcher.request ); assertTrue( httpFetcher.request.isInternalRequest() ); }
@Test public void testReadConfigEndpointsDown() throws Exception { EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }
@Test public void testReadConfigRequestMarkedInternal() throws Exception { JSONObject config = createConfig(); config.getJSONObject("default"). getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) .getJSONObject(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG) .put(DefaultServiceFetcher.OSAPI_BASE_ENDPOINTS, new JSONArray(ImmutableList.of(endPoint1))); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); CapturingHttpFetcher httpFetcher = new CapturingHttpFetcher(); fetcher = new DefaultServiceFetcher(containerConfig, httpFetcher); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); assertEquals(configuredServices, services); assertNotNull( httpFetcher.request ); assertTrue( httpFetcher.request.isInternalRequest() ); }
@Test public void testReadConfigEndpointsDown() throws Exception { EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }