Java Code Examples for javax.ws.rs.core.Response#seeOther()

The following examples show how to use javax.ws.rs.core.Response#seeOther() . 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: TestClass19.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
@javax.ws.rs.GET public Response method() {
    Response.ResponseBuilder responseBuilder = Response.accepted();
    responseBuilder = Response.created(URI.create(""));
    responseBuilder = Response.noContent();
    responseBuilder = Response.notAcceptable(new LinkedList<>());
    responseBuilder = Response.notModified();
    responseBuilder = Response.ok();
    responseBuilder = Response.ok(1L, new Variant(MediaType.TEXT_PLAIN_TYPE, Locale.ENGLISH, "UTF-8"));
    responseBuilder = Response.seeOther(URI.create(""));
    responseBuilder = Response.serverError();
    responseBuilder = Response.temporaryRedirect(URI.create(""));

    return responseBuilder.build();
}
 
Example 2
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 3
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 4
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 5
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 6
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 7
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 8
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 9
Source File: BaseController.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
private Response handleRedirectException(UriInfo uriInfo, HttpHeaders httpHeaders, String methodName, RedirectException e, String transactionId) {
	this.log.error("Esecuzione del metodo ["+methodName+"] si e' conclusa con un errore: " + e.getMessage() + ", redirect verso la url: " + e.getLocation());
	ResponseBuilder responseBuilder = Response.seeOther(e.getURILocation());
	this.handleEventoOk(responseBuilder, transactionId);
	if(transactionId != null)
		return responseBuilder.header(this.transactionIdHeaderName, transactionId).build();
	else
		return responseBuilder.build();
}
 
Example 10
Source File: FedizRedirectBindingFilter.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
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 11
Source File: FedizRedirectBindingFilter.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
private void processSignInRequired(ContainerRequestContext context, FedizContext fedConfig) {
 // Unauthenticated -> redirect
    FedizProcessor processor =
        FedizProcessorFactory.newFedizProcessor(fedConfig.getProtocol());

    HttpServletRequest request = messageContext.getHttpServletRequest();
    try {
        RedirectionResponse redirectionResponse =
            processor.createSignInRequest(request, fedConfig);
        String redirectURL = redirectionResponse.getRedirectionURL();
        if (redirectURL != null) {
            ResponseBuilder response = Response.seeOther(new URI(redirectURL));
            Map<String, String> headers = redirectionResponse.getHeaders();
            if (!headers.isEmpty()) {
                for (Entry<String, String> entry : headers.entrySet()) {
                    response.header(entry.getKey(), entry.getValue());
                }
            }

            // Save the RequestState
            RequestState requestState = redirectionResponse.getRequestState();
            if (requestState != null && requestState.getState() != null) {
                getStateManager().setRequestState(requestState.getState(), requestState);

                String contextCookie =
                    CookieUtils.createCookie(SECURITY_CONTEXT_STATE,
                                             requestState.getState(),
                                             request.getRequestURI(),
                                             getWebAppDomain(),
                                             getStateTimeToLive());
                response.header(HttpHeaders.SET_COOKIE, contextCookie);
            }

            context.abortWith(response.build());
        } else {
            LOG.warn("Failed to create SignInRequest.");
            throw ExceptionUtils.toInternalServerErrorException(null, null);
        }
    } catch (Exception ex) {
        LOG.debug(ex.getMessage(), ex);
        throw ExceptionUtils.toInternalServerErrorException(ex, null);
    }

}
 
Example 12
Source File: FedizRedirectBindingFilter.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
private boolean isLogoutRequest(ContainerRequestContext context, FedizContext fedConfig,
                                Message message, MultivaluedMap<String, String> params) {

    boolean signout = false;
    String logoutUrl = fedConfig.getLogoutURL();
    if (params != null && fedConfig.getProtocol() instanceof FederationProtocol
        && FederationConstants.ACTION_SIGNOUT.equals(
            params.getFirst(FederationConstants.PARAM_ACTION))) {
        signout = true;
    } else if (logoutUrl != null && !logoutUrl.isEmpty()) {
        String requestPath = "/" + context.getUriInfo().getPath();
        if (requestPath.equals(logoutUrl) || requestPath.equals(logoutUrl + "/")) {
            signout = true;
        }
    }

    if (signout) {
        cleanupContext(message);

        try {
            FedizProcessor processor =
                FedizProcessorFactory.newFedizProcessor(fedConfig.getProtocol());

            HttpServletRequest request = messageContext.getHttpServletRequest();
            RedirectionResponse redirectionResponse =
                processor.createSignOutRequest(request, null, fedConfig); //TODO
            String redirectURL = redirectionResponse.getRedirectionURL();
            if (redirectURL != null) {
                ResponseBuilder response = Response.seeOther(new URI(redirectURL));
                Map<String, String> headers = redirectionResponse.getHeaders();
                if (!headers.isEmpty()) {
                    for (Entry<String, String> entry : headers.entrySet()) {
                        response.header(entry.getKey(), entry.getValue());
                    }
                }

                context.abortWith(response.build());

                return true;
            }
        } catch (Exception ex) {
            LOG.debug(ex.getMessage(), ex);
            throw ExceptionUtils.toInternalServerErrorException(ex, null);
        }
    }

    return false;
}