Package org.apache.sling.auth.xing.api

Examples of org.apache.sling.auth.xing.api.XingUser


        try {
            final HttpSession httpSession = request.getSession(true);

            Token accessToken = (Token) httpSession.getAttribute(OAuthConstants.ACCESS_TOKEN);
            XingUser xingUser = (XingUser) httpSession.getAttribute(USER_SESSION_ATTRIBUTE_NAME);

            if (accessToken == null) {
                // we need the request token and verifier to get an access token
                final Token requestToken = (Token) httpSession.getAttribute(OAuthConstants.TOKEN);
                final String verifier = request.getParameter(OAuthConstants.VERIFIER);
                if (requestToken == null || verifier == null) {
                    return null;
                }
                accessToken = oAuthService.getAccessToken(requestToken, new Verifier(verifier));
                logger.debug("access token: {}", accessToken);
                httpSession.setAttribute(OAuthConstants.ACCESS_TOKEN, accessToken);
            }

            if (xingUser == null) {
                xingUser = fetchUser(accessToken);
                logger.debug("xing user: {}", xingUser);
                httpSession.setAttribute(USER_SESSION_ATTRIBUTE_NAME, xingUser);
            }

            final AuthenticationInfo authenticationInfo = new AuthenticationInfo(XingOauth.AUTH_TYPE, xingUser.getId());
            authenticationInfo.put(XingOauth.AUTHENTICATION_CREDENTIALS_ACCESS_TOKEN_KEY, accessToken);
            authenticationInfo.put(XingOauth.AUTHENTICATION_CREDENTIALS_USER_KEY, xingUser);
            return authenticationInfo;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
View Full Code Here


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

        final Token accessToken = XingOauthUtil.getAccessToken(credentials);
        final XingUser xingUser = XingOauthUtil.getXingUser(credentials);
        if (accessToken == null || xingUser == null) {
            return false;
        }

        User user = xingOauthUserManager.getUser(credentials);
View Full Code Here

    }

    @Override
    public User createUser(final Credentials credentials) {
        logger.debug("create user");
        final XingUser xingUser = XingOauthUtil.getXingUser(credentials);
        if (xingUser == null) {
            return null;
        }

        try {
            final String userId = xingUser.getId(); // TODO make configurable

            final Session session = getSession();
            final UserManager userManager = getUserManager(session);
            final User user = userManager.createUser(userId, null);

            // TODO disable user on create?
            final ValueFactory valueFactory = session.getValueFactory();
            final Value firstnameValue = valueFactory.createValue(xingUser.getFirstName());
            final Value lastnameValue = valueFactory.createValue(xingUser.getLastName());
            user.setProperty(FIRSTNAME_PROPERTY, firstnameValue);
            user.setProperty(LASTNAME_PROPERTY, lastnameValue);
            session.save();
            return user;
        } catch (Exception e) {
View Full Code Here

    }

    @Override
    public User updateUser(Credentials credentials) {
        logger.debug("update user");
        final XingUser xingUser = XingOauthUtil.getXingUser(credentials);
        if (xingUser == null) {
            return null;
        }

        try {
            final Session session = getSession();
            final User user = getUser(credentials);
            final ValueFactory valueFactory = session.getValueFactory();

            final boolean firstnameUpdated = updateUserProperty(user, valueFactory, FIRSTNAME_PROPERTY, xingUser.getFirstName());
            final boolean lastnameUpdated = updateUserProperty(user, valueFactory, LASTNAME_PROPERTY, xingUser.getLastName());
            if (firstnameUpdated || lastnameUpdated) {
                session.save();
            }

            return user;
View Full Code Here

    @Override
    public boolean canHandle(final Credentials credentials) {
        logger.debug("canHandle({})", credentials);
        final Token accessToken = XingOauthUtil.getAccessToken(credentials);
        final XingUser xingUser = XingOauthUtil.getXingUser(credentials);
        logger.debug("access token: {}, xing user: {}", accessToken, xingUser);
        return accessToken != null && xingUser != null;
    }
View Full Code Here

            logger.error(e.getMessage(), e);
            return null;
        }

        try {
            final XingUser xingUser = XingLoginUtil.fromJson(json);
            final String userId = xingUser.getId(); // TODO make configurable

            User user = getUser(userId);
            if (user == null) {
                logger.debug("creating a new user with id '{}'", userId);
                final Session session = getSession();
View Full Code Here

TOP

Related Classes of org.apache.sling.auth.xing.api.XingUser

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.