Skip to content

Commit

Permalink
fix: ciba device notifier header ui and EL support
Browse files Browse the repository at this point in the history
  • Loading branch information
podlesrafal committed Jan 10, 2025
1 parent 05ae562 commit 932d141
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.gravitee.am.repository</groupId>
<artifactId>gravitee-am-repository-api</artifactId>
<version>4.7.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>


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

import io.vertx.rxjava3.ext.web.RoutingContext;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -36,4 +37,5 @@ public class ADNotificationRequest {
private List<String> acrValues;
private String state;
private String message;
private RoutingContext context;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import io.gravitee.am.authdevice.notifier.api.model.ADUserResponse;
import io.gravitee.am.authdevice.notifier.http.HttpAuthenticationDeviceNotifierConfiguration;
import io.gravitee.am.authdevice.notifier.http.provider.spring.HttpAuthenticationDeviceProviderSpringConfiguration;
import io.gravitee.am.identityprovider.api.AuthenticationContext;
import io.gravitee.am.identityprovider.api.SimpleAuthenticationContext;
import io.gravitee.common.http.HttpStatusCode;
import io.gravitee.el.TemplateEngine;
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 All @@ -40,6 +44,7 @@

import java.util.Optional;

import static io.gravitee.am.common.utils.ConstantKeys.CIBA_AUTH_REQUEST_KEY;
import static org.springframework.util.StringUtils.hasText;

/**
Expand Down Expand Up @@ -69,16 +74,30 @@ public class HttpAuthenticationDeviceNotifierProvider implements AuthenticationD

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

AuthenticationContext authenticationContext = new SimpleAuthenticationContext(request.getContext().get(CIBA_AUTH_REQUEST_KEY));
//removing context from request to not duplicate.
request.setContext(null);
authenticationContext.setAttribute("cibaRequest", request);
TemplateEngine templateEngine = authenticationContext.getTemplateEngine();

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 = templateEngine.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 @@ -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;
}
}
}
}

0 comments on commit 932d141

Please sign in to comment.