Java Code Examples for javax.ws.rs.container.ResourceInfo#getResourceMethod()

The following examples show how to use javax.ws.rs.container.ResourceInfo#getResourceMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthDynamicFeature.java    From Bats with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 2
Source File: BookServer20.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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));
        }
    }
}
 
Example 3
Source File: CacheControlFeature.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
@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()));
    }
}
 
Example 4
Source File: AuthDynamicFeature.java    From dropwizard-java8 with Apache License 2.0 6 votes vote down vote up
@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;
                }
            }
        }
    }
}
 
Example 5
Source File: DefaultFilterDynamicFeature.java    From azeroth with Apache License 2.0 6 votes vote down vote up
@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);
        }

    }
}
 
Example 6
Source File: AuthDynamicFeature.java    From dropwizard-simpleauth with Apache License 2.0 6 votes vote down vote up
@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));
        }
      }
    }
  }
}
 
Example 7
Source File: MCRJerseyDefaultFeature.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: DefaultFilterDynamicFeature.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
@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);
		}

	}
}
 
Example 9
Source File: SecuredResourceFilterFactory.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@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);
    }

}
 
Example 10
Source File: BaseUmaProtectionService.java    From oxTrust with MIT License 5 votes vote down vote up
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()));
	}
}
 
Example 11
Source File: RolesAnnotationFilter.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@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()));
  }
}
 
Example 12
Source File: RolesAllowedDynamicFeatureImpl.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 13
Source File: MCRRestFeature.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 14
Source File: RateLimited429EnforcerFeature.java    From ratelimitj with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 15
Source File: AuthFilterDynamicBinding.java    From SAPNetworkMonitor with GNU General Public License v3.0 5 votes vote down vote up
@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);
            }
        }
    }
}
 
Example 16
Source File: AuthenticationFeature.java    From Alpine with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 17
Source File: AuthorizationFeature.java    From Alpine with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 18
Source File: ResourceAccessType.java    From presto with Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example 19
Source File: DataViewMessageBodyWriter.java    From ameba with MIT License 4 votes vote down vote up
/** {@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);
}