Package org.apache.jackrabbit.api.security.user

Examples of org.apache.jackrabbit.api.security.user.User


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

        User user = xingOauthUserManager.getUser(credentials);
        if (user == null) { // check if given credentials pulled up an existing user
            logger.debug("no user found for given credentials");
            if (xingOauthUserManager.autoCreate()) {
                logger.debug("creating a new user from given user data");
                user = xingOauthUserManager.createUser(credentials);
View Full Code Here


        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) {
            logger.error(e.getMessage(), e);
            return null;
View Full Code Here

            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) {
View Full Code Here

                    : null;
            if ( resolver != null ) {
                final Session session = resolver.adaptTo(Session.class);
                if ( session != null ) {
                    try {
                        final User u = this.authenticate(session);
                        if ( u != null ) {
                            request.setAttribute(USER_ATTRIBUTE, u);
                            return true;
                        }
                    } catch (final Exception re) {
View Full Code Here

    @Override
    public Principal getPrincipal(final Credentials credentials) {
        logger.debug("getPrincipal({})", credentials);
        try {
            User user = xingOauthUserManager.getUser(credentials);
            if (user == null && xingOauthUserManager.autoCreate()) {
                user = xingOauthUserManager.createUser(credentials);
            }
            if (user != null) {
                return user.getPrincipal();
            }
        } catch (RepositoryException e) {
            logger.error(e.getMessage(), e);
        }
        return null;
View Full Code Here

        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;
            }
View Full Code Here

        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();
                final UserManager userManager = getUserManager(session);
                user = userManager.createUser(userId, null);
            } else {
                logger.debug("updating an existing user with id '{}'", userId);
            }

            // TODO disable user on create?
            final ValueFactory valueFactory = getSession().getValueFactory();
            final Value dataValue = valueFactory.createValue(json);
            final Value hashValue = valueFactory.createValue(givenHash);
            user.setProperty(userDataProperty, dataValue);
            user.setProperty(userHashProperty, hashValue);
            session.save();
            return user;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
View Full Code Here

        if ("anonymous".equals(name)) {
            throw new RepositoryException(
                "Can not change the password of the anonymous user.");
        }

        User user;
        UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
        Authorizable authorizable = userManager.getAuthorizable(name);
        if (authorizable instanceof User) {
            user = (User)authorizable;
        } else {
            throw new ResourceNotFoundException(
                "User to update could not be determined");
        }

        //SLING-2069: if the current user is an administrator, then a missing oldPwd is ok,
        // otherwise the oldPwd must be supplied.
        boolean administrator = false;

        // check that the submitted parameter values have valid values.
        if (oldPassword == null || oldPassword.length() == 0) {
            try {
                UserManager um = AccessControlUtil.getUserManager(jcrSession);
                User currentUser = (User) um.getAuthorizable(jcrSession.getUserID());
                administrator = currentUser.isAdmin();

                if (!administrator) {
                    //check if the user is a member of the 'User administrator' group
                    Authorizable userAdmin = um.getAuthorizable(this.userAdminGroupName);
                    if (userAdmin instanceof Group) {
View Full Code Here

     */
    public User updateUser(Session jcrSession, String name,
            Map<String, ?> properties, List<Modification> changes)
            throws RepositoryException {

        User user;
        UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
        Authorizable authorizable = userManager.getAuthorizable(name);
        if (authorizable instanceof User) {
            user = (User)authorizable;
        } else {
            throw new ResourceNotFoundException(
                "User to update could not be determined");
        }

        String userPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX
            + user.getID();

        Map<String, RequestProperty> reqProperties = collectContent(properties, userPath);
        try {
            // cleanup any old content (@Delete parameters)
            processDeletes(user, reqProperties, changes);

            // write content from form
            writeContent(jcrSession, user, reqProperties, changes);

            //SLING-2072 set the user as enabled or disabled if the request
            // has supplied the relevant properties
            String disabledParam = convertToString(properties.get(":disabled"));
            if ("true".equalsIgnoreCase(disabledParam)) {
                //set the user as disabled
                String disabledReason = convertToString(properties.get(":disabledReason"));
                if (disabledReason == null) {
                    disabledReason = "";
                }
                user.disable(disabledReason);
            } else if ("false".equalsIgnoreCase(disabledParam)) {
                //re-enable a disabled user
                user.disable(null);
            }
        } catch (RepositoryException re) {
            throw new RepositoryException("Failed to update user.", re);
        }
        return user;
View Full Code Here

     * @see org.apache.sling.jackrabbit.usermanager.DeleteUser#deleteUser(javax.jcr.Session, java.lang.String, java.util.List)
     */
    public void deleteUser(Session jcrSession, String name,
            List<Modification> changes) throws RepositoryException {

        User user;
        UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
        Authorizable authorizable = userManager.getAuthorizable(name);
        if (authorizable instanceof User) {
            user = (User)authorizable;
        } else {
            throw new ResourceNotFoundException(
                "User to delete could not be determined");
        }
       
        String userPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_USER_PREFIX
                            + user.getID();
        user.remove();
        changes.add(Modification.onDeleted(userPath));
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.api.security.user.User

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.