diff --git a/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/GrpcChannelConfigurator.java b/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/GrpcChannelConfigurator.java new file mode 100644 index 0000000000000000000000000000000000000000..1329b1084168a7086e24c1d051410afa84b52e3a --- /dev/null +++ b/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/GrpcChannelConfigurator.java @@ -0,0 +1,26 @@ +package de.ozgcloud.client.autoconfigure; + +import lombok.Builder; +import lombok.Getter; +import net.devh.boot.grpc.client.config.GrpcChannelProperties; +import net.devh.boot.grpc.client.config.GrpcChannelsProperties; +import net.devh.boot.grpc.client.config.NegotiationType; + +@Builder +@Getter +public class GrpcChannelConfigurator { + + private String clientName; + private String address; + private NegotiationType negotiationType; + + public void addToProperties(GrpcChannelsProperties properties) { + var clientMap = properties.getClient(); + + var channelProps = new GrpcChannelProperties(); + channelProps.setAddress(address); + channelProps.setNegotiationType(negotiationType); + + clientMap.put(clientName, channelProps); + } +} diff --git a/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/OzgCloudClientAutoConfiguration.java b/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/OzgCloudClientAutoConfiguration.java index 72c9378c6fb2dbf7d458c5cc2dcbd4d6a6c9537c..dc3249e1b318acab3ce68e41529dc6f76d0f2f1a 100644 --- a/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/OzgCloudClientAutoConfiguration.java +++ b/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/OzgCloudClientAutoConfiguration.java @@ -1,5 +1,6 @@ package de.ozgcloud.client.autoconfigure; +import java.util.Collection; import java.util.Map; import org.mapstruct.factory.Mappers; @@ -48,6 +49,7 @@ public class OzgCloudClientAutoConfiguration { private static final String CLIENT_NAME_VORGANG_MANAGER = "vorgang-manager"; private static final String CLIENT_NAME_FILE_MANAGER = "file-manager"; private static final String CLIENT_NAME_COMMAND_MANAGER = "command-manager"; + private static final String CLIENT_NAME_USER_MANAGER = "user-manager"; @Autowired private OzgCloudVorgangManagerProperties vorgangManagerProperties; @@ -55,6 +57,8 @@ public class OzgCloudClientAutoConfiguration { private OzgCloudFileManagerProperties fileManagerProperties; @Autowired private OzgCloudCommandManagerProperties commandManagerProperties; + @Autowired + private OzgCloudUserManagerProperties userManagerProperties; // @Bean // @ConditionalOnProperty("ozgcloud.vorgang-manager.address") @@ -71,10 +75,27 @@ public class OzgCloudClientAutoConfiguration { @Bean @ConditionalOnProperty("ozgcloud.command-manager.address") - GrpcChannelsProperties commandProperties() { + GrpcChannelConfigurator commandProperties() { + return GrpcChannelConfigurator.builder() + .clientName(CLIENT_NAME_COMMAND_MANAGER) + .address(commandManagerProperties.getAddress()) + .negotiationType(commandManagerProperties.getNegotiationType()) + .build(); + } + + GrpcChannelConfigurator userManagerProperties() { + return GrpcChannelConfigurator.builder() + .clientName(CLIENT_NAME_USER_MANAGER) + .address(userManagerProperties.getAddress()) + .negotiationType(userManagerProperties.getNegotiationType()) + .build(); + } + + @Bean + GrpcChannelsProperties clientProperties(Collection<GrpcChannelConfigurator> configurators) { var properties = new GrpcChannelsProperties(); - var clientMap = properties.getClient(); - addCommandManager(clientMap); + configurators.stream().forEach(configurator -> configurator.addToProperties(properties)); + return properties; } @@ -163,4 +184,11 @@ public class OzgCloudClientAutoConfiguration { AlfaService alfaService() { return new DummyAlfaService(); } + + @Bean + @ConditionalOnProperty("ozgcloud.user-manager.address") + OzgCloudUserProfileService grpcOzgCloudUserProfileService(@GrpcClient("user-manager") UserProfileServiceBlockingStub grpcStub, + UserProfileMapper mapper) { + return new GrpcOzgCloudUserProfileService(grpcStub, mapper); + } } diff --git a/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/OzgCloudUserManagerProperties.java b/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/OzgCloudUserManagerProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..4fec478ca3b5cca9d9f9c2caab02fffe88ecaf53 --- /dev/null +++ b/ozg-cloud-spring-boot-starter/src/main/java/de/ozgcloud/client/autoconfigure/OzgCloudUserManagerProperties.java @@ -0,0 +1,24 @@ +package de.ozgcloud.client.autoconfigure; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import lombok.Getter; +import lombok.Setter; +import net.devh.boot.grpc.client.config.NegotiationType; + +@Getter +@Setter +@Configuration +@ConfigurationProperties("ozgcloud.user-manager") +public class OzgCloudUserManagerProperties { + /** + * Network-Address of the User-Manager instance, starting with resolving + * protocoll. + */ + private String address; + /** + * Negotiation Type for the gRPC connection - possible Values: PLAINTEXT, TLS + */ + private NegotiationType negotiationType = NegotiationType.valueOf("TLS"); +}