Java Code Examples for javax.ws.rs.container.ContainerRequestContext#setProperty()
The following examples show how to use
javax.ws.rs.container.ContainerRequestContext#setProperty() .
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: SecurityFilter.java From divide with Apache License 2.0 | 6 votes |
@Override public void filter(ContainerRequestContext request) throws IOException { log.info("Filter(): " + request.getUriInfo().getPath()); String path = request.getUriInfo().getPath(); if(!path.startsWith("/auth/user/data") && !path.startsWith("/auth/user/data/")) if ( path.startsWith("auth") || path.startsWith("/auth") || securityManager.getSafePaths().contains(path) ) { log.info("Auth Skipped : (" + path +")"); return; } UserContext context = authenticate(request); if (context != null) { log.info("Authenticated: " + context.getUser().getEmailAddress()); } else { log.info("Authentication Failed"); } request.setProperty(Session.SESSION_KEY,context); request.setSecurityContext(context); }
Example 2
Source File: AuditFilter.java From onos with Apache License 2.0 | 6 votes |
@Override public void filter(ContainerRequestContext requestContext) throws IOException { if (auditService() != null) { String requestBody = (requestContext.hasEntity() ? (readTreeFromStream(mapper, requestContext.getEntityStream()).toString()) : ""); requestContext.setProperty("requestBody", requestBody); // FIXME: audit message should be better structured requestContext.setProperty("auditMessage", "{\"Path" + logCompSeperator + requestContext.getUriInfo().getPath() + separator + "Method" + logCompSeperator + requestContext.getMethod() + separator + (requestContext.getMethod().equals("PUT") ? // FIXME: is there really a need to differentiate based on method? ("Path_Parameters" + logCompSeperator + requestContext.getUriInfo().getPathParameters().toString() + separator + "Query_Parameters" + logCompSeperator + requestContext.getUriInfo().getQueryParameters().toString() + separator + "Request_Body" + logCompSeperator + requestBody) : "")); requestContext.setEntityStream(IOUtils.toInputStream(requestBody)); } }
Example 3
Source File: BookServer20.java From cxf with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext context) throws IOException { if (!"true".equals(context.getProperty("FirstPrematchingFilter"))) { throw new RuntimeException(); } context.setProperty("DynamicPrematchingFilter", "true"); }
Example 4
Source File: BraveProvider.java From cxf with Apache License 2.0 | 5 votes |
@Override public void filter(final ContainerRequestContext requestContext) throws IOException { final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getHeaders(), requestContext.getUriInfo().getRequestUri(), requestContext.getMethod()); if (holder != null) { requestContext.setProperty(TRACE_SPAN, holder); } }
Example 5
Source File: RpcServerFilter.java From nuls with MIT License | 5 votes |
@Override public void filter(ContainerRequestContext requestContext) throws IOException { if (!whiteSheetVerifier(request)) { throw new NulsRuntimeException(KernelErrorCode.REQUEST_DENIED); } requestContext.setProperty("start", System.currentTimeMillis()); }
Example 6
Source File: SessionManager.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public SessionInfo get(ContainerRequestContext requestContext) { SessionInfoImpl session = (SessionInfoImpl) requestContext.getProperty(PROPERTY_SESSION); if (session == null) { String sessionId = sessionId(requestContext); session = new SessionInfoImpl(sessionId, sessionRepository); requestContext.setProperty(PROPERTY_SESSION, session); } return session; }
Example 7
Source File: BookServer.java From cxf with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext requestContext) throws IOException { if (requestContext.getUriInfo().getPath().endsWith("/blockAndThrowException")) { requestContext.setProperty("blocked", Boolean.TRUE); requestContext.abortWith(Response.ok().build()); } }
Example 8
Source File: TracingFilter.java From hadoop-ozone with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext requestContext) { finishAndCloseActiveSpan(); Span span = GlobalTracer.get().buildSpan( resourceInfo.getResourceClass().getSimpleName() + "." + resourceInfo.getResourceMethod().getName()).start(); Scope scope = GlobalTracer.get().activateSpan(span); requestContext.setProperty(TRACING_SCOPE, scope); requestContext.setProperty(TRACING_SPAN, span); }
Example 9
Source File: EmptyPayloadFilter.java From hawkular-metrics with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext requestContext) throws IOException { if (HttpMethod.POST.equals(requestContext.getMethod()) || HttpMethod.PUT.equals(requestContext.getMethod())) { requestContext.setProperty(EMPTY_PAYLOAD, Boolean.TRUE); } }
Example 10
Source File: BaseMethodStatsInterceptor.java From datawave with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { // Copy the headers because they get committed before the message body writer context is // called, and when they are committed, the contents of the map is modified. ResponseMethodStats stats = new ResponseMethodStats(); MultivaluedTreeMap.addAll(response.getHeaders(), stats.responseHeaders); stats.statusCode = response.getStatus(); request.setProperty(RESPONSE_STATS_NAME, stats); }
Example 11
Source File: AuditFilter.java From onos with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException { AuditService auditService = auditService(); if (auditService != null) { containerRequestContext.setProperty("auditMessage", containerRequestContext.getProperty("auditMessage") + separator + "Status" + logCompSeperator + containerResponseContext.getStatusInfo().toString() + "\"}"); // FIXME: Audit record should indicate who did it, not just what was done and when String user = containerRequestContext.getSecurityContext().getUserPrincipal().getName(); String action = containerRequestContext.getProperty("auditMessage").toString(); auditService.logUserAction(user, action); } }
Example 12
Source File: SwaggerToOpenApiConversionFilter.java From cxf with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext reqCtx) throws IOException { String path = reqCtx.getUriInfo().getPath(); if (path.endsWith(openApiJsonPath)) { reqCtx.setRequestUri(URI.create(SWAGGER_PATH)); reqCtx.setProperty(OPEN_API_PROPERTY, Boolean.TRUE); } }
Example 13
Source File: RequestProperties.java From servicetalk with Apache License 2.0 | 5 votes |
/** * Initialize all request properties. * * @param entityStream the {@link BufferPublisherInputStream} associated with the request. * @param reqCtx the {@link ContainerRequestContext} for the request */ public static void initRequestProperties(final BufferPublisherInputStream entityStream, final ContainerRequestContext reqCtx) { reqCtx.setProperty(REQUEST_BUFFER_PUBLISHER_IS, requireNonNull(entityStream)); reqCtx.setProperty(REQUEST_CANCELLABLE, new DelayedCancellable()); reqCtx.setProperty(RESPONSE_BUFFER_PUBLISHER, null); reqCtx.setProperty(RESPONSE_EXEC_STRATEGY, null); }
Example 14
Source File: MetricsFilter.java From keycloak-metrics-spi with Apache License 2.0 | 4 votes |
@Override public void filter(ContainerRequestContext req) { req.setProperty(METRICS_REQUEST_TIMESTAMP, System.currentTimeMillis()); }
Example 15
Source File: UsernameTestFilter.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { containerRequestContext.setProperty(AuthenticationProps.USERNAME, USERNAME); }
Example 16
Source File: EndpointMetricsFilter.java From syndesis with Apache License 2.0 | 4 votes |
/** * Called before the resource method. */ @Override public void filter(ContainerRequestContext requestContext) throws IOException { Sample sample = Timer.start(registry); requestContext.setProperty(TIMING_SAMPLE, sample); }
Example 17
Source File: EndpointMetricsFilter.java From syndesis with Apache License 2.0 | 4 votes |
/** * Called before the resource method. */ @Override public void filter(ContainerRequestContext requestContext) throws IOException { Sample sample = Timer.start(registry); requestContext.setProperty(TIMING_SAMPLE, sample); }
Example 18
Source File: RequestScopedMetricsIntegrationTest.java From rest-utils with Apache License 2.0 | 4 votes |
@Override public void filter(ContainerRequestContext context) { Map<String, String> maps = new HashMap<>(); maps.put("runtime_tag-1", "runtime_value-1"); context.setProperty(MetricsResourceMethodApplicationListener.REQUEST_TAGS_PROP_KEY, maps); }
Example 19
Source File: FedizRedirectBindingFilter.java From cxf-fediz with Apache License 2.0 | 4 votes |
private void processSignInRequest(ContainerRequestContext context, FedizContext fedConfig, Message m, MultivaluedMap<String, String> params) { String responseToken = getResponseToken(fedConfig, params); String state = getState(fedConfig, params); if (responseToken == null) { LOG.debug("SignIn request must contain a response token from the IdP"); throw ExceptionUtils.toBadRequestException(null, null); } else { // processSignInRequest LOG.debug("Process SignIn request"); LOG.debug("token=\n{}", responseToken); FedizResponse wfRes = validateSignInRequest(fedConfig, params, responseToken, state); // Validate AudienceRestriction List<String> audienceURIs = fedConfig.getAudienceUris(); HttpServletRequest request = messageContext.getHttpServletRequest(); validateAudienceRestrictions(wfRes, audienceURIs, request); // Set the security context String securityContextKey = UUID.randomUUID().toString(); long currentTime = System.currentTimeMillis(); Instant notOnOrAfter = wfRes.getTokenExpires(); long expiresAt = 0; if (notOnOrAfter != null) { expiresAt = notOnOrAfter.toEpochMilli(); } else { expiresAt = currentTime + getStateTimeToLive(); } String webAppDomain = getWebAppDomain(); String token = DOM2Writer.nodeToString(wfRes.getToken()); // Add "Authenticated" role List<String> roles = wfRes.getRoles(); if (roles == null || roles.isEmpty()) { roles = Collections.singletonList("Authenticated"); } else if (fedConfig.isAddAuthenticatedRole()) { roles = new ArrayList<>(roles); roles.add("Authenticated"); } String webAppContext = getWebAppContext(m); ResponseState responseState = new ResponseState(token, state, webAppContext, webAppDomain, currentTime, expiresAt); responseState.setClaims(wfRes.getClaims()); responseState.setRoles(roles); responseState.setIssuer(wfRes.getIssuer()); responseState.setSubject(wfRes.getUsername()); getStateManager().setResponseState(securityContextKey, responseState); long stateTimeToLive = getStateTimeToLive(); String contextCookie = CookieUtils.createCookie(SECURITY_CONTEXT_TOKEN, securityContextKey, webAppContext, webAppDomain, stateTimeToLive); // Redirect with cookie set if (isRedirectOnInitialSignIn()) { ResponseBuilder response = Response.seeOther(new UriInfoImpl(m).getAbsolutePath()); response.header(HttpHeaders.SET_COOKIE, contextCookie); context.abortWith(response.build()); } else { try { setSecurityContext(responseState, m, wfRes.getToken()); context.setProperty(SECURITY_CONTEXT_TOKEN, contextCookie); } catch (Exception ex) { reportError("INVALID_RESPONSE_STATE"); } } } }
Example 20
Source File: MCREnableTransactionFilter.java From mycore with GNU General Public License v3.0 | 4 votes |
@Override public void filter(ContainerRequestContext requestContext) throws IOException { requestContext.setProperty(MCRTransactionFilter.PROP_REQUIRE_TRANSACTION, true); }