javax.ws.rs.Priorities Java Examples
The following examples show how to use
javax.ws.rs.Priorities.
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: AuthorizationFilterFeature.java From shiro-jersey with Apache License 2.0 | 6 votes |
@Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { List<Annotation> authzSpecs = new ArrayList<>(); for (Class<? extends Annotation> annotationClass : shiroAnnotations) { // XXX What is the performance of getAnnotation vs getAnnotations? Annotation classAuthzSpec = resourceInfo.getResourceClass().getAnnotation(annotationClass); Annotation methodAuthzSpec = resourceInfo.getResourceMethod().getAnnotation(annotationClass); if (classAuthzSpec != null) authzSpecs.add(classAuthzSpec); if (methodAuthzSpec != null) authzSpecs.add(methodAuthzSpec); } if (!authzSpecs.isEmpty()) { context.register(new AuthorizationFilter(authzSpecs), Priorities.AUTHORIZATION); } }
Example #2
Source File: AuthorizationFilterFeature.java From shiro-jersey with Apache License 2.0 | 6 votes |
@Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { List<Annotation> authzSpecs = new ArrayList<>(); for (Class<? extends Annotation> annotationClass : shiroAnnotations) { // XXX What is the performance of getAnnotation vs getAnnotations? Annotation classAuthzSpec = resourceInfo.getResourceClass().getAnnotation(annotationClass); Annotation methodAuthzSpec = resourceInfo.getResourceMethod().getAnnotation(annotationClass); if (classAuthzSpec != null) authzSpecs.add(classAuthzSpec); if (methodAuthzSpec != null) authzSpecs.add(methodAuthzSpec); } if (!authzSpecs.isEmpty()) { context.register(new AuthorizationFilter(authzSpecs), Priorities.AUTHORIZATION); } }
Example #3
Source File: RestClientBean.java From cxf with Apache License 2.0 | 6 votes |
@Override public Object create(CreationalContext<Object> creationalContext) { CxfTypeSafeClientBuilder builder = new CxfTypeSafeClientBuilder(); String baseUri = getBaseUri(); builder = (CxfTypeSafeClientBuilder) builder.baseUri(URI.create(baseUri)); List<Class<?>> providers = getConfiguredProviders(); Map<Class<?>, Integer> providerPriorities = getConfiguredProviderPriorities(providers); for (Class<?> providerClass : providers) { builder = (CxfTypeSafeClientBuilder) builder.register(providerClass, providerPriorities.getOrDefault(providerClass, Priorities.USER)); } setTimeouts(builder); setSSLConfig(builder); setFollowRedirects(builder); setProxyAddress(builder); setQueryParamStyle(builder); Object clientInstance = builder.build(clientInterface); builders.put(clientInstance, builder); return clientInstance; }
Example #4
Source File: SysFilteringFeature.java From ameba with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public boolean configure(FeatureContext context) { Configuration configuration = context.getConfiguration(); if (!configuration.isRegistered(UriConnegFilter.class)) { context.register(UriConnegFilter.class, Priorities.AUTHENTICATION - 100); } if (!context.getConfiguration().isRegistered(DownloadEntityFilter.class)) { context.register(DownloadEntityFilter.class); } if (!configuration.isRegistered(LoadBalancerRequestFilter.class)) { context.register(LoadBalancerRequestFilter.class); } return true; }
Example #5
Source File: ParsecValidationAutoDiscoverable.java From parsec-libraries with Apache License 2.0 | 6 votes |
@Override public void configure(FeatureContext context) { final int priorityInc = 3000; // Jersey MOXY provider have higher priority(7000), so we need set higher than it int priority = Priorities.USER + priorityInc; Configuration config = context.getConfiguration(); if (!config.isRegistered(ParsecValidationExceptionMapper.class)) { context.register(ParsecValidationExceptionMapper.class, priority); } if (!config.isRegistered(ValidationConfigurationContextResolver.class)) { context.register(ValidationConfigurationContextResolver.class, priority); } if (!config.isRegistered(ParsecMoxyFeature.class)) { context.register(ParsecMoxyFeature.class, priority); } if (!config.isRegistered(JaxbExceptionMapper.class)) { context.register(JaxbExceptionMapper.class, priority); } }
Example #6
Source File: ParsecMoxyFeature.java From parsec-libraries with Apache License 2.0 | 6 votes |
@Override public boolean configure(FeatureContext context) { final Configuration config = context.getConfiguration(); if (CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), CommonProperties.MOXY_JSON_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) { return false; } final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class); // Other JSON providers registered. if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { return false; } // Disable other JSON providers. context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE); final int workerPriority = Priorities.USER + 3000; context.register(ParsecMoxyProvider.class, workerPriority); return true; }
Example #7
Source File: InstrumentedRestApplication.java From java-jaxrs with Apache License 2.0 | 5 votes |
@Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { context.register(new ContainerRequestFilter() { @Override public void filter(ContainerRequestContext requestContext) throws IOException { if (requestContext.getUriInfo().getPath().endsWith("filtered")) { throw new ForbiddenException(); } } }, Priorities.AUTHORIZATION); }
Example #8
Source File: ClientTracingFeature.java From java-jaxrs with Apache License 2.0 | 5 votes |
public Builder(Tracer tracer) { this.tracer = tracer; this.spanDecorators = Collections.singletonList(ClientSpanDecorator.STANDARD_TAGS); this.serializationSpanDecorators = Arrays.asList(InterceptorSpanDecorator.STANDARD_TAGS); // by default do not use Priorities.AUTHENTICATION due to security concerns this.priority = Priorities.HEADER_DECORATOR; this.serializationPriority = Priorities.ENTITY_CODER; this.traceSerialization = true; }
Example #9
Source File: ServerTracingDynamicFeature.java From java-jaxrs with Apache License 2.0 | 5 votes |
public Builder(Tracer tracer) { this.tracer = tracer; this.spanDecorators = Collections.singletonList(ServerSpanDecorator.STANDARD_TAGS); this.serializationSpanDecorators = Collections.singletonList(InterceptorSpanDecorator.STANDARD_TAGS); // by default do not use Priorities.AUTHENTICATION due to security concerns this.priority = Priorities.HEADER_DECORATOR; this.serializationPriority = Priorities.ENTITY_CODER; this.allTraced = true; this.operationNameBuilder = WildcardOperationName.newBuilder(); this.traceSerialization = true; this.joinExistingActiveSpan = false; }
Example #10
Source File: AuthorizationFilterFeature.java From redpipe with Apache License 2.0 | 5 votes |
@Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { List<Annotation> authzSpecs = new ArrayList<>(); boolean canRedirect = true; for (Class<? extends Annotation> annotationClass : filterAnnotations) { // XXX What is the performance of getAnnotation vs getAnnotations? Annotation classAuthzSpec = resourceInfo.getResourceClass().getAnnotation(annotationClass); Annotation methodAuthzSpec = resourceInfo.getResourceMethod().getAnnotation(annotationClass); if (classAuthzSpec != null) authzSpecs.add(classAuthzSpec); if (methodAuthzSpec != null) authzSpecs.add(methodAuthzSpec); if(resourceInfo.getResourceClass().isAnnotationPresent(NoAuthRedirect.class) || resourceInfo.getResourceMethod().isAnnotationPresent(NoAuthRedirect.class)) canRedirect = false; if(resourceInfo.getResourceClass().isAnnotationPresent(NoAuthFilter.class) || resourceInfo.getResourceMethod().isAnnotationPresent(NoAuthFilter.class)) return; } if (!authzSpecs.isEmpty()) { if(canRedirect) context.register(new LoginRedirectFilter(), Priorities.AUTHENTICATION + 1); context.register(new AuthorizationFilter(authzSpecs), Priorities.AUTHORIZATION); } }
Example #11
Source File: AnnotationUtils.java From cxf with Apache License 2.0 | 5 votes |
public static int getBindingPriority(Class<?> providerCls) { if (PRIORITY_API == null) { return Priorities.USER; } Annotation b = getClassAnnotation(providerCls, PRIORITY_API); try { return b == null ? Priorities.USER : Integer.class.cast(PRIORITY_VALUE.invoke(b)); } catch (final IllegalAccessException | InvocationTargetException e) { return Priorities.USER; } }
Example #12
Source File: ServerProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private Integer getPriority(Collection<?> list, Class<?> cls, Class<?> filterClass) { Collection<ProviderInfo<?>> list2 = CastUtils.cast(list); for (ProviderInfo<?> p : list2) { if (p instanceof FilterProviderInfo) { Class<?> pClass = ClassHelper.getRealClass(p.getBus(), p.getProvider()); if (cls.isAssignableFrom(pClass)) { return ((FilterProviderInfo<?>)p).getPriority(filterClass); } } } return Priorities.USER; }
Example #13
Source File: TestMediaTypeFilter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Test public void testAnnotations() { // Check that the class is correctly annotated assertNotNull("@PreMatching annotation is required to modify headers", MediaTypeFilter.class.getAnnotation(PreMatching.class)); Priority priority = MediaTypeFilter.class.getAnnotation(Priority.class); assertNotNull("@Priority annotation is required to modify headers", priority); assertTrue("priority should be higher than HEADER_DECORATOR", priority.value() <= Priorities.HEADER_DECORATOR); }
Example #14
Source File: RestClientBean.java From cxf with Apache License 2.0 | 5 votes |
Map<Class<?>, Integer> getConfiguredProviderPriorities(List<Class<?>> providers) { Map<Class<?>, Integer> map = new HashMap<>(); for (Class<?> providerClass : providers) { String propertyFormat = "%s" + String.format(REST_PROVIDERS_PRIORITY_FORMAT, providerClass.getName()); Integer priority = ConfigFacade.getOptionalValue(propertyFormat, clientInterface, Integer.class) .orElse(getPriorityFromClass(providerClass, Priorities.USER)); map.put(providerClass, priority); } return map; }
Example #15
Source File: RestClientCdiTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testProvidersRegisteredViaMPConfigProperty() throws Exception { Map<String, String> configValues = new HashMap<>(); configValues.put(InterfaceWithoutProvidersDefined.class.getName() + "/mp-rest/providers", HighPriorityClientReqFilter.class.getName() + "," + LowPriorityClientReqFilter.class.getName() + "," + InvokedMethodClientRequestFilter.class.getName()); configValues.put(InterfaceWithoutProvidersDefined.class.getName() + "/mp-rest/providers/" + LowPriorityClientReqFilter.class.getName() + "/priority", "3"); ((MockConfigProviderResolver)ConfigProviderResolver.instance()).setConfigValues(configValues); IMocksControl control = EasyMock.createNiceControl(); BeanManager mockedBeanMgr = control.createMock(BeanManager.class); mockedBeanMgr.isScope(Path.class); EasyMock.expectLastCall().andReturn(false); mockedBeanMgr.isScope(Produces.class); EasyMock.expectLastCall().andReturn(false); mockedBeanMgr.isScope(Consumes.class); EasyMock.expectLastCall().andReturn(false); control.replay(); RestClientBean bean = new RestClientBean(InterfaceWithoutProvidersDefined.class, mockedBeanMgr); List<Class<?>> registeredProviders = bean.getConfiguredProviders(); assertEquals(3, registeredProviders.size()); assertTrue(registeredProviders.contains(HighPriorityClientReqFilter.class)); assertTrue(registeredProviders.contains(LowPriorityClientReqFilter.class)); assertTrue(registeredProviders.contains(InvokedMethodClientRequestFilter.class)); Map<Class<?>, Integer> priorities = bean.getConfiguredProviderPriorities(registeredProviders); assertEquals(3, priorities.size()); assertEquals(3, (int) priorities.get(LowPriorityClientReqFilter.class)); assertEquals(10, (int) priorities.get(HighPriorityClientReqFilter.class)); assertEquals(Priorities.USER, (int) priorities.get(InvokedMethodClientRequestFilter.class)); control.verify(); }
Example #16
Source File: ShiroAuthorizationFeature.java From aries-jax-rs-whiteboard with Apache License 2.0 | 4 votes |
@Override public boolean configure(FeatureContext fc) { Configuration configuration = fc.getConfiguration(); if(_LOG.isInfoEnabled()) { @SuppressWarnings("unchecked") Map<String, Object> applicationProps = (Map<String, Object>) configuration.getProperty(JAX_RS_APPLICATION_SERVICE_PROPERTIES); _LOG.info("Registering the Shiro Authorization feature with application {}", applicationProps.getOrDefault(JAX_RS_NAME, "<No Name found in application configuration>")); } Map<Class<?>, Integer> contracts = configuration.getContracts(ExceptionMapper.class); if(contracts.isEmpty()) { _LOG.debug("Registering the Shiro ExceptionMapper"); // Only register the ExceptionMapper if it isn't already registered fc.register(ExceptionMapper.class, AUTHORIZATION); } else if(AUTHORIZATION < contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER)) { _LOG.debug("Updating the priority of the Shiro ExceptionMapper from {} to {}", contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER), AUTHORIZATION); // Update the priority if it's registered too low contracts.put(javax.ws.rs.ext.ExceptionMapper.class, AUTHORIZATION); } contracts = configuration.getContracts(SubjectPrincipalRequestFilter.class); if(contracts.isEmpty()) { _LOG.debug("Registering the Shiro SubjectPrincipalRequestFilter"); // Only register the SubjectPrincipalRequestFilter if it isn't already registered fc.register(SubjectPrincipalRequestFilter.class, AUTHORIZATION); } else if(AUTHORIZATION < contracts.getOrDefault(ContainerRequestFilter.class, USER)) { _LOG.debug("Updating the priority of the Shiro SubjectPrincipalRequestFilter from {} to {}", contracts.getOrDefault(ContainerRequestFilter.class, USER), AUTHORIZATION); // Update the priority if it's registered too low contracts.put(ContainerRequestFilter.class, AUTHORIZATION); } _LOG.debug("Registering the Shiro ShiroAnnotationFilterFeature"); fc.register(ShiroAnnotationFilterFeature.class, Priorities.AUTHORIZATION); return true; }
Example #17
Source File: ConfigurableImpl.java From cxf with Apache License 2.0 | 4 votes |
@Override public C register(Object provider, Class<?>... contracts) { return doRegister(provider, Priorities.USER, contracts); }
Example #18
Source File: ConfigurableImpl.java From cxf with Apache License 2.0 | 4 votes |
@Override public C register(Class<?> providerClass, Class<?>... contracts) { return doRegister(providerClass, Priorities.USER, contracts); }
Example #19
Source File: TestResponseExceptionMapperOverridePriority.java From microprofile-rest-client with Apache License 2.0 | 4 votes |
@Override public int getPriority() { return Priorities.USER + 1; }