public boolean authenticate()

in src/main/java/org/apache/sling/auth/xing/login/impl/XingLoginAuthenticationPlugin.java [42:88]


    public boolean authenticate(final Credentials credentials) throws RepositoryException {
        logger.debug("authenticate");

        // check if given credentials have a hash
        final String givenHash = XingLoginUtil.getHash(credentials);
        if (givenHash == null) {
            logger.debug("unable to get hash from given credentials");
            return false;
        }

        User user = xingLoginUserManager.getUser(credentials);
        if (user == null) { // check if given credentials pull up an existing user
            logger.debug("no user found for given credentials");
            if (xingLoginUserManager.autoCreate()) {
                logger.debug("creating a new user from given user data");
                // validating with hash happens in createUser(credentials)
                user = xingLoginUserManager.createUser(credentials);
            }
        }

        // re-check
        if (user == null) {
            return false;
        }

        // check if stored user has a hash
        final String storedHash = xingLoginUserManager.getHash(user);
        if (storedHash == null) { // should not happen, so return false
            logger.debug("no hash found for user '{}'", user.getID());
            return false;
        }

        // check if hashes match
        if (givenHash.equals(storedHash)) {
            logger.debug("hashes for user '{}' do match", user.getID());
            return true;
        } else {
            logger.debug("hashes for user '{}' do not match", user.getID());
            if (xingLoginUserManager.autoUpdate()) {
                logger.debug("updating an existing user from given user data");
                // validating with hash happens in updateUser(credentials)
                return xingLoginUserManager.updateUser(credentials) != null;
            }
        }

        return false;
    }