Examples of TokenCredentials


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

            return false;
        }

        Credentials credentials = getCredentials();
        if (credentials instanceof TokenCredentials) {
            TokenCredentials tc = (TokenCredentials) credentials;
            TokenAuthentication authentication = new TokenAuthentication(tokenProvider);
            if (authentication.authenticate(tc)) {
                tokenCredentials = tc;
                tokenInfo = authentication.getTokenInfo();
                userID = null; // TODO: getUserID(tc);
View Full Code Here

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

            Credentials shared = getSharedCredentials();
            if (shared != null) {
                if (tokenProvider.doCreateToken(shared)) {
                    TokenInfo ti = tokenProvider.createToken(shared);
                    if (ti != null) {
                        TokenCredentials tc = new TokenCredentials(ti.getToken());
                        Map<String, String> attributes = ti.getPrivateAttributes();
                        for (String name : attributes.keySet()) {
                            tc.setAttribute(name, attributes.get(name));
                        }
                        attributes = ti.getPublicAttributes();
                        for (String name : attributes.keySet()) {
                            tc.setAttribute(name, attributes.get(name));
                        }
                        subject.getPublicCredentials().add(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

     */
    public boolean authenticate(Credentials credentials) throws RepositoryException {
        if (!(credentials instanceof TokenCredentials)) {
            throw new RepositoryException("TokenCredentials expected. Cannot handle " + credentials.getClass().getName());
        }
        TokenCredentials tokenCredentials = (TokenCredentials) credentials;

        // credentials without userID -> check if attributes provide
        // sufficient information for successful authentication.
        if (token.equals(tokenCredentials.getToken())) {
            long loginTime = new Date().getTime();
            // test if the token has already expired
            if (expiry < loginTime) {
                // already expired -> login fails.
                // ... remove the expired token node before aborting the login
                removeToken();
                return false;
            }

            // test for matching key
            if (key != null && !key.equals(getDigestedKey(tokenCredentials))) {
                return false;
            }

            // check if all other required attributes match
            for (String name : attributes.keySet()) {
                if (!attributes.get(name).equals(tokenCredentials.getAttribute(name))) {
                    // no match -> login fails.
                    return false;
                }
            }

            // update set of informative attributes on the credentials
            // based on the properties present on the token node.
            Collection<String> attrNames = Arrays.asList(tokenCredentials.getAttributeNames());
            for (String key : info.keySet()) {
                if (!attrNames.contains(key)) {
                    tokenCredentials.setAttribute(key, info.get(key));
                }
            }

            // update token node if required: optionally resetting the expiration
            updateTokenNode(expiry, loginTime);
View Full Code Here

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

        Principal pr = user.getPrincipal();
        if (pr instanceof ItemBasedPrincipal) {
            userPath = ((ItemBasedPrincipal) pr).getPath();
        }

        TokenCredentials tokenCredentials;
        if (userPath != null && session.nodeExists(userPath)) {
            Node userNode = session.getNode(userPath);
            Node tokenParent;
            if (userNode.hasNode(TOKENS_NODE_NAME)) {
                tokenParent = userNode.getNode(TOKENS_NODE_NAME);
            } else {
                tokenParent = userNode.addNode(TOKENS_NODE_NAME, TOKENS_NT_NAME);
            }

            long creationTime = new Date().getTime();
            long expirationTime = creationTime + tokenExpiration;

            Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(creationTime);

            // generate key part of the login token
            String key = generateKey(8);

            // create the token node
            String tokenName = Text.replace(ISO8601.format(cal), ":", ".");
            Node tokenNode;
            // avoid usage of sequential nodeIDs
            if (System.getProperty(NodeIdFactory.SEQUENTIAL_NODE_ID) == null) {
                tokenNode = tokenParent.addNode(tokenName);
            } else {
                tokenNode = ((NodeImpl) tokenParent).addNodeWithUuid(tokenName, NodeId.randomId().toString());
            }

            StringBuilder sb = new StringBuilder(tokenNode.getIdentifier());
            sb.append(DELIM).append(key);

            String token = sb.toString();
            tokenCredentials = new TokenCredentials(token);
            credentials.setAttribute(TOKEN_ATTRIBUTE, token);

            // add key property
            tokenNode.setProperty(TOKEN_ATTRIBUTE_KEY, getDigestedKey(key));

            // add expiration time property
            cal.setTimeInMillis(expirationTime);
            tokenNode.setProperty(TOKEN_ATTRIBUTE_EXPIRY, session.getValueFactory().createValue(cal));

            // add additional attributes passed in by the credentials.
            for (String name : credentials.getAttributeNames()) {
                if (!TOKEN_ATTRIBUTE.equals(name)) {
                    String value = credentials.getAttribute(name).toString();
                    tokenNode.setProperty(name, value);
                    tokenCredentials.setAttribute(name, value);
                }
            }
            session.save();
            return tokenCredentials;
        } else {
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

                    }
                }
            }
            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

            return false;
        }

        Credentials credentials = getCredentials();
        if (credentials instanceof TokenCredentials) {
            TokenCredentials tc = (TokenCredentials) credentials;
            TokenAuthentication authentication = new TokenAuthentication(tokenProvider);
            if (authentication.authenticate(tc)) {
                tokenCredentials = tc;
                tokenInfo = authentication.getTokenInfo();
                userId = tokenInfo.getUserId();
View Full Code Here

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

        if (tokenProvider != null && sharedState.containsKey(SHARED_KEY_CREDENTIALS)) {
            Credentials shared = getSharedCredentials();
            if (shared != null && tokenProvider.doCreateToken(shared)) {
                TokenInfo ti = tokenProvider.createToken(shared);
                if (ti != null) {
                    TokenCredentials tc = new TokenCredentials(ti.getToken());
                    Map<String, String> attributes = ti.getPrivateAttributes();
                    for (String name : attributes.keySet()) {
                        tc.setAttribute(name, attributes.get(name));
                    }
                    attributes = ti.getPublicAttributes();
                    for (String name : attributes.keySet()) {
                        tc.setAttribute(name, attributes.get(name));
                    }
                    subject.getPublicCredentials().add(tc);
                }
            }
        }
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.