Exemplo n.º 1
0
 private void fillSecurityMetadata(ApiAction action, Method method) {
   Secured securedAnnotation = method.getAnnotation(Secured.class);
   if (securedAnnotation != null) {
     SecurityInfo info = new SecurityInfo();
     info.setDetectUser(securedAnnotation.detectUser());
     info.setRoles(securedAnnotation.roles());
     action.setSecurityInfo(info);
   }
 }
Exemplo n.º 2
0
  private void fillParamsMetadata(ApiAction action, MethodRef methodRef) throws ApiException {
    final Class[] params = methodRef.getMethod().getParameterTypes();

    for (final Class paramType : params) {
      if (paramType.equals(RequestContext.class)) {
        methodRef.addParam(RequestObjectParam.getInstance());
      } else if (paramType.equals(HttpServletRequest.class)) {
        methodRef.addParam(HttpServletRequestParam.getInstance());
      } else if (paramType.equals(HttpServletResponse.class)) {
        methodRef.addParam(HttpServletResponseParam.getInstance());
      } else if (Model.class.isAssignableFrom(paramType) && action.getModelType() == null) {
        methodRef.addParam(buildModelParam(paramType));
        action.setModelType(paramType);
      } else {
        throw new ApiException(
            "Unexpected action parameter " + paramType.getName() + " for action " + action);
      }
    }
  }
Exemplo n.º 3
0
  private void addValidators(
      ApiAction action,
      RequestValidator requestValidatorAnnotation,
      Class<? extends ParamsValidator>[] validatorTypes)
      throws ApiException {
    final String[] customParams = requestValidatorAnnotation.params();
    for (Class<? extends ParamsValidator> each : validatorTypes) {
      final ParamsValidator validator = getParamsValidator(each, customParams);

      if (validator != null) {
        action.addRequestValidator(validator);
      }
    }
  }
Exemplo n.º 4
0
  private void fillValidatorMetadata(ApiAction action, Method method) throws ApiException {
    RequestValidator requestValidatorAnnotation = method.getAnnotation(RequestValidator.class);
    if (requestValidatorAnnotation != null) {
      final Class<? extends ParamsValidator>[] validatorClasses =
          requestValidatorAnnotation.value();
      if (validatorClasses.length == 0) {
        throw new ApiException("Validator is not specified for " + action);
      }

      addValidators(action, requestValidatorAnnotation, validatorClasses);
    }

    RequestParamsValidator paramsValidatorAnnotation =
        method.getAnnotation(RequestParamsValidator.class);
    if (paramsValidatorAnnotation != null) {
      final String[] required = paramsValidatorAnnotation.required();
      action.addRequestValidator(new SimpleRequestParamsValidator(required));
    }
  }