Try the local-grpc-server example first run:
./gradlew :example:local-grpc-server:bootRun
In a different terminal window run:
./gradlew :example:local-grpc-client:bootRun
Visit http://localhost:8080/ to see the result.
Try the cloud-eureka-server example first run:
./gradlew :example:cloud-eureka-server:bootRun
Run zipkin-server
In a different terminal window run:
./gradlew :example:cloud-grpc-server:bootRun
In a different terminal window run:
./gradlew :example:cloud-grpc-client:bootRun
Visit http://localhost:8080/ to see the result.
Try the security-grpc-server example first run:
./gradlew :example:security-grpc-server:bootRun
In a different terminal window run:
./gradlew :example:security-grpc-client:bootRun
Visit http://localhost:8080/ to see the result.
You can configure the client's username in the application.yml.
Try the security-grpc-bearerAuth-server example first run:
./gradlew :example:security-grpc-bearerAuth-server:bootRun
In a different terminal window run:
./gradlew :example:security-grpc-bearerAuth-client:bootRun
Visit http://localhost:8080/ to see the result.
This will not run out of the box since one needs to set up an identity provider service, like
for example Keycloak. Keycloak provides an endpoint to retrieve the necessary configuration (Public RSA key, etc).
The URI to this endpoint needs to be provided in the server's SecurityConfiguration.java
in the jwtDecoder()
method.
Additionally you will need to obtain a valid access token from the Keycloak server. This token has to be provided in
the client's SecurityConfiguration.java
To obtain an access token you can use Postman and perform an HTTP POST call to:
http://127.0.0.1:8080/auth/realms/YOURREALM/protocol/openid-connect/token
with basic authentication. Username and password are the client id and secret of the client you configured in the
Keycloak admin panel (http://127.0.0.1:8080/).
You can configure the bearer token in the SecurityConfiguration.java
Advice for testing/development:
When testing/developing it is not always possible to have an IDP service ready. In that case you can add the following line:
providers.add(anonymousAuthenticationProvider());
right above (your actual authentication providers)
providers.add(jwtAuthenticationProvider());
in the authenticationManager()
bean method of the server's SecurityConfiguration.java
This will of course require an appropriate Bean like such:
@Bean
AnonymousAuthenticationProvider anonymousAuthenticationProvider() {
return new AnonymousAuthenticationProvider("dev");
}
and in the authenticationReader() Bean replace the return with:
return new AnonymousAuthenticationReader("dev", "developer", AuthorityUtils.createAuthorityList("ROLE_TEST"));
You can add/change the roles there to your liking.
Overall what happens here is that the BearerAuthenticationReader is replaced by AnonymousAuthenticationReader, which
ignores the Bearer token and creates an AnonymousAuthenticationToken which is processed by the
AnonymousAuthenticationProvider
. This way you can temporarily bypass the bearer token auth.
You might want to toggle this behavior with a dev
or debug
property.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。