Authentication of the CLI Client
Add authentication to the sample CLI client.
The sample CLI client ftp-service-cli-client
interacts with the FTP server to let the user add or delete files from the server’s destination directory. To enable secure communication, we added certificates to the CLI client so that it establishes a TLS channel.
Making client certificates accessible on classpath
The CLI client needs its own key and certificate as well as the root CA certificate to authenticate itself. We show how to create these files in the SSL certificate generation lesson and placed them in the src/main/resources/cert
directory in the ftp-service-cli-client
module of the grpc-ftp-project
. To copy this folder to the target directory, we will use the Maven Resources Plugin
.
We will add this plugin in the <build>
section of the POM file of ftp-service-cli-client
. The following code represents a configuration for setting up an execution for the plugin to copy the certificates from the src/main/resources/certs
directory to the output target/certs
directory during the generate-sources
phase. This will make the certificates accessible on the classpath where the JAR file resides. Explanation of the code is given below the code widget.
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version><executions><execution><id>copy-resource-one</id><phase>generate-sources</phase><goals><goal>copy-resources</goal></goals><configuration><outputDirectory>${basedir}/target/certs</outputDirectory><resources><resource><directory>src/main/resources/certs</directory><filtering>true</filtering></resource></resources></configuration></execution></executions></plugin>
Plugin information: The group ID and artifact ID specify the Maven Resources Plugin and its version being employed for resource management. The group ID is org.apache.maven.plugins
, the artifact ID is maven-resources-plugin
and the version is 3.0.2
.
Execution configuration: The execution configuration has the ID copy-resource-one
. The <goals>
section defines an execution block named copy-resource-one
to handle the copy-resources
goal during the generate-sources
phase of the Maven build lifecycle.
Configuration details: The output directory is set to ${basedir}/target/certs
. It specifies the directory where the resources will be copied. src/main/resources/certs
indicates the source directory from which resources will be copied. The filtering
attribute is set to true
. It indicates that resource files can contain Maven variables that will be replaced during the copy process.
Command line option for secure connection
In the SampleCLIClient