Package net.sourceforge.pebble.security

Examples of net.sourceforge.pebble.security.SecurityRealm


      // can the user change their user details?
      if (!currentUserDetails.isDetailsUpdateable()) {
        return new FourZeroThreeView();
      }

      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      PebbleUserDetails newUserDetails;

      ValidationContext validationContext = new ValidationContext();

      if (!validationContext.hasErrors()) {
      newUserDetails = new PebbleUserDetails(
          currentUserDetails.getUsername(),
          name,
          emailAddress,
          website,
          profile,
          currentUserDetails.getRoles(),
          currentUserDetails.getPreferences(),
          currentUserDetails.isDetailsUpdateable());

          realm.updateUser(newUserDetails);

          return new RedirectView(blog.getUrl() + "editUserDetails.secureaction");
      }

      getModel().put("validationContext", validationContext);
View Full Code Here


    }
  }

  public static PebbleUserDetails getUserDetails() {
    try {
      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      return realm.getUser(getUsername());
    } catch (SecurityRealmException e) {
      log.error("Exception encountered", e);
      return null;
    }
  }
View Full Code Here

    try {
      AbstractBlog blog = (AbstractBlog)getModel().get(Constants.BLOG_KEY);
      String usernames[] = request.getParameterValues("user");
      String submit = request.getParameter("submit");

      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      if (usernames != null) {
        for (String username : usernames) {
          if (submit.equalsIgnoreCase("Remove")) {
            realm.removeUser(username);
          } else if (submit.equalsIgnoreCase("Reset Password")) {
            realm.changePassword(username, "password");
          }
        }
      }

      return new RedirectView(blog.getUrl() + "viewUsers.secureaction");
View Full Code Here

      // can the user change their user details?
      if (!currentUserDetails.isDetailsUpdateable()) {
        return new FourZeroThreeView();
      }

      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();

      ValidationContext validationContext = new ValidationContext();

      if (!validationContext.hasErrors()) {
        currentUserDetails.setPreferences(preferences);
        realm.updateUser(currentUserDetails);

        return new RedirectView(blog.getUrl() + "editUserPreferences.secureaction");
      }

      getModel().put("validationContext", validationContext);
View Full Code Here

   *
   * @return  a PebbleUserDetails instance
   */
  public PebbleUserDetails getUser() {
    if (this.user == null) {
      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      try {
        this.user = realm.getUser(getAuthor());
      } catch (SecurityRealmException e) {
        log.error("Exception encountered", e);
      }
    }

View Full Code Here

   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    String username = request.getParameter("user");
    SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
    try {
      PebbleUserDetails user = realm.getUser(username);
      if (user != null) {
        getModel().put(Constants.USER_KEY, user);
        getModel().put(Constants.BLOG_ENTRIES, blog.getRecentPublishedBlogEntries(username));
        return new AboutAuthorView();
      }
View Full Code Here

        if (parameterName.startsWith(PREFERENCE)) {
          preferences.put(parameterName.substring(PREFERENCE.length()), request.getParameter(parameterName));
        }
      }

      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      PebbleUserDetails currentUserDetails = realm.getUser(username);
      PebbleUserDetails newUserDetails = new PebbleUserDetails(username, password1, name, emailAddress, website, profile, roles, preferences, detailsUpdateable);

      ValidationContext validationContext = new ValidationContext();

      if (newUser && currentUserDetails != null) {
        validationContext.addError("A user with this username already exists");
      } else if (newUser && (username == null || username.trim().length() == 0)) {
        validationContext.addError("Username can't be empty");
      } else if (password1 != null && password1.length() > 0 && !password1.equals(password2)) {
        validationContext.addError("Passwords must match");
      } else {

        if (newUser) {
          try {
            realm.createUser(newUserDetails);
          } catch (SecurityRealmException sre) {
            validationContext.addError(sre.getMessage());
          }
        } else {
          realm.updateUser(newUserDetails);
          if (password1 != null && password1.length() > 0) {
            realm.changePassword(username, password1);
          }
        }
        return new RedirectView(blog.getUrl() + "viewUsers.secureaction");
      }
View Full Code Here

   * @param response the HttpServletResponse instance
   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    try {
      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      PebbleUserDetails currentUserDetails = SecurityUtils.getUserDetails();
      String password1 = request.getParameter("password1");
      String password2 = request.getParameter("password2");
      String submit = request.getParameter("submit");

      // can the user change their user details?
      if (!currentUserDetails.isDetailsUpdateable()) {
        return new ForbiddenView();
      }

      if (submit == null || submit.length() == 0) {
        return new ChangePasswordView();
      }

      ValidationContext validationContext = new ValidationContext();

      if (password1 == null || password1.length() == 0) {
        validationContext.addError("Password can not be empty");
      } else if (!password1.equals(password2)) {
        validationContext.addError("Passwords do not match");
      }

      if (!validationContext.hasErrors()) {
          realm.changePassword(currentUserDetails.getUsername(), password1);

          return new PasswordChangedView();
      }

      getModel().put("validationContext", validationContext);
View Full Code Here

TOP

Related Classes of net.sourceforge.pebble.security.SecurityRealm

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.