leap.core.validation.Validation.addError()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中leap.core.validation.Validation.addError()方法的一些代码示例,展示了Validation.addError()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validation.addError()方法的具体详情如下:
包路径:leap.core.validation.Validation
类名称:Validation
方法名:addError

Validation.addError介绍

暂无

代码示例

代码示例来源:origin: org.leapframework/jmms-core

@Override
  public boolean checkAndConvert(Validation validation, String name, Object value, Out<Object> out) {
    try {
      out.set(Converts.convert(value, targetType));
      return true;
    }catch (ConvertException e) {
      validation.addError(name, "Can't convert to '" + targetType.getSimpleName() + "', invalid data type");
      return false;
    }
  }
}

代码示例来源:origin: org.leapframework/jmms-core

protected boolean validateNumber(Validation validation, String name, Object value) {
  if(validated.hasNumberValidation()) {
    BigDecimal n = Converts.convert(value, BigDecimal.class);
    if(null != maximum && n.compareTo(maximum) > 0) {
      validation.addError(name, "The number must <= " + validated.getMaximum());
      return false;
    }
    if(null != minimum && n.compareTo(minimum) < 0) {
      validation.addError(name, "The number must >= " + validated.getMinimum());
      return false;
    }
  }
  return true;
}

代码示例来源:origin: org.leapframework/jmms-core

@Override
protected boolean doValidate(Validation validation, String name, Object value, Out<Object> out) {
  if(!(value instanceof Map)) {
    validation.addError(name, "Invalid value, must be a map");
    return false;
  }
  if(null != valueValidator) {
    Map map = (Map)value;
    Map converted = null;
    Out<Object> entryOut = new Out<>();
    for(Object object : map.entrySet()) {
      Map.Entry entry = (Map.Entry)object;
      if(!valueValidator.validate(validation, qname(name, entry.getKey().toString()), entry.getValue(), entryOut)) {
        return false;
      }
      if(entryOut.isPresent()) {
        if(null == converted) {
          converted = new HashMap();
        }
        converted.put(entry.getKey(), entryOut.getAndReset());
      }
    }
    if(null != converted) {
      map.putAll(converted);
    }
  }
  return true;
}

代码示例来源:origin: org.leapframework/jmms-core

protected boolean doValidateArray(Validation validation, String name, Enumerable e) {
  int size = e.size();
  if(null != validated.getMinItems() && size < validated.getMinItems()) {
    validation.addError(name, "The array's size must be >= " + validated.getMinItems());
    return false;
  }
  if(null != validated.getMaxItems() && size > validated.getMaxItems()) {
    validation.addError(name, "The array's size must <= " + validated.getMaxItems());
    return false;
  }
  return true;
}

代码示例来源:origin: org.leapframework/jmms-core

protected boolean validateString(Validation validation, String name, Object value) {
  if(validated.hasStringValidation()) {
    String s = Converts.toString(value);
    if(null != validated.getMaxLength() && s.length() > validated.getMaxLength()) {
      validation.addError(name, "The string's length must be <= " + validated.getMaxLength());
      return false;
    }
    if(null != validated.getMinLength() && s.length() < validated.getMinLength()) {
      validation.addError(name, "The string's length must be >= " + validated.getMinLength());
      return false;
    }
    if(null != validated.getEnums() && !Arrays2.contains(validated.getEnums(), s)) {
      validation.addError(name, "The value must be one of [" + Strings.join(validated.getEnums(), ',') + "]");
      return false;
    }
    if(null != validated.getPattern()) {
      if(!validated.getPattern().matcher(value.toString()).matches()){
        validation.addError(name, "The value did not matches the pattern!");
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: org.leapframework/jmms-core

protected boolean validateEnums(Validation validation, String name, Object value) {
    if(validated.hasEnumValidation()) {
      String s = Converts.toString(value);

      if(Arrays2.indexOf(validated.getEnums(), s) < 0) {
        validation.addError(name, "The value must be one of [" + stringEnums + "]");
        return false;
      }
    }
    return true;
  }
}

代码示例来源:origin: org.leapframework/leap-websecurity

protected UserDetails resolveUserDetails(ValidationContext context, String username, Map<String, Object> params) {
  UserDetails details =
      sc.getUserStore().loadUserDetailsByLoginName(username);
  
  //User not found
  if(null == details){
    log.debug("User '{}' not found",username);
    context.validation().addError(UsernamePasswordCredentials.USERNAME, USER_NOT_FOUND_MESSAGE_KEY, "User not found");
    return null;
  }
  
  //Check enabled
  if(!details.isEnabled()){
    log.debug("User '{}' was disabled",username);
    context.validation().addError(UsernamePasswordCredentials.USERNAME, USER_NOT_ENABLED_MESSAGE_KEY,"User was disabled");
    return null;
  }
  
  return details;
}

代码示例来源:origin: org.leapframework/jmms-core

for(String fieldName : requiredProperties) {
  if(Strings.isNullOrEmpty(map.get(fieldName))) {
    validation.addError(qname(name, fieldName), "The property is required!");
    return false;
  Object v = map.get(fieldName);
  if(!Strings.isNullOrEmpty(v)) {
    validation.addError(qname(name, fieldName), "The property is read only");
    return false;

代码示例来源:origin: org.leapframework/jmms-core

@Override
protected boolean doValidate(Validation validation, String name, Object value, Out<Object> out) {
  Enumerable e;
  try {
    e = Enumerables.of(value);
  }catch (IllegalArgumentException ex) {
    validation.addError(name, "The value must be an array or collection");
    return false;
  }
  if(null != arrayValidator && !arrayValidator.doValidateArray(validation, name, e)) {
    return false;
  }
  if(null != elementValidator) {
    int i=0;
    for(Object element : e) {
      if(!elementValidator.validate(validation, name + "[" + i + "]", element, Out.empty())) {
        return false;
      }
      i++;
    }
  }
  return true;
}

代码示例来源:origin: org.leapframework/leap-oauth2-server

validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client_id required");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "redirect_uri required");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid client_id");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client disabled");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid redirect_uri");
request.forwardToView(config.getErrorView());
return null;

代码示例来源:origin: org.leapframework/leap-oauth2

validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client_id required");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "redirect_uri required");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid client_id");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client disabled");
request.forwardToView(config.getErrorView());
return null;
validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid redirect_uri");
request.forwardToView(config.getErrorView());
return null;

代码示例来源:origin: org.leapframework/leap-oauth2-server

protected ResponseTypeHandler getResponseTypeHandler(Request request, Response response, OAuth2Params params) throws Throwable {
  //String redirectUri  = params.getRedirectUri();
  String responseType = params.getResponseType();
  if(Strings.isEmpty(responseType)) {
    //if(Strings.isEmpty(redirectUri)) {
    log.debug("error : response_type required");
    request.getValidation().addError(OAuth2Errors.ERROR_INVALID_REQUEST, "response_type required");
    request.forwardToView(config.getErrorView());
    //}else{
    //    OAuth2Errors.redirectInvalidRequest(response, redirectUri, "response_type required");
    //}
    return null;
  }
  ResponseTypeHandler handler = factory.tryGetBean(ResponseTypeHandler.class, responseType);
  if(null == handler) {
    log.info("error : invalid response type {}", responseType);
    //if(Strings.isEmpty(redirectUri)) {
      request.getValidation().addError(OAuth2Errors.ERROR_INVALID_REQUEST, "unsupported or invalid response type");
      request.forwardToView(config.getErrorView());
    //}else{
    //    OAuth2Errors.redirectUnsupportedResponseType(response, redirectUri, "unsupported or invalid response type");
    //}
    return null;
  }
  return handler;
}

代码示例来源:origin: org.leapframework/leap-oauth2

protected ResponseTypeHandler getResponseTypeHandler(Request request, Response response, OAuth2Params params) throws Throwable {
  //String redirectUri  = params.getRedirectUri();
  String responseType = params.getResponseType();
  if(Strings.isEmpty(responseType)) {
    //if(Strings.isEmpty(redirectUri)) {
    log.debug("error : response_type required");
    request.getValidation().addError(OAuth2Errors.ERROR_INVALID_REQUEST, "response_type required");
    request.forwardToView(config.getErrorView());
    //}else{
    //    OAuth2Errors.redirectInvalidRequest(response, redirectUri, "response_type required");
    //}
    return null;
  }
  ResponseTypeHandler handler = factory.tryGetBean(ResponseTypeHandler.class, responseType);
  if(null == handler) {
    log.info("error : invalid response type {}", responseType);
    //if(Strings.isEmpty(redirectUri)) {
      request.getValidation().addError(OAuth2Errors.ERROR_INVALID_REQUEST, "unsupported or invalid response type");
      request.forwardToView(config.getErrorView());
    //}else{
    //    OAuth2Errors.redirectUnsupportedResponseType(response, redirectUri, "unsupported or invalid response type");
    //}
    return null;
  }
  return handler;
}

代码示例来源:origin: org.leapframework/leap-oauth2-server

if(Strings.isEmpty(clientId)) {
  log.debug("error : client_id required");
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client_id required");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
if(Strings.isEmpty(redirectUri)) {
  log.debug("error : redirect_uri required");
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "redirect_uri required");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
if(null == client) {
  log.debug("error : client_id {} not found", clientId);
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid client_id");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client disabled");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid redirect_uri");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();

代码示例来源:origin: org.leapframework/leap-oauth2

if(Strings.isEmpty(clientId)) {
  log.debug("error : client_id required");
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client_id required");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
if(Strings.isEmpty(redirectUri)) {
  log.debug("error : redirect_uri required");
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "redirect_uri required");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
if(null == client) {
  log.debug("error : client_id {} not found", clientId);
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid client_id");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "client disabled");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();
  validation.addError(OAuth2Errors.ERROR_INVALID_REQUEST, "invalid redirect_uri");
  request.forwardToView(config.getErrorView());
  return Result.intercepted();

代码示例来源:origin: org.leapframework/leap-websecurity

@Override
  public boolean authenticate(CredentialsAuthenticationContext context, 
                Credentials credentials, 
                Out<UserPrincipal> principal) throws AuthenticationException {
    
    if(credentials instanceof UsernamePasswordCredentials){
      UsernamePasswordCredentials usernamePassword = (UsernamePasswordCredentials)credentials;
      
      UserDetails details = resolveUserDetails(context, usernamePassword.getUsername(), usernamePassword.getParameters());
      if(null == details) {
        return true;
      }
      
      //Check password
      String rawPassword = Strings.nullToEmpty(usernamePassword.getPassword());
      if(!sc.getPasswordEncoder().matches(rawPassword, details.getPassword())){
        log.debug("Incorrect password of user '{}'",usernamePassword.getUsername());
        context.validation().addError(UsernamePasswordCredentials.PASSWORD, INCORRECT_PASSWORD_MESSAGE_KEY,"Incorrect password");
      }else{
        principal.set(details);
      }

      return true;
    }
    
    return false;
  }
}

相关文章