diff --git a/CHANGELOG.md b/CHANGELOG.md
index c55b391..85b23c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Authorization Utils
+## [v2.3.0-SNAPSHOT]
+
+- Added support for 'client_id' and backward compatibility with 'clientId' claim #25802
+
## [v2.2.0]
- Switched to the new version of keycloak-client [#25295]
diff --git a/pom.xml b/pom.xml
index 831b195..ed414c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.gcube.common
authorization-utils
- 2.2.0
+ 2.3.0-SNAPSHOT
UTF-8
diff --git a/src/main/java/org/gcube/common/authorization/utils/user/KeycloakUser.java b/src/main/java/org/gcube/common/authorization/utils/user/KeycloakUser.java
index e604cc5..94135e0 100644
--- a/src/main/java/org/gcube/common/authorization/utils/user/KeycloakUser.java
+++ b/src/main/java/org/gcube/common/authorization/utils/user/KeycloakUser.java
@@ -15,7 +15,8 @@ public class KeycloakUser extends AccessToken implements User {
*/
private static final long serialVersionUID = -7083648026885406300L;
- public static final String CLIENT_ID_PROPERTY = "clientId";
+ public static final String CLIENT_ID_PROPERTY_OLD_KEY = "clientId";
+ public static final String CLIENT_ID_PROPERTY = "client_id";
protected Collection roles;
protected Boolean application;
@@ -26,10 +27,19 @@ public class KeycloakUser extends AccessToken implements User {
return getPreferredUsername();
}
+ @JsonIgnore
+ protected String getClientId() {
+ Object clientIdObj = getOtherClaims().get(CLIENT_ID_PROPERTY);
+ if(clientIdObj==null) {
+ clientIdObj = getOtherClaims().get(CLIENT_ID_PROPERTY_OLD_KEY);
+ }
+ return clientIdObj==null ? null : clientIdObj.toString();
+ }
+
@Override
public boolean isApplication() {
if(application==null) {
- application = getOtherClaims().get(CLIENT_ID_PROPERTY)!=null;
+ application = getClientId()!=null;
}
return application;
}
@@ -59,7 +69,10 @@ public class KeycloakUser extends AccessToken implements User {
@Override
public String getFullName(boolean nameSurname) {
if(isApplication()) {
- String clientID = (String) getOtherClaims().getOrDefault("clientId", getUsername());
+ String clientID = getClientId();
+ if(clientID==null) {
+ clientID = getUsername();
+ }
return clientID;
}