Search in sources :

Example 1 with AbsoluteExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration in project zm-mailbox by Zimbra.

the class EphemeralAttributesTest method testCsrfTokens.

@Test
public void testCsrfTokens() throws Exception {
    EphemeralKey tokenDataKey1 = new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb1");
    EphemeralKey tokenDataKey2 = new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb2");
    //already expired
    acct.addCsrfTokenData("crumb1", "data1", new AbsoluteExpiration(1000L));
    acct.addCsrfTokenData("crumb2", "data2", new RelativeExpiration(1L, TimeUnit.DAYS));
    //is it in the ephemeral store?
    assertEquals("data1", store.get(tokenDataKey1, location).getValue());
    assertEquals("data2", store.get(tokenDataKey2, location).getValue());
    //test getter
    assertEquals("data1", acct.getCsrfTokenData("crumb1"));
    assertEquals("data2", acct.getCsrfTokenData("crumb2"));
    //test removing expired
    acct.purgeCsrfTokenData();
    assertTrue(store.get(tokenDataKey1, location).isEmpty());
    assertEquals("data2", store.get(tokenDataKey2, location).getValue());
    //test removing a specific value
    acct.addCsrfTokenData("crumb3", "data3", new RelativeExpiration(1L, TimeUnit.DAYS));
    acct.removeCsrfTokenData("crumb2", "data2");
    assertTrue(store.get(tokenDataKey2, location).isEmpty());
    assertEquals("data3", acct.getCsrfTokenData("crumb3"));
    //test removing incorrect value
    acct.removeCsrfTokenData("crumb3", "data2");
    assertEquals("data3", acct.getCsrfTokenData("crumb3"));
}
Also used : RelativeExpiration(com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Test(org.junit.Test)

Example 2 with AbsoluteExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration in project zm-mailbox by Zimbra.

the class EphemeralAttributesTest method testAuthTokens.

@Test
public void testAuthTokens() throws Exception {
    EphemeralKey tokenKey1 = new EphemeralKey(Provisioning.A_zimbraAuthTokens, "token1");
    EphemeralKey tokenKey2 = new EphemeralKey(Provisioning.A_zimbraAuthTokens, "token2");
    //already expired
    acct.addAuthTokens("token1", "data1", new AbsoluteExpiration(1000L));
    acct.addAuthTokens("token2", "data2", new RelativeExpiration(1L, TimeUnit.DAYS));
    //is it in the ephemeral store?
    assertEquals("data1", store.get(tokenKey1, location).getValue());
    assertEquals("data2", store.get(tokenKey2, location).getValue());
    //test getter
    assertEquals("data1", acct.getAuthTokens("token1"));
    assertEquals("data2", acct.getAuthTokens("token2"));
    //test removing expired
    acct.purgeAuthTokens();
    assertTrue(store.get(tokenKey1, location).isEmpty());
    assertEquals("data2", store.get(tokenKey2, location).getValue());
    //test removing a specific value
    acct.addAuthTokens("token3", "data3", new RelativeExpiration(1L, TimeUnit.DAYS));
    acct.removeAuthTokens("token2", "data2");
    assertTrue(store.get(tokenKey2, location).isEmpty());
    assertEquals("data3", acct.getAuthTokens("token3"));
    //test removing incorrect value
    acct.removeAuthTokens("token3", "data2");
    assertEquals("data3", acct.getAuthTokens("token3"));
}
Also used : RelativeExpiration(com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Test(org.junit.Test)

Example 3 with AbsoluteExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration in project zm-mailbox by Zimbra.

the class LdapEphemeralStoreTest method testExpiry.

@Test
public void testExpiry() throws Exception {
    EphemeralLocation location = new TestLocation();
    EphemeralInput input = new EphemeralInput(new EphemeralKey("foo"), "bar");
    input.setExpiration(new AbsoluteExpiration(1000L));
    store.set(input, location);
    input = new EphemeralInput(new EphemeralKey("foo", "1"), "bar");
    input.setExpiration(new AbsoluteExpiration(1000L));
    store.set(input, location);
    input = new EphemeralInput(new EphemeralKey("foo", "2"), "bar");
    input.setExpiration(new AbsoluteExpiration(1000L));
    store.set(input, location);
    helper.reset();
    Thread.sleep(1500);
    store.purgeExpired(new EphemeralKey("foo"), location);
    Map<String, Object> expected = makeMap("-foo", "bar||1000", "bar|1|1000", "bar|2|1000");
    verifyAttrMap(expected);
}
Also used : AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) TestLocation(com.zimbra.cs.ephemeral.EphemeralStoreTest.TestLocation) Test(org.junit.Test)

Example 4 with AbsoluteExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration in project zm-mailbox by Zimbra.

the class EphemeralStoreTest method testFallbackEphemeralStore.

@Test
public void testFallbackEphemeralStore() throws Exception {
    EphemeralStore primary = new InMemoryEphemeralStore();
    EphemeralStore secondary = new InMemoryEphemeralStore();
    EphemeralStore store = new FallbackEphemeralStore(primary, secondary);
    EphemeralLocation target = new TestLocation();
    EphemeralKey key1 = new EphemeralKey("foo1");
    EphemeralKey key2 = new EphemeralKey("foo2");
    EphemeralInput input1 = new EphemeralInput(key1, "bar1");
    input1.setExpiration(new AbsoluteExpiration(1000L));
    EphemeralInput input2 = new EphemeralInput(key2, "bar2");
    input2.setExpiration(new AbsoluteExpiration(1000L));
    //add a value via the fallback store
    primary.set(input1, target);
    //make sure it went to the primary store
    assertEquals("bar1", primary.get(key1, target).getValue());
    //but not the secondary store
    assertTrue(secondary.get(key1, target).isEmpty());
    //add a value to the secondary store
    secondary.set(input2, target);
    //make sure get() and has() work for values in both primary and secondary stores
    assertTrue(store.has(key1, target));
    assertTrue(store.has(key2, target));
    assertEquals("bar1", store.get(key1, target).getValue());
    assertEquals("bar2", store.get(key2, target).getValue());
    //deleting via fallback store should delete from both primary and secondary
    store.delete(key1, "bar1", target);
    assertFalse(primary.has(key1, target));
    store.delete(key2, "bar2", target);
    assertFalse(secondary.has(key2, target));
    //purging should purge from both primary and secondary as well
    primary.set(input1, target);
    secondary.set(input1, target);
    store.purgeExpired(key1, target);
    assertFalse(primary.has(key1, target));
    assertFalse(secondary.has(key1, target));
}
Also used : AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Test(org.junit.Test)

Example 5 with AbsoluteExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration in project zm-mailbox by Zimbra.

the class ZimbraAuthToken method register.

private void register() {
    if (!isZimbraUser() || isZMGAppBootstrap()) {
        return;
    }
    try {
        Account acct = Provisioning.getInstance().get(AccountBy.id, accountId);
        if (Provisioning.getInstance().getLocalServer().getLowestSupportedAuthVersion() > 1) {
            try {
                //house keeping. If we are issuing a new token, clean up old ones.
                acct.cleanExpiredTokens();
            } catch (ServiceException e) {
                LOG.error("unable to de-register auth token", e);
            }
            Expiration expiration = new AbsoluteExpiration(this.expires);
            acct.addAuthTokens(String.valueOf(tokenID), server_version, expiration);
        }
    } catch (ServiceException e) {
        LOG.error("unable to register auth token", e);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Expiration(com.zimbra.cs.ephemeral.EphemeralInput.Expiration) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration)

Aggregations

AbsoluteExpiration (com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration)10 Test (org.junit.Test)5 Expiration (com.zimbra.cs.ephemeral.EphemeralInput.Expiration)4 TestLocation (com.zimbra.cs.ephemeral.EphemeralStoreTest.TestLocation)3 EphemeralInput (com.zimbra.cs.ephemeral.EphemeralInput)2 RelativeExpiration (com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration)2 EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)2 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1