use of com.okta.commons.http.Response in project okta-sdk-java by okta.
the class DefaultDataStore method getResourceData.
@SuppressWarnings("unchecked")
private ResourceDataResult getResourceData(String href, Class<? extends Resource> clazz, Map<String, ?> queryParameters, HttpHeaders httpHeaders) {
Assert.hasText(href, "href argument cannot be null or empty.");
Assert.notNull(clazz, "Resource class argument cannot be null.");
FilterChain chain = new DefaultFilterChain(this.filters, req -> {
CanonicalUri uri = req.getUri();
Request getRequest = new DefaultRequest(HttpMethod.GET, uri.getAbsolutePath(), uri.getQuery(), req.getHttpHeaders());
Response getResponse = execute(getRequest);
Map<String, ?> body = getBody(getResponse);
if (Collections.isEmpty(body)) {
throw new IllegalStateException("Unable to obtain resource data from the API server or from cache.");
}
return new DefaultResourceDataResult(req.getAction(), uri, req.getResourceClass(), (Map<String, Object>) body);
});
CanonicalUri uri = canonicalize(href, queryParameters);
ResourceDataRequest req = new DefaultResourceDataRequest(ResourceAction.READ, uri, clazz, new HashMap<>(), httpHeaders);
return chain.filter(req);
}
use of com.okta.commons.http.Response in project okta-sdk-java by okta.
the class DefaultDataStore method getRawResponse.
@Override
public InputStream getRawResponse(String href, Map<String, Object> queryParameters, Map<String, List<String>> headerParameters) {
Assert.hasText(href, "href argument cannot be null or empty.");
CanonicalUri uri = canonicalize(href, queryParameters);
Request getRequest = new DefaultRequest(HttpMethod.GET, uri.getAbsolutePath(), uri.getQuery(), headers(headerParameters));
Response getResponse = execute(getRequest);
return getRawBody(getResponse).orElseThrow(() -> new IllegalStateException("Unable to obtain resource data from the API server."));
}
use of com.okta.commons.http.Response in project okta-idx-java by okta.
the class IDXAuthenticationWrapper method fetchSignUpFormValues.
/**
* Populate UI form values for signing up a new user.
*
* @param proceedContext the proceedContext
* @return the authentication response
*/
public AuthenticationResponse fetchSignUpFormValues(ProceedContext proceedContext) {
AuthenticationResponse newUserRegistrationResponse = new AuthenticationResponse();
try {
Assert.notNull(proceedContext.getSelectProfileEnrollHref(), "Org policy is not configured to register new users.");
// enroll new user
AuthenticationTransaction enrollTransaction = AuthenticationTransaction.proceed(client, proceedContext, () -> {
EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withStateHandle(proceedContext.getStateHandle()).build();
return client.enroll(enrollRequest, proceedContext.getSelectProfileEnrollHref());
});
RemediationOption enrollProfileRemediationOption = enrollTransaction.getRemediationOption(RemediationType.ENROLL_PROFILE);
List<FormValue> enrollProfileFormValues = Arrays.stream(enrollProfileRemediationOption.form()).filter(x -> "userProfile".equals(x.getName())).collect(Collectors.toList());
newUserRegistrationResponse.setFormValues(enrollProfileFormValues);
newUserRegistrationResponse.setProceedContext(enrollTransaction.createProceedContext());
return newUserRegistrationResponse;
} catch (ProcessingException e) {
return handleProcessingException(e);
} catch (IllegalArgumentException e) {
return handleIllegalArgumentException(e);
}
}
use of com.okta.commons.http.Response 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;
}
use of com.okta.commons.http.Response 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;
}
Aggregations