Package org.apache.jackrabbit.oak.spi.security.authentication.token

Examples of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo


        userId = getTestUser().getID();
    }

    @Test
    public void testGetUserId() {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
        assertEquals(userId, info.getUserId());

        info = tokenProvider.getTokenInfo(info.getToken());
        assertEquals(userId, info.getUserId());
    }
View Full Code Here


        assertEquals(userId, info.getUserId());
    }

    @Test
    public void testGetToken() {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
        assertNotNull(info.getToken());

        info = tokenProvider.getTokenInfo(info.getToken());
        assertNotNull(info.getToken());
    }
View Full Code Here

    @Test
    public void testIsExpired() {
        long loginTime = new Date().getTime();

        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
        assertFalse(info.isExpired(loginTime));

        loginTime = new Date().getTime() + 3600000;
        assertFalse(info.isExpired(loginTime));

        long expiredTime = new Date().getTime() + 7200001;
        assertTrue(info.isExpired(expiredTime));
    }
View Full Code Here

        assertTrue(info.isExpired(expiredTime));
    }

    @Test
    public void testMatches() {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
        assertTrue(info.matches(new TokenCredentials(info.getToken())));

        Map<String,String> attributes = new HashMap<String, String>();
        attributes.put("something", "value");
        info = tokenProvider.createToken(userId, attributes);
        assertTrue(info.matches(new TokenCredentials(info.getToken())));

        attributes.put(".token-something", "mandatory");
        info = tokenProvider.createToken(userId, attributes);
        assertFalse(info.matches(new TokenCredentials(info.getToken())));
        TokenCredentials tc = new TokenCredentials(info.getToken());
        tc.setAttribute(".token-something", "mandatory");
        assertTrue(info.matches(tc));
        tc.setAttribute("another", "value");
        assertTrue(info.matches(tc));
        tc.setAttribute(".token_ignored", "value");
        assertTrue(info.matches(tc));
    }
View Full Code Here

        Map<String, String> attributes = new HashMap<String, String>();
        attributes.putAll(reserved);
        attributes.putAll(publicAttributes);
        attributes.putAll(privateAttributes);

        TokenInfo info = tokenProvider.createToken(userId, attributes);

        Map<String,String> pubAttr = info.getPublicAttributes();
        assertEquals("public attributes",publicAttributes.size(), pubAttr.size());
        for (String key : publicAttributes.keySet()) {
            assertTrue("public attribute "+key+" not contained",pubAttr.containsKey(key));
            assertEquals("public attribute " + key,publicAttributes.get(key), pubAttr.get(key));
        }

        Map<String,String> privAttr = info.getPrivateAttributes();
        assertEquals("private attributes",privateAttributes.size(), privAttr.size());
        for (String key : privateAttributes.keySet()) {
            assertTrue("private attribute "+key+" not contained",privAttr.containsKey(key));
            assertEquals("private attribute" + key,privateAttributes.get(key), privAttr.get(key));
        }
View Full Code Here

        }
    }

    @Test
    public void testRemoveToken() throws Exception {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
        assertTrue(info.remove());
    }
View Full Code Here

        assertTrue(info.remove());
    }

    @Test
    public void testRemoveToken2() throws Exception {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
        assertTrue(info.remove());
    }
View Full Code Here

        assertTrue(info.remove());
    }

    @Test
    public void testRemoveTokenRemovesNode() throws Exception {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());

        Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
        Tree tokens = userTree.getChild(".tokens");
        String tokenNodePath = tokens.getChildren().iterator().next().getPath();

        info.remove();
        assertFalse(root.getTree(tokenNodePath).exists());
    }
View Full Code Here

        assertFalse(root.getTree(tokenNodePath).exists());
    }

    @Test
    public void testResetTokenExpirationExpiredToken() throws Exception {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());

        long expiredTime = new Date().getTime() + 7200001;
        assertTrue(info.isExpired(expiredTime));
        assertFalse(info.resetExpiration(expiredTime));
    }
View Full Code Here

        assertFalse(info.resetExpiration(expiredTime));
    }

    @Test
    public void testResetTokenExpiration() throws Exception {
        TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());

        assertFalse(info.resetExpiration(new Date().getTime()));

        long loginTime = new Date().getTime() + 3600000;
        assertFalse(info.isExpired(loginTime));
        assertTrue(info.resetExpiration(loginTime));
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.