Search in sources :

Example 1 with ADNotificationResponse

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());
}
Also used : CibaAuthRequest(io.gravitee.am.repository.oidc.model.CibaAuthRequest) JWT(io.gravitee.am.common.jwt.JWT) CibaAuthenticationRequest(io.gravitee.am.gateway.handler.ciba.service.request.CibaAuthenticationRequest) Client(io.gravitee.am.model.oidc.Client) Date(java.util.Date) ADNotificationResponse(io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse) Test(org.junit.Test)

Example 2 with ADNotificationResponse

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);
    });
}
Also used : Buffer(io.vertx.reactivex.core.buffer.Buffer) MultiMap(io.vertx.reactivex.core.MultiMap) DeviceNotificationException(io.gravitee.am.authdevice.notifier.api.exception.DeviceNotificationException) JsonObject(io.vertx.core.json.JsonObject) ADNotificationResponse(io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse)

Aggregations

ADNotificationResponse (io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse)2 DeviceNotificationException (io.gravitee.am.authdevice.notifier.api.exception.DeviceNotificationException)1 JWT (io.gravitee.am.common.jwt.JWT)1 CibaAuthenticationRequest (io.gravitee.am.gateway.handler.ciba.service.request.CibaAuthenticationRequest)1 Client (io.gravitee.am.model.oidc.Client)1 CibaAuthRequest (io.gravitee.am.repository.oidc.model.CibaAuthRequest)1 JsonObject (io.vertx.core.json.JsonObject)1 MultiMap (io.vertx.reactivex.core.MultiMap)1 Buffer (io.vertx.reactivex.core.buffer.Buffer)1 Date (java.util.Date)1 Test (org.junit.Test)1