Package org.jboss.seam.wiki.core.model

Examples of org.jboss.seam.wiki.core.model.User


                );
            }
        }
        uploader.reset();

        User adminUser = (User)Component.getInstance("adminUser");
        User guestUser = (User)Component.getInstance("guestUser");

        if ( !getInstance().getId().equals(adminUser.getId()) &&
             !getInstance().getId().equals(guestUser.getId()) &&
             roles != null && roles.size() > 0) {
            // Roles
            getInstance().setRoles(new ArrayList<Role>()); // Clear out the collection
            getInstance().getRoles().addAll(roles);
        }

        // Preferences
        if (preferenceEditor != null) {
            String editorFailed = preferenceEditor.save();
            if (editorFailed != null) return null;
        }

        boolean loginCredentialsModified = false;

        // User wants to change his password
        if (getPassword() != null && getPassword().length() != 0) {
            if (!passwordAndControlNotNull() ||
                !passwordMatchesRegex() ||
                !passwordMatchesControl()) {

                // Force re-entry
                setPassword(null);
                setPasswordControl(null);

                return null;
            } else {
                // Set password hash
                getInstance().setPasswordHash(hashUtil.hash(getPassword()));
                loginCredentialsModified = true;
            }
        }

        // User changed his username
        if (!getInstance().getUsername().equals(oldUsername)) {
            loginCredentialsModified = true;

            // Validate
            if (!isUniqueUsername()) return null;
        }

        if (Identity.instance().hasPermission("User", "isAdmin", Component.getInstance("currentUser"))) {
            // Current user is admin and activated an account
            if (getInstance().isActivated()) {
                getInstance().setActivationCode(null);
            }
        }

        String outcome = super.update();
        if (outcome != null) {

            org.jboss.seam.core.Events.instance().raiseEvent("User.updated", getInstance());

            User currentUser = (User)Component.getInstance("currentUser");
            if (getInstance().getId().equals(currentUser.getId())) {
                // Updated profile of currently logged-in user
                Contexts.getSessionContext().set("currentUser", getInstance());
               
                // TODO: If identity.logout() wouldn't kill my session, I could call it here...
                // And I don't have cleartext password in all cases, so I can't relogin the user automatically
View Full Code Here


        }
        return true;
    }

    public boolean isUniqueUsername() {
        User foundUser = userDAO.findUser(getInstance().getUsername(), false, false);
        if ( foundUser != null && foundUser != getInstance() ) {
            statusMessages.addToControlFromResourceBundleOrDefault(
                "username",
                WARN,
                "lacewiki.msg.UsernameExists",
View Full Code Here


    public void sendResetPasswordEmail() {
        log.debug("trying to reset password of user: " + username);

        User user = getUserForEmail(username, email);
        if (user == null) {
            statusMessages.addFromResourceBundleOrDefault(
                WARN,
                "lacewiki.msg.resetPassword.NotValid",
                "Your account and e-mail address information didn't match, please try again to reset your password."
            );
            username = null;
            email = null;
            return;
        }

        // Set activation code (unique user in time)
        String seed = user.getUsername() + System.currentTimeMillis() + prefs.getActivationCodeSalt();
        user.setActivationCode( ((Hash) Component.getInstance(Hash.class)).hash(seed) );
        // TODO: Flush by side effect?

        try {

            // Outject for email
View Full Code Here

            statusMessages.add(WARN, "Couldn't send password reset email: " + ex.getMessage());
        }
    }

    public String prepare() {
        User user = userDAO.findUserWithActivationCode(activationCode);
        if (user != null) {
            log.debug("preparing password reset of: " + user);
            user.setActivationCode(null);
            // Outject for form
            Contexts.getSessionContext().set(RESET_PASSWORD_OF_USER, user);

            return "prepared";
        } else {
View Full Code Here

            return "notFound";
        }
    }

    public void reset() {
        User user = (User)Component.getInstance(RESET_PASSWORD_OF_USER);
        if (user == null) {
            throw new IllegalStateException("No user for password reset in SESSION context");
        }

        // Validate
        if (!passwordAndControlNotNull() ||
            !passwordMatchesRegex() ||
            !passwordMatchesControl()) {

            // Force re-entry
            setPassword(null);
            setPasswordControl(null);

            return;
        }
        log.debug("resetting password of: " + user);

        User persistentUser = userDAO.findUser(user.getId());
        persistentUser.setPasswordHash(hashUtil.hash(getPassword()));

        // As a side effect, also activate the user! http://jira.jboss.com/jira/browse/JBSEAM-2687
        persistentUser.setActivated(true);

        Contexts.getSessionContext().remove(RESET_PASSWORD_OF_USER);

        statusMessages.addFromResourceBundleOrDefault(
            INFO,
            "lacewiki.msg.resetPassword.Complete",
            "Successfully reset password of account '{0}', please log in.",
            persistentUser.getUsername()
        );

    }
View Full Code Here

    }

    private User getUserForEmail(String username, String email) {
        if (User.GUEST_USERNAME.equals(username)) return null;
        User user = userDAO.findUser(username, false, true);
        return user != null && user.getEmail().equals(email) ? user : null;
    }
View Full Code Here

                .getSingleResult();
    }

    public void resetNodeCreatorToAdmin(User user) {

        User adminUser = (User) Component.getInstance("adminUser");

        entityManager.createQuery("update WikiNode n set n.createdBy = :admin where n.createdBy = :user")
                    .setParameter("admin", entityManager.merge(adminUser))
                    .setParameter("user", user)
                    .executeUpdate();
View Full Code Here

            protected void beforeRequest() {
                setParameter("activationCode", "ebb0bce9eeeee191e8089afd1120c4a7");
            }

            protected void renderResponse() throws Exception {
                User user = (User)getInstance(UserPasswordReset.RESET_PASSWORD_OF_USER);
                assert user.getId().equals(3l);

            }
        }.run();

        new FacesRequest("/wiki.xhtml") {

            protected void invokeApplication() throws Exception {
                UserPasswordReset reset = (UserPasswordReset)getInstance(UserPasswordReset.class);
                reset.setPassword("foo123");
                reset.setPasswordControl("foo123");

                reset.reset();
            }

            protected void renderResponse() throws Exception {
                User user = (User)getInstance(UserPasswordReset.RESET_PASSWORD_OF_USER);
                assert user == null;

                UserDAO dao = (UserDAO)getInstance(UserDAO.class);
                User dbUser = dao.findUser(3l);
                assert dbUser.getActivationCode() == null;
                Hash hashUtil = (Hash)getInstance(Hash.class);
                assert dbUser.getPasswordHash().equals(hashUtil.hash("foo123"));
            }
        }.run();

    }
View Full Code Here

            Of course that is just wrong and it looks like this warning was added in a hurry between 3.2 and 3.3. Or this is not the
            query that is causing the warning - who knows! It probably would have been too easy printing the offending query string
            with the message...
             */
            User guestUser =
                    (User) entityManager
                            .createQuery("select u from User u left join fetch u.roles where u.username = '"+User.GUEST_USERNAME+"'")
                            .setHint("org.hibernate.cacheable", true)
                            .getSingleResult();
            if (guestUser.getRoles().size() > 1 || guestUser.getRoles().size() == 0) {
                throw new RuntimeException("Your '"+User.GUEST_USERNAME+"' user has none or more than one role assigned, illegal database state");
            }
            if (guestUser.getRoles().iterator().next().getAccessLevel() != Role.GUESTROLE_ACCESSLEVEL) {
                throw new RuntimeException("Your '"+User.GUEST_USERNAME+"' user isn't assigned to the guest role (access level "+Role.GUESTROLE_ACCESSLEVEL+")");
            }
            return guestUser;
        } catch (NoResultException ex) {
            throw new RuntimeException("You need to INSERT a user with username '"+User.GUEST_USERNAME+"' into the database");
View Full Code Here


    @Factory(value = "adminUser", scope = ScopeType.SESSION)
    public User getAdminUser() {
        try {
            User adminUser =
                    (User) entityManager
                            .createQuery("select u from User u left join fetch u.roles where u.username = '"+User.ADMIN_USERNAME+"'")
                            .setHint("org.hibernate.cacheable", true)
                            .getSingleResult();
            if (adminUser.getRoles().size() > 1 || adminUser.getRoles().size() == 0) {
                throw new RuntimeException("Your '"+User.ADMIN_USERNAME+"' user has none or more than one role assigned, illegal database state");
            }
            if (adminUser.getRoles().iterator().next().getAccessLevel() != Role.ADMINROLE_ACCESSLEVEL) {
                throw new RuntimeException("Your '"+User.ADMIN_USERNAME+"' user isn't assigned to the admin role (access level "+Role.ADMINROLE_ACCESSLEVEL+")");
            }
            return adminUser;
        } catch (NoResultException ex) {
            throw new RuntimeException("You need to INSERT a user with username '"+User.ADMIN_USERNAME+"' into the database");
View Full Code Here

TOP

Related Classes of org.jboss.seam.wiki.core.model.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.