public int getTokenTimeToLive(String container) { Integer tokenTTL = this.tokenTTLs.get(container); if (tokenTTL == null) { return getTokenTimeToLive(); } return tokenTTL; } }
public int getTokenTimeToLive(String container) { Integer tokenTTL = this.tokenTTLs.get(container); if (tokenTTL == null) { return getTokenTimeToLive(); } return tokenTTL; } }
public int getTokenTimeToLive(String container) { Integer tokenTTL = this.tokenTTLs.get(container); if (tokenTTL == null) { return getTokenTimeToLive(); } return tokenTTL; } }
@Test public void testGetTokenTimeToLive() throws Exception { Builder<String, Object> builder = ImmutableMap.builder(); Map<String, Object> container = builder.putAll(makeContainer("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()); } }
@Test public void testGetTokenTimeToLive() throws Exception { Builder<String, Object> builder = ImmutableMap.builder(); Map<String, Object> container = builder.putAll(makeContainer("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()); } }
@Test public void testGetTokenTimeToLive() throws Exception { Builder<String, Object> builder = ImmutableMap.builder(); Map<String, Object> container = builder.putAll(makeContainer("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()); } }
@Test public void testExpired() throws Exception { Map<String, String> values = new HashMap<String, String>(); values.put(Keys.APP_URL.getKey(), "http://www.example.com/gadget.xml"); values.put(Keys.MODULE_ID.getKey(), Long.toString(12345L, 10)); values.put(Keys.OWNER.getKey(), "owner"); values.put(Keys.VIEWER.getKey(), "viewer"); values.put(Keys.TRUSTED_JSON.getKey(), "trusted"); BlobCrypterSecurityToken token = new BlobCrypterSecurityToken("container", null, null, values); token.setTimeSource(timeSource); timeSource.incrementSeconds(-1 * (codec.getTokenTimeToLive("container") + 181)); // one hour plus clock skew String encrypted = codec.encodeToken(token); try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("should have expired"); } catch (SecurityTokenException e) { assertTrue(e.getMessage(), e.getMessage().contains("Blob expired")); } }
@Test public void testExpired() throws Exception { Map<String, String> values = new HashMap<String, String>(); values.put(Keys.APP_URL.getKey(), "http://www.example.com/gadget.xml"); values.put(Keys.MODULE_ID.getKey(), Long.toString(12345L, 10)); values.put(Keys.OWNER.getKey(), "owner"); values.put(Keys.VIEWER.getKey(), "viewer"); values.put(Keys.TRUSTED_JSON.getKey(), "trusted"); BlobCrypterSecurityToken token = new BlobCrypterSecurityToken("container", null, null, values); token.setTimeSource(timeSource); timeSource.incrementSeconds(-1 * (codec.getTokenTimeToLive("container") + 181)); // one hour plus clock skew String encrypted = codec.encodeToken(token); try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("should have expired"); } catch (SecurityTokenException e) { assertTrue(e.getMessage(), e.getMessage().contains("Blob expired")); } }
@Test public void testExpired() throws Exception { Map<String, String> values = new HashMap<String, String>(); values.put(Keys.APP_URL.getKey(), "http://www.example.com/gadget.xml"); values.put(Keys.MODULE_ID.getKey(), Long.toString(12345L, 10)); values.put(Keys.OWNER.getKey(), "owner"); values.put(Keys.VIEWER.getKey(), "viewer"); values.put(Keys.TRUSTED_JSON.getKey(), "trusted"); BlobCrypterSecurityToken token = new BlobCrypterSecurityToken("container", null, null, values); token.setTimeSource(timeSource); timeSource.incrementSeconds(-1 * (codec.getTokenTimeToLive("container") + 181)); // one hour plus clock skew String encrypted = codec.encodeToken(token); try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("should have expired"); } catch (SecurityTokenException e) { assertTrue(e.getMessage(), e.getMessage().contains("Blob expired")); } }