To make sure the security between the interfaces of services, users can enable RSA Authorizaiton by simple configuration as below.
- Add dependence in pom.xml file:
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>handler-publickey-auth</artifactId>
</dependency>- Add handler chain in microservice.yaml:
servicecomb:
handler:
chain:
Consumer:
default: auth-consumer- Add dependence in pom.xml file:
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>handler-publickey-auth</artifactId>
</dependency>- Add handler chain in microservice.yaml:
servicecomb:
handler:
chain:
Consumer:
default: auth-providersee Precondition
Auth sample use RestTemplate to present RSA communication between provider and consumer.
-
Start the ServiceComb/Service Center
- how to start the service center
- make sure service center address is configured correctly in
microservice.yamlfile
servicecomb:
service:
registry:
address: http://127.0.0.1:30100 #service center address-
Start the auth-provider service
-
Start provider service by maven
Compile the source code, and use
mvn execto execute the main classAuthProviderMain.mvn clean install cd auth-sample/auth-provider/ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.auth.provider.AuthProviderMain"
-
Start provider service by IDE
Import the project by InteliJ IDEA or Eclipse, then find
mainfunctionAuthProviderMainof provider service andRUNit like any other Java program.
-
-
Start the auth-consumer service
Just like how to start auth-provider service. But the main class of auth-consumer service is
AuthConsumerMain.
cd auth-sample/auth-consumer/
mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.auth.consumer.AuthConsumerMain"-
How to verify On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 'swagger: 2.0 info: version: 1.0.0 ...' means the producer generated swagger contracts
- 'rest listen success. address=0.0.0.0:8080' means the rest endpoint is listening on port 8080
On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- 'Hello Authenticate' means the consumer calls sayhi with name=Authenticate successfully
- 'Hello person ServiceComb/Authenticate' means the consumer calls sayhello successfully