use of io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse in project gravitee-access-management by gravitee-io.
the class AuthenticationRequestAcknowledgeHandlerTest method shouldGenerateAuthReqId.
@Test
public void shouldGenerateAuthReqId() throws Exception {
CibaAuthenticationRequest cibaRequest = new CibaAuthenticationRequest();
cibaRequest.setLoginHint("username");
cibaRequest.setSubject("usernameuuid");
router.route().order(-1).handler(routingContext -> {
routingContext.put(ConstantKeys.CLIENT_CONTEXT_KEY, client);
routingContext.put(ConstantKeys.CIBA_AUTH_REQUEST_KEY, cibaRequest);
routingContext.next();
});
when(jwtService.encode(any(JWT.class), any(Client.class))).thenReturn(Single.just("signed_jwt"));
final CibaAuthRequest req = new CibaAuthRequest();
req.setCreatedAt(new Date());
req.setExpireAt(new Date());
when(authReqService.register(any(), any())).thenReturn(Single.just(req));
when(authReqService.updateAuthDeviceInformation(any())).thenReturn(Single.just(req));
when(authReqService.notify(any())).thenReturn(Single.just(new ADNotificationResponse("jit")));
testRequest(HttpMethod.POST, CIBAProvider.CIBA_PATH + CIBAProvider.AUTHENTICATION_ENDPOINT + "?request=fakejwt", null, HttpStatusCode.OK_200, "OK", null);
verify(authReqService).register(any(), any());
verify(authReqService).updateAuthDeviceInformation(any());
verify(authReqService).notify(any());
}
use of io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse in project gravitee-access-management by gravitee-io.
the class HttpAuthenticationDeviceNotifierProvider method notify.
@Override
public Single<ADNotificationResponse> notify(ADNotificationRequest request) {
final MultiMap formData = MultiMap.caseInsensitiveMultiMap();
formData.set(TRANSACTION_ID, request.getTransactionId());
formData.set(STATE, request.getState());
formData.set(PARAM_SUBJECT, request.getSubject());
formData.set(PARAM_SCOPE, request.getScopes());
formData.set(PARAM_EXPIRE, Integer.toString(request.getExpiresIn()));
if (!CollectionUtils.isEmpty(request.getAcrValues())) {
formData.set(PARAM_ACR, request.getAcrValues());
}
if (!isEmpty(request.getMessage())) {
formData.set(PARAM_MESSAGE, request.getMessage());
}
final HttpRequest<Buffer> notificationRequest = this.client.requestAbs(HttpMethod.POST, this.configuration.getEndpoint());
if (!StringUtils.isEmpty(this.configuration.getHeaderValue())) {
notificationRequest.putHeader(this.configuration.getHeaderName(), this.configuration.getHeaderValue());
}
return notificationRequest.rxSendForm(formData).doOnError((error) -> LOGGER.warn("Unexpected error during device notification : {}", error.getMessage(), error)).onErrorResumeNext(Single.error(new DeviceNotificationException("Unexpected error during device notification"))).flatMap(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
LOGGER.info("Device notification fails for tid '{}' with status '{}'", request.getTransactionId(), response.statusCode());
return Single.error(new DeviceNotificationException("Device notification fails"));
}
final JsonObject result = response.bodyAsJsonObject();
if (!request.getTransactionId().equals(result.getString(TRANSACTION_ID)) || !request.getState().equals(result.getString(STATE))) {
LOGGER.warn("Device notification response contains invalid tid or state", request.getTransactionId(), response.statusCode());
return Single.error(new DeviceNotificationException("Invalid device notification response"));
}
final ADNotificationResponse notificationResponse = new ADNotificationResponse(request.getTransactionId());
final JsonObject extraData = result.getJsonObject(RESPONSE_ATTR_DATA);
if (extraData != null) {
notificationResponse.setExtraData(extraData.getMap());
}
return Single.just(notificationResponse);
});
}
Aggregations