Package org.damour.base.client.objects

Examples of org.damour.base.client.objects.User


  public void populateUI() {
    principalListBox.clear();
    for (Permission permission : permissions) {
      if (showUserPerms && permission.getSecurityPrincipal() instanceof User) {
        User user = (User) permission.getSecurityPrincipal();
        principalListBox.addItem(user.getUsername());
      } else if (showGroupPerms && permission.getSecurityPrincipal() instanceof UserGroup) {
        UserGroup group = (UserGroup) permission.getSecurityPrincipal();
        principalListBox.addItem(group.getName());
      }
    }
View Full Code Here


  }

  private User login(org.hibernate.Session session, HttpServletRequest request, HttpServletResponse response, String username, String password, boolean internal)
      throws SimpleMessageException {
    username = username.toLowerCase();
    User user = UserHelper.getUser(session, username);
    MD5 md5 = new MD5();
    md5.Update(password);
    String passwordHash = md5.asHex();
    if (user != null && isAccountValidated(user) && ((internal && password.equals(user.getPasswordHash())) || user.getPasswordHash().equals(passwordHash))) {
      Cookie userCookie = new Cookie("user", user.getUsername());
      userCookie.setPath("/");
      userCookie.setMaxAge(COOKIE_TIMEOUT);
      Cookie userAuthCookie = new Cookie("auth", internal ? password : passwordHash);
      userAuthCookie.setPath("/");
      userAuthCookie.setMaxAge(COOKIE_TIMEOUT);
View Full Code Here

    }
    if (userCookie == null || userAuthCookie == null) {
      return null;
    }
    String username = userCookie.getValue().toLowerCase();
    User user = UserHelper.getUser(session, username);
    if (user != null && userAuthCookie.getValue().equals(user.getPasswordHash())) {
      return user;
    }
    return null;
  }
View Full Code Here

      }
    }
    if (userCookie == null || userAuthCookie == null) {
      throw new LoginException("Could not get authenticated user.");
    }
    User user = getAuthenticatedUser(session.get());
    if (user == null) {
      destroyAuthCookies(getThreadLocalRequest(), getThreadLocalResponse());
      throw new LoginException("Could not get authenticated user.");
    }
    return user;
View Full Code Here

  // create or edit account
  public User createOrEditAccount(User inUser, String password, String captchaText) throws SimpleMessageException {
    Transaction tx = session.get().beginTransaction();
    try {
      User possibleAuthUser = getAuthenticatedUser(session.get());
      User authUser = null;
      if (possibleAuthUser instanceof User) {
        authUser = (User) possibleAuthUser;
      }

      User dbUser = null;
      try {
        dbUser = (User) session.get().load(User.class, inUser.getId());
      } catch (Exception e) {
      }

      if (dbUser == null) {
        // new account, it did NOT exist
        // validate captcha first
        if (StringUtils.isEmpty(captchaText)) {
          captchaText = "INVALID!";
        }
        Captcha captcha = (Captcha) getThreadLocalRequest().getSession().getAttribute("captcha");
        if (captcha != null && !captcha.isValid(captchaText)) {
          throw new SimpleMessageException("CAPTCHA validation failed");
        }

        User newUser = new User();
        newUser.setUsername(inUser.getUsername().toLowerCase());
        if (password != null && !"".equals(password)) {
          MD5 md5 = new MD5();
          md5.Update(password);
          newUser.setPasswordHash(md5.asHex());
        }
        if (authUser != null && authUser.isAdministrator()) {
          newUser.setAdministrator(inUser.isAdministrator());
        }
        newUser.setFirstname(inUser.getFirstname());
        newUser.setLastname(inUser.getLastname());
        newUser.setEmail(inUser.getEmail());
        newUser.setBirthday(inUser.getBirthday());
        newUser.setPasswordHint(inUser.getPasswordHint());

        newUser.setValidated(!BaseSystem.requireAccountValidation());
        if (authUser != null && authUser.isAdministrator()) {
          // admin can automatically create/validate accounts
          newUser.setValidated(true);
        }

        session.get().save(newUser);

        UserGroup userGroup = new UserGroup();
        userGroup.setName(newUser.getUsername());
        userGroup.setVisible(true);
        userGroup.setAutoJoin(false);
        userGroup.setLocked(false);
        userGroup.setOwner(newUser);

        session.get().save(userGroup);

        GroupMembership groupMembership = new GroupMembership();
        groupMembership.setUser(newUser);
        groupMembership.setUserGroup(userGroup);
        session.get().save(groupMembership);

        tx.commit();

        // if a new user is creating a new account, login if new user account is validated
        if (authUser == null && isAccountValidated(newUser)) {
          destroyAuthCookies(getThreadLocalRequest(), getThreadLocalResponse());
          if (login(session.get(), getThreadLocalRequest(), getThreadLocalResponse(), newUser.getUsername(), newUser.getPasswordHash(), true) != null) {
            return newUser;
          }
        } else if (authUser == null && !isAccountValidated(newUser)) {
          // send user a validation email, where, upon clicking the link, their account will be validated
          // the validation code in the URL will simply be a hash of their email address
          MD5 md5 = new MD5();
          md5.Update(newUser.getEmail());
          md5.Update(newUser.getPasswordHash());

          String portStr = "";
          if (getThreadLocalRequest().getLocalPort() != 80) {
            portStr = ":" + getThreadLocalRequest().getLocalPort();
          }
          String url = getThreadLocalRequest().getScheme() + "://" + getThreadLocalRequest().getServerName() + portStr + "/?u=" + newUser.getUsername() + "&v="
              + md5.asHex();

          String text = "Thank you for signing up with " + BaseSystem.getDomainName()
              + ".<BR><BR>Please confirm your account by clicking the following link:<BR><BR>";
          text += "<A HREF=\"";
          text += url;
          text += "\">" + url + "</A>";
          BaseSystem.getEmailService().sendMessage(BaseSystem.getSmtpHost(), BaseSystem.getAdminEmailAddress(), BaseSystem.getDomainName() + " validator",
              newUser.getEmail(), BaseSystem.getDomainName() + " account validation", text);
        }
        return newUser;
      } else if (authUser != null && (authUser.isAdministrator() || authUser.getId().equals(dbUser.getId()))) {
        // edit an existing account
        // the following conditions must be met to be here:
View Full Code Here

      }
    }
  }

  public String getLoginHint(String username) throws SimpleMessageException {
    User user = UserHelper.getUser(session.get(), username.toLowerCase());
    if (user == null) {
      throw new SimpleMessageException("Could not get login hint.");
    }
    return user.getPasswordHint();
  }
View Full Code Here

  public List<User> getUsers() throws SimpleMessageException {
    return SecurityHelper.getUsers(session.get());
  }

  public List<UserGroup> getGroups(User user) throws SimpleMessageException {
    User authUser = getAuthenticatedUser(session.get());
    // the admin & actual user can list all groups for the user
    if (authUser != null && (authUser.isAdministrator() || authUser.equals(user))) {
      return SecurityHelper.getUserGroups(session.get(), user);
    }
    // everyone else can only see visible groups for the user
    return SecurityHelper.getVisibleUserGroups(session.get(), user);
  }
View Full Code Here

    removeButton.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        final int index = membersListBox.getSelectedIndex();
        final String username = membersListBox.getItemText(index);
        final User user = userMap.get(username);
        final AsyncCallback<Void> deleteUserCallback = new AsyncCallback<Void>() {
          public void onFailure(Throwable caught) {
            MessageDialogBox dialog = new MessageDialogBox("Error", caught.getMessage(), true, true, true);
            dialog.center();
          }

          public void onSuccess(Void nothing) {
            members.remove(user);
            populateUI();
            try {
              if (index < membersListBox.getItemCount()) {
                membersListBox.setSelectedIndex(index);
              } else {
                membersListBox.setSelectedIndex(index - 1);
              }
            } catch (Exception e) {
            }
            onChange(new com.google.gwt.event.dom.client.ChangeEvent() {
              public Object getSource() {
                return membersListBox;
              }
            });
          };
        };
        BaseServiceCache.getService().deleteUser(user, group, deleteUserCallback);
      }
    });
    removeButton.setText(" < ");
    removeButton.setTitle("Remove Member");

    addButton.setText(" > ");
    addButton.setTitle("Add Member");
    addButton.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        final int index = allUsersListBox.getSelectedIndex();
        final String username = allUsersListBox.getItemText(index);
        final User user = userMap.get(username);
        final AsyncCallback<GroupMembership> addUserCallback = new AsyncCallback<GroupMembership>() {
          public void onFailure(Throwable caught) {
            MessageDialogBox dialog = new MessageDialogBox("Error", caught.getMessage(), true, true, true);
            dialog.center();
          }
View Full Code Here

  public void populateUI() {
    nameTextBox.setText(group.getName());
    descriptionTextBox.setText(group.getDescription());
    if (showUsers) {
      for (int i = 0; i < users.size(); i++) {
        User user = users.get(i);
        ownerListBox.addItem(user.getUsername());
        if (user.getId().equals(group.getOwner().getId())) {
          group.setOwner(user);
          ownerListBox.setSelectedIndex(i);
        }
      }
    }
View Full Code Here

public class UserHelper {

  public static User getUser(Session session, String username) {
    List<User> users = session.createQuery("from User where username = '" + username + "'").setCacheable(true).list();
    User user = null;
    if (users != null && users.size() > 0) {
      user = users.get(0);
    }
    if (user == null) {
      // try email
View Full Code Here

TOP

Related Classes of org.damour.base.client.objects.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.