Skip to content

Commit 7fd70c4

Browse files
committed
Purge bearer auth example
The example is mostly non functional and just statically provides the bearer token, which is usually a dynamic token. The basic auth example and the docs accurately describe the security setup. We could still add a bearer auth setup using i.e. keycloak, but then it should be included in the testExamples.sh script to ensure it doesn't break unnoticed.
1 parent 3523201 commit 7fd70c4

File tree

15 files changed

+0
-597
lines changed

15 files changed

+0
-597
lines changed

examples/README.md

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -72,71 +72,3 @@
7272
3. Visit http://localhost:8080/ to see the result.
7373

7474
*You can configure the client's username in the application.yml.*
75-
76-
## With Bearer auth security
77-
78-
1. Try the security-grpc-bearerAuth-server example first run:
79-
80-
````sh
81-
./gradlew :example:security-grpc-bearerAuth-server:bootRun
82-
````
83-
84-
2. In a different terminal window run:
85-
86-
````sh
87-
./gradlew :example:security-grpc-bearerAuth-client:bootRun
88-
````
89-
90-
3. Visit http://localhost:8080/ to see the result.
91-
92-
This will not run out of the box since one needs to set up an identity provider service, like
93-
for example Keycloak. Keycloak provides an endpoint to retrieve the necessary configuration (Public RSA key, etc).
94-
The URI to this endpoint needs to be provided in the server's `SecurityConfiguration.java` in the `jwtDecoder()` method.
95-
96-
Additionally you will need to obtain a valid access token from the Keycloak server. This token has to be provided in
97-
the client's `SecurityConfiguration.java`
98-
99-
To obtain an access token you can use Postman and perform an HTTP POST call to:
100-
`http://127.0.0.1:8080/auth/realms/YOURREALM/protocol/openid-connect/token`
101-
with basic authentication. Username and password are the client id and secret of the client you configured in the
102-
Keycloak admin panel (http://127.0.0.1:8080/).
103-
104-
*You can configure the bearer token in the `SecurityConfiguration.java`*
105-
106-
**Advice for testing/development:**
107-
108-
When testing/developing it is not always possible to have an IDP service ready. In that case you can add the following
109-
line:
110-
111-
````java
112-
providers.add(anonymousAuthenticationProvider());
113-
````
114-
115-
right above (your actual authentication providers)
116-
117-
````java
118-
providers.add(jwtAuthenticationProvider());
119-
````
120-
121-
in the `authenticationManager()` bean method of the server's `SecurityConfiguration.java`
122-
This will of course require an appropriate Bean like such:
123-
124-
````java
125-
@Bean
126-
AnonymousAuthenticationProvider anonymousAuthenticationProvider() {
127-
return new AnonymousAuthenticationProvider("dev");
128-
}
129-
````
130-
131-
and in the authenticationReader() Bean replace the return with:
132-
133-
````java
134-
return new AnonymousAuthenticationReader("dev", "developer", AuthorityUtils.createAuthorityList("ROLE_TEST"));
135-
````
136-
137-
You can add/change the roles there to your liking.
138-
139-
Overall what happens here is that the BearerAuthenticationReader is replaced by AnonymousAuthenticationReader, which
140-
ignores the Bearer token and creates an AnonymousAuthenticationToken which is processed by the
141-
`AnonymousAuthenticationProvider`. This way you can temporarily bypass the bearer token auth.
142-
You might want to toggle this behavior with a `dev` or `debug` property.

examples/security-grpc-bearerAuth-client/build.gradle

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/security-grpc-bearerAuth-client/src/main/java/net/devh/boot/grpc/examples/security/client/GrpcClientController.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/security-grpc-bearerAuth-client/src/main/java/net/devh/boot/grpc/examples/security/client/GrpcClientService.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

examples/security-grpc-bearerAuth-client/src/main/java/net/devh/boot/grpc/examples/security/client/SecurityBearerGrpcClientApplication.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

examples/security-grpc-bearerAuth-client/src/main/java/net/devh/boot/grpc/examples/security/client/SecurityConfiguration.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/security-grpc-bearerAuth-client/src/main/resources/application.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/security-grpc-bearerAuth-server/build.gradle

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/security-grpc-bearerAuth-server/src/main/java/net/devh/boot/grpc/examples/security/server/GrpcServerService.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)