javax.ws.rs.container.ResourceInfo#getResourceMethod ( )源码实例Demo

下面列出了javax.ws.rs.container.ResourceInfo#getResourceMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bats   文件: AuthDynamicFeature.java
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
  AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());

  // RolesAllowed on the method takes precedence over PermitAll
  RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
  if (ra != null) {
    configuration.register(AuthCheckFilter.INSTANCE);
    return;
  }

  // PermitAll takes precedence over RolesAllowed on the class
  // This avoids putting AuthCheckFilter in the request flow for all path's which
  // are defined under PermitAll annotation. That is requests for "/", "/login", "/mainLogin" and "/spnegoLogin"
  // path's doesn't go through AuthCheckFilter.
  if (am.isAnnotationPresent(PermitAll.class)) {
    // Do nothing.
    return;
  }

  // RolesAllowed on the class takes precedence over PermitAll
  ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
  if (ra != null) {
    configuration.register(AuthCheckFilter.INSTANCE);
  }
}
 
源代码2 项目: azeroth   文件: DefaultFilterDynamicFeature.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    // 获取资源方法
    Method resourceMethod = resourceInfo.getResourceMethod();

    if (resourceMethod != null) {

        // 获取FormatJson注解
        ResponseFormat formatJson = resourceMethod.getAnnotation(ResponseFormat.class);

        if (formatJson == null || formatJson.type().equals(FormatType.JSON)) {
            context.register(DefaultWebFilter.class);
        }

    }
}
 
源代码3 项目: mycore   文件: MCRJerseyDefaultFeature.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Class<?> resourceClass = resourceInfo.getResourceClass();
    Method resourceMethod = resourceInfo.getResourceMethod();
    context.register(MCRCacheFilter.class);
    if (isStaticContent(resourceClass, resourceMethod)) {
        // class or method is annotated with MCRStaticContent
        //   -> do only register session lock filter
        context.register(MCRSessionLockFilter.class);
        return;
    }
    String packageName = resourceClass.getPackage().getName();
    if (getPackages().contains(packageName)) {
        registerTransactionFilter(context);
        registerSessionHookFilter(context);
        registerAccessFilter(context, resourceClass, resourceMethod);
    }
}
 
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
	// 获取资源方法
	Method resourceMethod = resourceInfo.getResourceMethod();

	if (resourceMethod != null) {

		// 获取FormatJson注解
		ResponseFormat formatJson = resourceMethod.getAnnotation(ResponseFormat.class);

		if(formatJson == null || formatJson.type().equals(FormatType.JSON)){
			context.register(DefaultWebFilter.class);
		}

	}
}
 
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
  AnnotatedMethod annotatedMethod       = new AnnotatedMethod(resourceInfo.getResourceMethod());
  Annotation[][]  parameterAnnotations  = annotatedMethod.getParameterAnnotations();
  Class<?>[]      parameterTypes        = annotatedMethod.getParameterTypes      ();
  Type[]          parameterGenericTypes = annotatedMethod.getGenericParameterTypes();

  verifyAuthAnnotations(parameterAnnotations);

  for (int i=0;i<parameterAnnotations.length;i++) {
    for (Annotation annotation : parameterAnnotations[i]) {
      if (annotation instanceof Auth) {
        Type parameterType = parameterTypes[i];

        if (parameterType == Optional.class) {
          parameterType = ((ParameterizedType)parameterGenericTypes[i]).getActualTypeArguments()[0];
          context.register(new WebApplicationExceptionCatchingFilter(getFilterFor(parameterType)));
        } else {
          context.register(getFilterFor(parameterType));
        }
      }
    }
  }
}
 
源代码6 项目: dropwizard-java8   文件: AuthDynamicFeature.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
    final Annotation[][] parameterAnnotations = am.getParameterAnnotations();
    if (am.isAnnotationPresent(RolesAllowed.class) || am.isAnnotationPresent(DenyAll.class) ||
        am.isAnnotationPresent(PermitAll.class)) {
        context.register(authFilter);
    } else {
        for (Annotation[] annotations : parameterAnnotations) {
            for (Annotation annotation : annotations) {
                if (annotation instanceof Auth) {
                    context.register(authFilter);
                    return;
                }
            }
        }
    }
}
 
源代码7 项目: seed   文件: CacheControlFeature.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) {
    CacheControl cacheControl = null;
    Method resourceMethod = resourceInfo.getResourceMethod();
    if (resourceMethod != null) {
        cacheControl = resourceMethod.getAnnotation(CacheControl.class);
    } else {
        Class<?> resourceClass = resourceInfo.getResourceClass();
        if (resourceClass != null) {
            cacheControl = resourceClass.getAnnotation(CacheControl.class);
        }
    }

    if (cacheControl == null) {
        featureContext.register(NO_CACHE_FILTER);
    } else {
        featureContext.register(new CacheResponseFilter(cacheControl.value()));
    }
}
 
源代码8 项目: cxf   文件: BookServer20.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext configurable) {

    configurable.register(new PreMatchDynamicContainerRequestFilter());
    configurable.register(RESPONSE_FILTER);
    Map<Class<?>, Integer> contracts = new HashMap<>();
    contracts.put(ContainerResponseFilter.class, 2);
    configurable.register(new PostMatchDynamicContainerRequestResponseFilter(),
                          contracts);
    Method m = resourceInfo.getResourceMethod();
    if ("echoBookElement".equals(m.getName())) {
        Class<?> paramType = m.getParameterTypes()[0];
        if (paramType == Book.class) {
            configurable.register(new PostMatchDynamicEchoBookFilter(2));
        }
    }
}
 
源代码9 项目: presto   文件: ResourceAccessType.java
private static void verifyNotPrestoResource(ResourceInfo resourceInfo)
{
    Method resourceMethod = resourceInfo.getResourceMethod();
    if (resourceMethod != null && resourceMethod.getDeclaringClass().getPackageName().startsWith("io.prestosql.")) {
        throw new IllegalArgumentException("Presto resource is not annotated with @" + ResourceSecurity.class.getSimpleName() + ": " + resourceInfo.getResourceMethod());
    }
}
 
源代码10 项目: Alpine   文件: AuthorizationFeature.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    if (ENFORCE_AUTHENTICATION && ENFORCE_AUTHORIZATION) {
        final Method method = resourceInfo.getResourceMethod();
        if (method.isAnnotationPresent(PermissionRequired.class)) {
            context.register(AuthorizationFilter.class);
        }
    }
}
 
源代码11 项目: Alpine   文件: AuthenticationFeature.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    if (ENFORCE_AUTHENTICATION) {
        final Method method = resourceInfo.getResourceMethod();
        if (!method.isAnnotationPresent(AuthenticationNotRequired.class)) {
            context.register(AuthenticationFilter.class);
        }
    }
}
 
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Method method = resourceInfo.getResourceMethod();
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (Annotation[] annotations : parameterAnnotations) {
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(Session.class) && !method.getName().startsWith("log")) {
                context.register(NiPingAuthFilter.class);
            }
        }
    }
}
 
源代码13 项目: ratelimitj   文件: RateLimited429EnforcerFeature.java
@Override
public void configure(final ResourceInfo resourceInfo,
                      final FeatureContext context) {

    final AnnotatedMethod method = new AnnotatedMethod(resourceInfo.getResourceMethod());
    final RateLimited rateLimited = method.getAnnotation(RateLimited.class);

    if (null != rateLimited) {
        context.register(RateLimit429EnforcerFilter.class);
    }
}
 
源代码14 项目: mycore   文件: MCRRestFeature.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Class<?> resourceClass = resourceInfo.getResourceClass();
    Method resourceMethod = resourceInfo.getResourceMethod();
    if (requiresTransaction(resourceClass, resourceMethod)) {
        context.register(MCREnableTransactionFilter.class);
    }
    super.configure(resourceInfo, context);
}
 
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext configuration) {
    final Method am = resourceInfo.getResourceMethod();
    try {
        // DenyAll on the method take precedence over RolesAllowed and PermitAll
        if (am.isAnnotationPresent(DenyAll.class)) {
            configuration.register(new RolesAllowedRequestFilter());
            return;
        }

        // RolesAllowed on the method takes precedence over PermitAll
        Optional<Annotation> ra = Arrays.stream(am.getAnnotations())
                .filter(a -> a.annotationType().getName().equals(RolesAllowed.class.getName())).findFirst();
        if (ra.isPresent()) {
            configuration.register(new RolesAllowedRequestFilter(((RolesAllowed) ra.get()).value()));
            return;
        }

        // PermitAll takes precedence over RolesAllowed on the class
        if (am.isAnnotationPresent(PermitAll.class)) {
            // Do nothing.
            return;
        }

        // DenyAll can't be attached to classes

        // RolesAllowed on the class takes precedence over PermitAll
        ra = Arrays.stream(resourceInfo.getResourceClass().getAnnotations())
                .filter(a -> a.annotationType().getName().equals(RolesAllowed.class.getName())).findFirst();
        if (ra.isPresent()) {
            configuration.register(new RolesAllowedRequestFilter(((RolesAllowed) ra.get()).value()));
        }
    } catch (Exception e) {
        logger.error("Error while configuring the roles", e);
    }
}
 
源代码16 项目: datacollector   文件: RolesAnnotationFilter.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
  final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());

  // DenyAll on the method take precedence over RolesAllowed and PermitAll
  if (am.isAnnotationPresent(DenyAll.class)) {
    context.register(new RolesAllowedRequestFilter());
    return;
  }

  // RolesAllowed on the method takes precedence over PermitAll
  RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
  if (ra != null) {
    context.register(new RolesAllowedRequestFilter(ra.value()));
    return;
  }

  // PermitAll takes precedence over RolesAllowed on the class
  if (am.isAnnotationPresent(PermitAll.class)) {
    // Do nothing.
    return;
  }

  // DenyAll can't be attached to classes

  // RolesAllowed on the class takes precedence over PermitAll
  ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
  if (ra != null) {
    context.register(new RolesAllowedRequestFilter(ra.value()));
  }
}
 
源代码17 项目: oxTrust   文件: BaseUmaProtectionService.java
private void addMethodScopes(ResourceInfo resourceInfo, List<String> scopes) {
	Method resourceMethod = resourceInfo.getResourceMethod();
	ProtectedApi methodAnnotation = resourceMethod.getAnnotation(ProtectedApi.class);
	if (methodAnnotation != null) {
		scopes.addAll(Stream.of(methodAnnotation.scopes()).collect(Collectors.toList()));
	}
}
 
源代码18 项目: usergrid   文件: SecuredResourceFilterFactory.java
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) {

    Method am = resourceInfo.getResourceMethod();

    if (logger.isTraceEnabled()) {
        logger.trace("configure {} method {}",
            resourceInfo.getResourceClass().getSimpleName(), resourceInfo.getResourceMethod().getName());
    }

    boolean sysadminLocalhostOnly =
            Boolean.parseBoolean(properties.getProperty("usergrid.sysadmin.localhost.only", "false"));

    if (sysadminLocalhostOnly) {
        // priority = PRIORITY_SUPERUSER forces this to run first
        featureContext.register( SysadminLocalhostFilter.class, PRIORITY_SUPERUSER );
    }

    if ( am.isAnnotationPresent( RequireApplicationAccess.class ) ) {
        featureContext.register( ApplicationFilter.class, PRIORITY_DEFAULT);
    }
    else if ( am.isAnnotationPresent( RequireOrganizationAccess.class ) ) {
        featureContext.register( OrganizationFilter.class, PRIORITY_DEFAULT);
    }
    else if ( am.isAnnotationPresent( RequireSystemAccess.class ) ) {
        featureContext.register( SystemFilter.class, PRIORITY_DEFAULT);
    }
    else if ( am.isAnnotationPresent( RequireAdminUserAccess.class ) ) {
        featureContext.register( SystemFilter.AdminUserFilter.class, PRIORITY_DEFAULT);
    }
    else if ( am.isAnnotationPresent( CheckPermissionsForPath.class ) ) {
        featureContext.register( PathPermissionsFilter.class, PRIORITY_DEFAULT);
    }

}
 
源代码19 项目: ameba   文件: DataViewMessageBodyWriter.java
/** {@inheritDoc} */
@Override
public void writeTo(final Object entity,
                    final Class<?> type,
                    final Type genericType,
                    final Annotation[] annotations,
                    MediaType mediaType,
                    final MultivaluedMap<String, Object> httpHeaders,
                    final OutputStream entityStream) throws IOException, WebApplicationException {
    if (mediaType == null
            || MediaTypes.isWildcard(mediaType)
            || (mediaType.getType().equals(LOW_IE_DEFAULT_REQ_TYPE.getType()) &&
            mediaType.getSubtype().equals(LOW_IE_DEFAULT_REQ_TYPE.getSubtype()))) {
        mediaType = MediaType.TEXT_HTML_TYPE;
    }

    List<String> templates = Lists.newArrayList();
    ResourceInfo resourceInfo = resourceInfoProvider.get();

    // 1. resource method name
    // 2. _protected/ + req path LOWER_UNDERSCORE
    // 3. _protected/ + req raw path
    // 4. req path LOWER_UNDERSCORE
    // 5. req raw path
    // 6. index
    // 7. default view

    if (resourceInfo != null && resourceInfo.getResourceMethod() != null) {
        templates.add(resourceInfo.getResourceMethod().getName());
    }
    // xxx/{a_b}.httl == xxx/{aB}.httl
    String path = getTemplatePath(uriInfoProvider.get());
    String _path = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, path);
    if (!_path.equals(path)) {
        templates.add(Viewables.PROTECTED_DIR_PATH + _path);
    }
    templates.add(Viewables.PROTECTED_DIR_PATH + path);
    if (!_path.equals(path)) {
        templates.add(_path);
    }
    templates.add(path);
    templates.add("index");
    if (!defaultDataViewDisabled) {
        if (entity == null
                || (entity instanceof Collection
                && ((Collection) entity).size() == 0)
                || (entity.getClass().isArray()
                && Array.getLength(entity) == 0)) {
            templates.add(dataViewNull);
        } else if (isItem(entity)) {
            templates.add(dataViewItem);
        } else {
            templates.add(dataViewList);
        }
    }

    Class clazz = null;

    if (resourceInfo != null) {
        clazz = resourceInfo.getResourceClass();
    }
    if (clazz == null) {
        List<Object> res = uriInfoProvider.get().getMatchedResources();
        if (res != null && res.size() > 0) {
            clazz = res.get(0).getClass();
        }
    }
    if (clazz == null) {
        clazz = Ameba.class;
    }
    workersProvider.get().getMessageBodyWriter(
            ImplicitViewable.class,
            ImplicitViewable.class,
            annotations,
            mediaType)

            .writeTo(new ImplicitViewable(templates, entity, clazz),
                    ImplicitViewable.class,
                    ImplicitViewable.class,
                    annotations, mediaType,
                    httpHeaders, entityStream);
}