Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ciba device notifier header ui and EL support #5349

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.gravitee.am.repository</groupId>
<artifactId>gravitee-am-repository-api</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
podlesrafal marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>io.gravitee.el</groupId>
<artifactId>gravitee-expression-language</artifactId>
<version>${gravitee-expression-language.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.gravitee.am.gateway.handler</groupId>
<artifactId>gravitee-am-gateway-handler-common</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>


</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,31 @@
*/
package io.gravitee.am.authdevice.notifier.api.model;

import io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest;
import io.gravitee.am.gateway.handler.context.EvaluableExecutionContext;
import io.gravitee.am.gateway.handler.context.EvaluableRequest;
import io.gravitee.el.TemplateContext;
import io.gravitee.el.TemplateEngine;
import io.vertx.rxjava3.ext.web.RoutingContext;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Set;

import static io.gravitee.am.gateway.handler.common.utils.RoutingContextUtils.getEvaluableAttributes;

/**
* @author Eric LELEU (eric.leleu at graviteesource.com)
* @author GraviteeSource Team
*/
@Setter
@Getter
public class ADNotificationRequest {

private static final String TEMPLATE_ATTRIBUTE_REQUEST = "request";
private static final String TEMPLATE_ATTRIBUTE_CONTEXT = "context";

private String deviceNotifierId;
private String transactionId;
private String subject;
Expand All @@ -36,4 +48,17 @@ public class ADNotificationRequest {
private List<String> acrValues;
private String state;
private String message;
private RoutingContext context;

private TemplateEngine templateEngine;

public TemplateEngine getTemplateEngine() {
if (templateEngine == null) {
templateEngine = TemplateEngine.templateEngine();
TemplateContext templateContext = templateEngine.getTemplateContext();
templateContext.setVariable(TEMPLATE_ATTRIBUTE_REQUEST, new EvaluableRequest(new VertxHttpServerRequest(this.context.request().getDelegate())));
templateContext.setVariable(TEMPLATE_ATTRIBUTE_CONTEXT, new EvaluableExecutionContext(getEvaluableAttributes(this.context)));
}
return templateEngine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.gravitee.am.authdevice.notifier.http.HttpAuthenticationDeviceNotifierConfiguration;
import io.gravitee.am.authdevice.notifier.http.provider.spring.HttpAuthenticationDeviceProviderSpringConfiguration;
import io.gravitee.common.http.HttpStatusCode;
import io.gravitee.el.exceptions.ExpressionEvaluationException;
import io.reactivex.rxjava3.core.Single;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -69,16 +70,24 @@ public class HttpAuthenticationDeviceNotifierProvider implements AuthenticationD

@Override
public Single<ADNotificationResponse> notify(ADNotificationRequest request) {

LOGGER.debug("Call notifier service '{}' (tid: {}) ", this.configuration.getEndpoint(), request.getTransactionId());

MultiMap formData = prepareFormData(request);

final HttpRequest<Buffer> notificationRequest = this.client.requestAbs(HttpMethod.POST, this.configuration.getEndpoint());
if (this.configuration.getHttpHeaders() != null && !this.configuration.getHttpHeaders().isEmpty()) {
notificationRequest.putHeaders(this.configuration.getHttpHeaders().stream()
.collect(MultiMap::caseInsensitiveMultiMap,
(map, header) -> map.add(header.getName(), header.getValue()),
MultiMap::addAll));
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
for (var header : this.configuration.getHttpHeaders()) {
try {
String value = request.getTemplateEngine().eval(header.getValue(), String.class).blockingGet();
headers.add(header.getName(), value);
} catch (ExpressionEvaluationException e) {
LOGGER.error("Failed to evaluate header '{}'", header.getName(), e);
return Single.error(new DeviceNotificationException("Failed to evaluate header"));
}
}
notificationRequest.putHeaders(headers);
}
if (hasText(this.configuration.getHeaderValue())) {
notificationRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"value": {
"title": "Value",
"description": "HTTP Header value",
"description": "HTTP Header value (support EL)",
"type": "string"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.gravitee.am.authdevice.notifier</groupId>
<artifactId>gravitee-am-authdevice-notifier-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<!-- Testing -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.gravitee.am.gateway.handler.ciba.ad;

import io.gravitee.am.gateway.handler.ciba.ad.model.ADNotificationRequest;
import io.gravitee.am.gateway.handler.ciba.ad.model.ADNotificationResponse;
import io.gravitee.am.authdevice.notifier.api.model.ADNotificationRequest;
import io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse;
import io.reactivex.rxjava3.core.Single;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package io.gravitee.am.gateway.handler.ciba.ad.impl;

import io.gravitee.am.authdevice.notifier.api.model.ADNotificationRequest;
import io.gravitee.am.authdevice.notifier.api.model.ADNotificationResponse;
import io.gravitee.am.gateway.handler.ciba.ad.AuthenticationDeviceNotifier;
import io.gravitee.am.gateway.handler.ciba.ad.model.ADNotificationRequest;
import io.gravitee.am.gateway.handler.ciba.ad.model.ADNotificationResponse;
import io.gravitee.am.gateway.handler.ciba.exception.DeviceNotificationException;
import io.gravitee.am.model.Domain;
import io.gravitee.am.service.http.WebClientBuilder;
Expand Down Expand Up @@ -103,7 +103,7 @@ public Single<ADNotificationResponse> notify(ADNotificationRequest request) {

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());
LOGGER.warn("Device notification response contains invalid tid '{}' or state '{}'", request.getTransactionId(), request.getState());
throw new DeviceNotificationException("Invalid device notification response");
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void handle(RoutingContext context) {
adRequest.setState(stateJwt);
adRequest.setTransactionId(externalTrxId);
adRequest.setDeviceNotifierId(authDeviceNotifierId);
adRequest.setContext(context);

return authRequestService.notify(adRequest)
.flatMap(adResponse -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@
:host ::ng-deep mat-error {
padding-left: 12px;
}

:host {
::ng-deep {
fieldset {
flex-layout-root-widget {
display: initial !important;
max-height: 100% !important;
box-sizing: border-box !important;
flex-flow: column nowrap !important;
}
}
}
}