I'm creating custom endpoints following the documentation
But I have version problems.
- In the development of custom endpoints I'm using the 12.0.4 version of keycloak.
- In production the keycloak is in version 11.0.3
In version 12.0.4 I can verify authentication this way:
...
public KeyCloakUserApiProvider(KeycloakSession session) {
this.session = session;
this.auth = new AppAuthManager.BearerTokenAuthenticator(session).authenticate();
}
...
public static void checkRealmAdmin(AuthenticationManager.AuthResult auth) {
if (auth == null || auth.getSession() == null || auth.getSession().getUser() == null) {
throw new ForbiddenException("User not authenticated");
} else {
boolean isAdmin = auth.getSession()
.getUser()
.getRoleMappingsStream()
.anyMatch(r-> r.getName().equals("ADMINISTRATOR") || r.getName().equals("ADMIN"));
if (!isAdmin) {
throw new ForbiddenException("User is not admin");
}
}
}
But in version 11.0.3 there is no such method:
new AppAuthManager.BearerTokenAuthenticator(
Can I do this authentication check in what way in version 11.0.3?