Examples of TokenCredentials


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

    }

    @Test
    public void testDoCreateToken() throws Exception {
        assertFalse(tokenProvider.doCreateToken(new GuestCredentials()));
        assertFalse(tokenProvider.doCreateToken(new TokenCredentials("token")));
        assertFalse(tokenProvider.doCreateToken(getAdminCredentials()));

        SimpleCredentials sc = new SimpleCredentials("uid", "pw".toCharArray());
        assertFalse(tokenProvider.doCreateToken(sc));
View Full Code Here

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

    @Test
    public void testCreateTokenFromInvalidCredentials() throws Exception {
        List<Credentials> invalid = new ArrayList<Credentials>();
        invalid.add(new GuestCredentials());
        invalid.add(new TokenCredentials("sometoken"));
        invalid.add(new ImpersonationCredentials(new GuestCredentials(), null));
        invalid.add(new SimpleCredentials("unknownUserId", new char[0]));

        for (Credentials creds : invalid) {
            assertNull(tokenProvider.createToken(creds));
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

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

        String token = tokenNode.getIdentifier();

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

        tokenCreds = new TokenCredentials(token);
    }
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;
        return validateCredentials(tokenCredentials);
    }
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)) {
                userNode.addNode(TOKENS_NODE_NAME, TOKENS_NT_NAME);
                try {
                    session.save();
                } catch (RepositoryException e) {
                    // may happen when .tokens node is created concurrently
                    session.refresh(false);
                }
            }
            tokenParent = userNode.getNode(TOKENS_NODE_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);
            sc.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 : sc.getAttributeNames()) {
                if (!TOKEN_ATTRIBUTE.equals(name)) {
                    String value = sc.getAttribute(name).toString();
                    tokenNode.setProperty(name, value);
                    tokenCredentials.setAttribute(name, value);
                }
            }
            session.save();
            return new CompatModeInfo(token, tokenNode);
        } else {
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 : attributes.keySet()) {
                tc.setAttribute(name, attributes.get(name));
            }
            for (String name : info.keySet()) {
                tc.setAttribute(name, info.get(name));
            }
            return 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.