davsclaus commented on code in PR #14849: URL: https://github.com/apache/camel/pull/14849#discussion_r1705490990
########## components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java: ########## @@ -59,6 +69,68 @@ public Service newHttpServer(HttpServerConfigurationProperties configuration) { server.setUploadEnabled(configuration.isUploadEnabled()); server.setUploadSourceDir(configuration.getUploadSourceDir()); + if (configuration.authentication().isEnabled()) { + configureAuthentication(server, configuration); + } + return server; } + + private void configureAuthentication(MainHttpServer server, HttpServerConfigurationProperties configuration) { + AuthenticationConfig authenticationConfig = server.getConfiguration().getAuthenticationConfig(); + + HttpServerAuthenticationConfigurationProperties authenticationProperties = configuration.getAuthentication(); + Optional<MainAuthenticationConfigurer> authenticationConfigurer + = findAuthenticationConfigurerByConfigurationProperties(authenticationProperties); + + authenticationConfigurer.ifPresentOrElse( + (configurer -> configurer.configureAuthentication(authenticationConfig, authenticationProperties)), + (() -> { + throw new RuntimeException( + "Authentication for camel-platform-http-main is enabled but no complete authentication configuration is found."); + })); + } + + private Optional<MainAuthenticationConfigurer> findAuthenticationConfigurerByConfigurationProperties( + HttpServerAuthenticationConfigurationProperties authenticationConfigurationProperties) { + + MainAuthenticationConfigurer result = null; + for (String authenticationTypeName : HttpServerAuthenticationConfigurationProperties.SUPPORTED_AUTHENTICATION_TYPES) { + if (authenticationTypeIsEnabled(authenticationConfigurationProperties, authenticationTypeName)) { + try { + if (result != null) { + throw new RuntimeException( + "Cannot configure authentication for MainHttpServer as more than one authentication configuration is present"); + } + String configurerQualifiedName = MainAuthenticationConfigurer.class.getPackageName() + "." + + authenticationTypeName + "AuthenticationConfigurer"; + ClassResolver resolver = new DefaultClassResolver(); Review Comment: You should get the class resolver via `CamelContext` and use `Injector` also from `CamelContext` to create an instance of the class -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org