From 28993756145a5c717c76ed34ed5debd80221bfdd Mon Sep 17 00:00:00 2001 From: Valeran86 Date: Fri, 21 Jun 2019 15:48:50 +0300 Subject: [PATCH] KeycloakRole equals only with itself I use Keycloak Spring Adapter (KSA) to secure existing application. Today I realized that some functions didn't work anymore because of security checking like this: ``` GrantedAuthority adminRole = new MySpecialGrantedAuthority( "superadmin" ); for ( GrantedAuthority role : userRoles ) { if ( role.equals( adminRole ) ) { return true; } } ``` In this example, when I use KSA authorization fails. I believe, that more preferable in `KeycloakRole` use this implementation of `equals` method. --- .../adapters/springsecurity/account/KeycloakRole.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/account/KeycloakRole.java b/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/account/KeycloakRole.java index 82efff1b86..f83549deb9 100644 --- a/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/account/KeycloakRole.java +++ b/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/account/KeycloakRole.java @@ -51,13 +51,13 @@ public class KeycloakRole implements GrantedAuthority { if (this == o) { return true; } - if (!(o instanceof KeycloakRole)) { + if (!(o instanceof GrantedAuthority)) { return false; } - KeycloakRole that = (KeycloakRole) o; + GrantedAuthority that = (GrantedAuthority) o; - if (!role.equals(that.role)) { + if (!role.equals(that.getAuthority())) { return false; }