2828import org .eclipse .dataplane .domain .dataflow .DataFlowSuspendMessage ;
2929import org .eclipse .dataplane .domain .dataflow .DataFlowTerminateMessage ;
3030import org .eclipse .dataplane .domain .registration .Authorization ;
31- import org .eclipse .dataplane .domain .registration .AuthorizationType ;
3231import org .eclipse .dataplane .domain .registration .ControlPlaneRegistrationMessage ;
3332import org .eclipse .dataplane .domain .registration .DataPlaneRegistrationMessage ;
3433import org .eclipse .dataplane .logic .OnCompleted ;
5655import java .util .Map ;
5756import java .util .Set ;
5857import java .util .UUID ;
59- import java .util .function .BiConsumer ;
6058
6159import static com .fasterxml .jackson .databind .DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES ;
6260import static java .util .Collections .emptyMap ;
@@ -79,7 +77,7 @@ public class Dataplane {
7977 private OnCompleted onCompleted = dataFlow -> Result .failure (new UnsupportedOperationException ("onCompleted is not implemented" ));
8078
8179 private final HttpClient httpClient = HttpClient .newHttpClient ();
82- private final Map <String , AuthorizationType > authorizationTypes = new HashMap <>();
80+ private final Map <String , Authorization > authorizations = new HashMap <>();
8381
8482 public static Builder newInstance () {
8583 return new Builder ();
@@ -314,11 +312,10 @@ private Result<Void> notifyControlPlane(String action, DataFlow dataFlow, Object
314312
315313 var controlPlane = controlPlaneStore .findByEndpoint (dataFlow .getCallbackAddress ());
316314 if (controlPlane .succeeded ()) {
317- var authorization = controlPlane .getContent ().authorization ();
318- if (authorization != null ) {
319- var authorizationType = authorizationTypes .get (authorization .getType ());
320- var castAuthorization = objectMapper .convertValue (authorization , authorizationType .authorizationClass ());
321- authorizationType .authorizationFunction ().accept (requestBuilder , castAuthorization );
315+ var authorizationProfile = controlPlane .getContent ().authorization ();
316+ if (authorizationProfile != null ) {
317+ var authorization = authorizations .get (authorizationProfile .getType ());
318+ authorization .apply (requestBuilder , authorizationProfile );
322319 }
323320 }
324321
@@ -348,7 +345,7 @@ public ControlPlaneStore controlPlaneStore() {
348345
349346 public Result <Void > registerControlPlane (ControlPlaneRegistrationMessage message ) {
350347 for (var auth : message .authorization ()) {
351- if (!authorizationTypes .containsKey (auth .getType ())) {
348+ if (!authorizations .containsKey (auth .getType ())) {
352349 return Result .failure (new AuthorizationNotSupported (auth ));
353350 }
354351 }
@@ -371,12 +368,14 @@ public static class Builder {
371368 private final Dataplane dataplane = new Dataplane ();
372369
373370 private Builder () {
371+
374372 }
375373
376374 public Dataplane build () {
377375 if (dataplane .id == null ) {
378376 dataplane .id = UUID .randomUUID ().toString ();
379377 }
378+
380379 return dataplane ;
381380 }
382381
@@ -430,8 +429,8 @@ public Builder onTerminate(OnTerminate onTerminate) {
430429 return this ;
431430 }
432431
433- public < T extends Authorization > Builder registerAuthorization (String type , Class < T > authorizationClass , BiConsumer < HttpRequest . Builder , T > authorizationFunction ) {
434- dataplane .authorizationTypes .put (type , new AuthorizationType <>( type , authorizationClass , authorizationFunction ) );
432+ public Builder registerAuthorization (Authorization authorization ) {
433+ dataplane .authorizations .put (authorization . type (), authorization );
435434 return this ;
436435 }
437436 }
0 commit comments