Examples of TokenCredentials


Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

            }
            return false;
        }

        public TokenCredentials getCredentials() {
            TokenCredentials tc = new TokenCredentials(token);
            for (String name : mandatoryAttributes.keySet()) {
                tc.setAttribute(name, mandatoryAttributes.get(name));
            }
            for (String name : publicAttributes.keySet()) {
                tc.setAttribute(name, publicAttributes.get(name));
            }
            return tc;
        }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

            }
            return false;
        }

        public TokenCredentials getCredentials() {
            TokenCredentials tc = new TokenCredentials(token);
            for (String name : mandatoryAttributes.keySet()) {
                tc.setAttribute(name, mandatoryAttributes.get(name));
            }
            for (String name : publicAttributes.keySet()) {
                tc.setAttribute(name, publicAttributes.get(name));
            }
            return tc;
        }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

                    }
                }
            }
            Set<TokenCredentials> tokenCreds = session.getSubject().getPublicCredentials(TokenCredentials.class);
            if (!tokenCreds.isEmpty()) {
                TokenCredentials tc = tokenCreds.iterator().next();
                for (String name : tc.getAttributeNames()) {
                    if (!TokenBasedAuthentication.isMandatoryAttribute(name)) {
                        session.setAttribute(name, tc.getAttribute(name));
                    }
                }
            }

            log.debug("User {} logged in to workspace {}",
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

            assertFalse(subject.getPublicCredentials().isEmpty());
            assertFalse(subject.getPublicCredentials(SimpleCredentials.class).isEmpty());
            assertFalse(subject.getPublicCredentials(TokenCredentials.class).isEmpty());
            assertEquals(2, subject.getPublicCredentials(Credentials.class).size());

            TokenCredentials tokenCredentials = subject.getPublicCredentials(TokenCredentials.class).iterator().next();

            ac.logout();

            // second login with token credentials
            ac = getAuthContext(tokenCredentials, DEFAULT_CONFIG);
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

            ac.login();
            Subject subj = ac.getSubject();
            assertFalse(subj.getPublicCredentials(SimpleCredentials.class).isEmpty());
            assertFalse(subj.getPublicCredentials(TokenCredentials.class).isEmpty());

            TokenCredentials tokenCredentials = subj.getPublicCredentials(TokenCredentials.class).iterator().next();
            ac.logout();

            // test login with token credentials
            ac = getAuthContext(tokenCredentials, DEFAULT_CONFIG);
            ac.login();
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

            // token credentials must be created
            Set<TokenCredentials> tokenCreds = ((SessionImpl) s).getSubject().getPublicCredentials(TokenCredentials.class);
            assertFalse(tokenCreds.isEmpty());
            assertEquals(1, tokenCreds.size());

            TokenCredentials tc = tokenCreds.iterator().next();         
            token = tc.getToken();

            // original simple credentials: token attribute should be updated
            assertNotNull(creds.getAttribute(TOKEN_ATTRIBUTE));
            assertFalse("".equals(creds.getAttribute(TOKEN_ATTRIBUTE)));

            // simple credentials must also be present on the subject
            Set<SimpleCredentials> scs = ((SessionImpl) s).getSubject().getPublicCredentials(SimpleCredentials.class);
            assertFalse(scs.isEmpty());
            assertEquals(1, scs.size());
            SimpleCredentials sc = scs.iterator().next();
            assertNotNull(sc.getAttribute(TOKEN_ATTRIBUTE));
            assertFalse("".equals(sc.getAttribute(TOKEN_ATTRIBUTE)));

            // test if session attributes only exposed non-mandatory attributes
            assertNull(s.getAttribute(TOKEN_ATTRIBUTE));
            for (String attrName : tc.getAttributeNames()) {
                if (TokenBasedAuthentication.isMandatoryAttribute(attrName)) {
                    assertNull(s.getAttribute(attrName));
                } else {
                    assertEquals(tc.getAttribute(attrName), s.getAttribute(attrName));
                }
            }

            // only test node characteristics if user-node resided within the same
            // workspace as 'superuser' has been created for.
            if (superuser.nodeExists(testuserPath)) {
                Node userNode = superuser.getNode(testuserPath);

                assertTrue(userNode.hasNode(TOKENS_NAME));

                Node tNode = userNode.getNode(TOKENS_NAME);
                assertTrue(tNode.hasNodes());

                Node ttNode = tNode.getNodes().nextNode();
                assertTrue(ttNode.hasProperty("attr"));
                assertEquals("attr", ttNode.getProperty("attr").getString());

                assertTrue(ttNode.hasProperty(TOKEN_ATTRIBUTE + ".any"));
                assertEquals("any", ttNode.getProperty(TOKEN_ATTRIBUTE + ".any").getString());

                String id = ttNode.getIdentifier();
                assertTrue(token.startsWith(id));
            }

        } finally {
            s.logout();
        }

        // login with token only must succeed as well.
        TokenCredentials tokenOnly = new TokenCredentials(token);
        tokenOnly.setAttribute(TOKEN_ATTRIBUTE + ".any", "any");

        s = repo.login(tokenOnly);
        try {
            assertEquals(creds.getUserID(), s.getUserID());

            Set<TokenCredentials> tokenCreds = ((SessionImpl) s).getSubject().getPublicCredentials(TokenCredentials.class);
            assertFalse(tokenCreds.isEmpty());
            assertEquals(1, tokenCreds.size());

            TokenCredentials tc = tokenCreds.iterator().next();
            String tk = tc.getToken();
            assertEquals(token, tk);

            assertNull(s.getAttribute(TOKEN_ATTRIBUTE));
            for (String attrName : tc.getAttributeNames()) {
                if (TokenBasedAuthentication.isMandatoryAttribute(attrName)) {
                    assertNull(s.getAttribute(attrName));
                } else {
                    assertEquals(tc.getAttribute(attrName), s.getAttribute(attrName));
                }
            }

        } finally {
            s.logout();
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

        }
    }

    public void testAttributes() throws RepositoryException {
        TokenBasedAuthentication auth = createAuthentication();
        assertFalse(auth.authenticate(new TokenCredentials(token)));

        TokenCredentials tc = new TokenCredentials(token);
        tc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE +".any", "wrong");
        assertFalse(auth.authenticate(tc));

        tc = new TokenCredentials(token);
        tc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE +".any", "correct");
        assertTrue(auth.authenticate(tokenCreds));
    }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

    public void testUpdateAttributes() throws RepositoryException {
        // token credentials must be updated to contain the additional attribute
        // present on the token node.
        TokenBasedAuthentication auth = createAuthentication();

        TokenCredentials tc = new TokenCredentials(token);
        tc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE +".any", "correct");

        assertTrue(auth.authenticate(tc));
        assertEquals("value", tc.getAttribute("informative"));

        // additional informative property present on credentials upon subsequent
        // authentication -> the node must not be updated
        auth = createAuthentication();
        tc.setAttribute("informative2", "value2");
        assertTrue(auth.authenticate(tc));
        assertFalse(tokenNode.hasProperty("informative2"));

        // modified informative property present on credentials upon subsequent
        // authentication -> the node must not be updated
        auth = createAuthentication();
        tc.setAttribute("informative", "otherValue");
        assertTrue(auth.authenticate(tc));
        assertTrue(tokenNode.hasProperty("informative"));
        assertEquals("value", tokenNode.getProperty("informative").getString());

        // additional mandatory property on the credentials upon subsequent
        // authentication -> must be ignored
        auth = createAuthentication();
        tc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE +".toIgnore", "ignore");
        assertTrue(auth.authenticate(tokenCreds));
        assertFalse(tokenNode.hasProperty(TokenBasedAuthentication.TOKEN_ATTRIBUTE +".toIgnore"));
    }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

        token = ti.getToken();

        nullTokenAuth = new TokenBasedAuthentication(null, -1, adminSession);
        validTokenAuth = new TokenBasedAuthentication(token, 7200, adminSession);

        tokenCreds = new TokenCredentials(token);
    }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials

    @Override
    public boolean authenticate(Credentials credentials) {
        boolean success = false;
        if (credentials instanceof TokenCredentials) {
            TokenCredentials tc = (TokenCredentials) credentials;
            success = validateCredentials(tc);
        }
        return success;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.