Search in sources :

Example 11 with DefaultRequest

use of com.okta.commons.http.DefaultRequest in project okta-sdk-java by okta.

the class DefaultDataStore method doDelete.

private void doDelete(String resourceHref, Class resourceClass, QueryString qs, HttpHeaders httpHeaders) {
    Assert.hasText(resourceHref, "This resource does not have an href value, therefore it cannot be deleted.");
    // if this URL is a partial, then we MUST add the baseUrl
    final CanonicalUri uri = canonicalize(resourceHref, qs);
    FilterChain chain = new DefaultFilterChain(this.filters, request -> {
        Request deleteRequest = new DefaultRequest(HttpMethod.DELETE, uri.getAbsolutePath(), uri.getQuery(), httpHeaders);
        execute(deleteRequest);
        // delete requests have HTTP 204 (no content), so just create an empty setBody for the result:
        return new DefaultResourceDataResult(request.getAction(), request.getUri(), request.getResourceClass(), new HashMap<>());
    });
    final CanonicalUri resourceUri = canonicalize(resourceHref, null);
    ResourceDataRequest request = new DefaultResourceDataRequest(ResourceAction.DELETE, resourceUri, resourceClass, new HashMap<>());
    chain.filter(request);
}
Also used : DefaultCanonicalUri(com.okta.sdk.impl.http.support.DefaultCanonicalUri) CanonicalUri(com.okta.sdk.impl.http.CanonicalUri) DefaultRequest(com.okta.commons.http.DefaultRequest) Request(com.okta.commons.http.Request) DefaultRequest(com.okta.commons.http.DefaultRequest)

Example 12 with DefaultRequest

use of com.okta.commons.http.DefaultRequest in project okta-idx-java by okta.

the class BaseIDXClient method enrollUpdateUserProfile.

@Override
public IDXResponse enrollUpdateUserProfile(EnrollUserProfileUpdateRequest enrollUserProfileUpdateRequest, String href) throws ProcessingException {
    IDXResponse idxResponse;
    try {
        Request request = new DefaultRequest(HttpMethod.POST, href, null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(enrollUserProfileUpdateRequest)), -1L);
        Response response = requestExecutor.executeRequest(request);
        if (response.getHttpStatus() != 200) {
            handleErrorResponse(request, response);
        }
        JsonNode responseJsonNode = objectMapper.readTree(response.getBody());
        idxResponse = objectMapper.convertValue(responseJsonNode, IDXResponse.class);
    } catch (IOException | HttpException e) {
        throw new ProcessingException(e);
    }
    return idxResponse;
}
Also used : ErrorResponse(com.okta.idx.sdk.api.response.ErrorResponse) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) InteractResponse(com.okta.idx.sdk.api.response.InteractResponse) Response(com.okta.commons.http.Response) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) DefaultRequest(com.okta.commons.http.DefaultRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SkipAuthenticatorEnrollmentRequest(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest) Request(com.okta.commons.http.Request) IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) EnrollUserProfileUpdateRequest(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest) DefaultRequest(com.okta.commons.http.DefaultRequest) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest) CancelRequest(com.okta.idx.sdk.api.request.CancelRequest) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) IntrospectRequest(com.okta.idx.sdk.api.request.IntrospectRequest) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) PollRequest(com.okta.idx.sdk.api.request.PollRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpException(com.okta.commons.http.HttpException) IOException(java.io.IOException) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException)

Example 13 with DefaultRequest

use of com.okta.commons.http.DefaultRequest in project okta-idx-java by okta.

the class BaseIDXClient method skip.

@Override
public IDXResponse skip(SkipAuthenticatorEnrollmentRequest skipAuthenticatorEnrollmentRequest, String href) throws ProcessingException {
    IDXResponse idxResponse;
    try {
        Request request = new DefaultRequest(HttpMethod.POST, href, null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(skipAuthenticatorEnrollmentRequest)), -1L);
        Response response = requestExecutor.executeRequest(request);
        if (response.getHttpStatus() != 200) {
            handleErrorResponse(request, response);
        }
        JsonNode responseJsonNode = objectMapper.readTree(response.getBody());
        idxResponse = objectMapper.convertValue(responseJsonNode, IDXResponse.class);
    } catch (IOException | HttpException e) {
        throw new ProcessingException(e);
    }
    return idxResponse;
}
Also used : ErrorResponse(com.okta.idx.sdk.api.response.ErrorResponse) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) InteractResponse(com.okta.idx.sdk.api.response.InteractResponse) Response(com.okta.commons.http.Response) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) DefaultRequest(com.okta.commons.http.DefaultRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SkipAuthenticatorEnrollmentRequest(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest) Request(com.okta.commons.http.Request) IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) EnrollUserProfileUpdateRequest(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest) DefaultRequest(com.okta.commons.http.DefaultRequest) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest) CancelRequest(com.okta.idx.sdk.api.request.CancelRequest) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) IntrospectRequest(com.okta.idx.sdk.api.request.IntrospectRequest) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) PollRequest(com.okta.idx.sdk.api.request.PollRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpException(com.okta.commons.http.HttpException) IOException(java.io.IOException) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException)

Example 14 with DefaultRequest

use of com.okta.commons.http.DefaultRequest in project okta-idx-java by okta.

the class BaseIDXClient method verifyEmailToken.

@Override
public Response verifyEmailToken(String token) throws ProcessingException {
    StringBuilder urlParameter = new StringBuilder();
    urlParameter.append("token=").append(token);
    try {
        Request request = new DefaultRequest(HttpMethod.GET, clientConfiguration.getBaseUrl() + "/email/verify", null, getHttpHeaders(false), new ByteArrayInputStream(urlParameter.toString().getBytes(StandardCharsets.UTF_8)), -1L);
        return requestExecutor.executeRequest(request);
    } catch (HttpException e) {
        throw new ProcessingException(e);
    }
}
Also used : DefaultRequest(com.okta.commons.http.DefaultRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SkipAuthenticatorEnrollmentRequest(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest) Request(com.okta.commons.http.Request) IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) EnrollUserProfileUpdateRequest(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest) DefaultRequest(com.okta.commons.http.DefaultRequest) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest) CancelRequest(com.okta.idx.sdk.api.request.CancelRequest) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) IntrospectRequest(com.okta.idx.sdk.api.request.IntrospectRequest) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) PollRequest(com.okta.idx.sdk.api.request.PollRequest) HttpException(com.okta.commons.http.HttpException) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException)

Example 15 with DefaultRequest

use of com.okta.commons.http.DefaultRequest in project okta-idx-java by okta.

the class BaseIDXClient method recover.

@Override
public IDXResponse recover(RecoverRequest recoverRequest, String href) throws ProcessingException {
    IDXResponse idxResponse;
    try {
        Request request = new DefaultRequest(HttpMethod.POST, Strings.hasText(href) ? href : clientConfiguration.getBaseUrl() + "/idp/idx/recover", null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(recoverRequest)), -1L);
        Response response = requestExecutor.executeRequest(request);
        if (response.getHttpStatus() != 200) {
            handleErrorResponse(request, response);
        }
        JsonNode responseJsonNode = objectMapper.readTree(response.getBody());
        idxResponse = objectMapper.convertValue(responseJsonNode, IDXResponse.class);
    } catch (IOException | HttpException e) {
        throw new ProcessingException(e);
    }
    return idxResponse;
}
Also used : ErrorResponse(com.okta.idx.sdk.api.response.ErrorResponse) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) InteractResponse(com.okta.idx.sdk.api.response.InteractResponse) Response(com.okta.commons.http.Response) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) DefaultRequest(com.okta.commons.http.DefaultRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SkipAuthenticatorEnrollmentRequest(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest) Request(com.okta.commons.http.Request) IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) EnrollUserProfileUpdateRequest(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest) DefaultRequest(com.okta.commons.http.DefaultRequest) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest) CancelRequest(com.okta.idx.sdk.api.request.CancelRequest) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) IntrospectRequest(com.okta.idx.sdk.api.request.IntrospectRequest) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) PollRequest(com.okta.idx.sdk.api.request.PollRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpException(com.okta.commons.http.HttpException) IOException(java.io.IOException) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException)

Aggregations

DefaultRequest (com.okta.commons.http.DefaultRequest)18 Request (com.okta.commons.http.Request)18 Response (com.okta.commons.http.Response)15 ByteArrayInputStream (java.io.ByteArrayInputStream)15 HttpException (com.okta.commons.http.HttpException)14 ProcessingException (com.okta.idx.sdk.api.exception.ProcessingException)14 AnswerChallengeRequest (com.okta.idx.sdk.api.request.AnswerChallengeRequest)14 CancelRequest (com.okta.idx.sdk.api.request.CancelRequest)14 ChallengeRequest (com.okta.idx.sdk.api.request.ChallengeRequest)14 EnrollRequest (com.okta.idx.sdk.api.request.EnrollRequest)14 EnrollUserProfileUpdateRequest (com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest)14 IdentifyRequest (com.okta.idx.sdk.api.request.IdentifyRequest)14 IntrospectRequest (com.okta.idx.sdk.api.request.IntrospectRequest)14 PollRequest (com.okta.idx.sdk.api.request.PollRequest)14 RecoverRequest (com.okta.idx.sdk.api.request.RecoverRequest)14 SkipAuthenticatorEnrollmentRequest (com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ErrorResponse (com.okta.idx.sdk.api.response.ErrorResponse)12 IDXResponse (com.okta.idx.sdk.api.response.IDXResponse)12 InteractResponse (com.okta.idx.sdk.api.response.InteractResponse)12