Package net.sourceforge.pebble.web.validation

Examples of net.sourceforge.pebble.web.validation.ValidationContext


public class ValidationContextTest extends TestCase {

  private ValidationContext context;

  protected void setUp() throws Exception {
    this.context = new ValidationContext();
  }
View Full Code Here


  @Inject
  private SecurityRealm securityRealm;

  public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    PebbleUserDetails userDetails = SecurityUtils.getUserDetails();
    ValidationContext validationContext = new ValidationContext();
    AbstractBlog blog = (AbstractBlog)getModel().get(Constants.BLOG_KEY);

    String identity = request.getParameter("openid.identity");

    // No identity, assume this is an add request
    if (identity == null || identity.length() == 0) {
      String claimedIdentity = request.getParameter("openid_identifier");
      try {
        String returnToUrl = request.getRequestURL().toString();
        String realm = PebbleContext.getInstance().getConfiguration().getUrl();
        String openIdUrl = openIDConsumer.beginConsumption(request, claimedIdentity, returnToUrl, realm);
        return new RedirectView(openIdUrl);
      } catch (OpenIDConsumerException oice) {
        log.error("Error adding OpenID", oice);
        validationContext.addError("Error adding OpenID " + oice.getMessage());
      }

    } else {

      try {
        OpenIDAuthenticationToken token = openIDConsumer.endConsumption(request);
        if (token.getStatus() == OpenIDAuthenticationStatus.SUCCESS) {
          // Check that the OpenID isn't already mapped
          String openId = token.getIdentityUrl();
          if (securityRealm.getUserForOpenId(openId) != null) {
            validationContext.addError("The OpenID supplied is already mapped to a user.");
          } else {
            // Add it
            securityRealm.addOpenIdToUser(userDetails, openId);
            return new RedirectView(blog.getUrl() + "/editUserPreferences.secureaction");
          }
        } else {
          validationContext.addError(StringUtils.transformHTML(token.getMessage()));
        }

      } catch (OpenIDConsumerException oice) {
        log.error("Error in consumer", oice);
        validationContext.addError("Error adding OpenID " + oice.getMessage());
      } catch (SecurityRealmException sre) {
        log.error("Error looking up user by security realm", sre);
      }
    }
View Full Code Here

    // we don't want to actually edit the original whilst previewing
    staticPage = (StaticPage)staticPage.clone();
    populateStaticPage(staticPage, request);

    ValidationContext validationContext = new ValidationContext();
    staticPage.validate(validationContext);
    getModel().put("validationContext", validationContext);
    getModel().put(Constants.STATIC_PAGE_KEY, staticPage);

    return new StaticPageFormView();
View Full Code Here

    StaticPageService service = new StaticPageService();
    StaticPage staticPage = getStaticPage(request);
    populateStaticPage(staticPage, request);
    getModel().put(Constants.STATIC_PAGE_KEY, staticPage);

    ValidationContext validationContext = new ValidationContext();
    staticPage.validate(validationContext);

    if (validationContext.hasErrors())  {
      getModel().put("validationContext", validationContext);
      return new StaticPageFormView();
    } else {
      try {
        service.putStaticPage(staticPage);
View Full Code Here

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

    return comment;
  }

  protected ValidationContext validateComment(Comment comment) {
    ValidationContext context = new ValidationContext();
    try {
      MailUtils.validate(comment.getEmail(), context);
    } catch (NoClassDefFoundError e) {
      // most likely: JavaMail is not in classpath
      // ignore, when we can not send email we must not validate address
View Full Code Here

TOP

Related Classes of net.sourceforge.pebble.web.validation.ValidationContext

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.