Added support for 'client_id' and backward compatibility with 'clientId'
claim #25802
This commit is contained in:
parent
0f1a5ad246
commit
f18dd864da
|
@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
# Changelog for Authorization Utils
|
# Changelog for Authorization Utils
|
||||||
|
|
||||||
|
## [v2.3.0-SNAPSHOT]
|
||||||
|
|
||||||
|
- Added support for 'client_id' and backward compatibility with 'clientId' claim #25802
|
||||||
|
|
||||||
## [v2.2.0]
|
## [v2.2.0]
|
||||||
|
|
||||||
- Switched to the new version of keycloak-client [#25295]
|
- Switched to the new version of keycloak-client [#25295]
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>authorization-utils</artifactId>
|
<artifactId>authorization-utils</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>2.3.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
|
@ -15,7 +15,8 @@ public class KeycloakUser extends AccessToken implements User {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -7083648026885406300L;
|
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<String> roles;
|
protected Collection<String> roles;
|
||||||
protected Boolean application;
|
protected Boolean application;
|
||||||
|
@ -26,10 +27,19 @@ public class KeycloakUser extends AccessToken implements User {
|
||||||
return getPreferredUsername();
|
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
|
@Override
|
||||||
public boolean isApplication() {
|
public boolean isApplication() {
|
||||||
if(application==null) {
|
if(application==null) {
|
||||||
application = getOtherClaims().get(CLIENT_ID_PROPERTY)!=null;
|
application = getClientId()!=null;
|
||||||
}
|
}
|
||||||
return application;
|
return application;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +69,10 @@ public class KeycloakUser extends AccessToken implements User {
|
||||||
@Override
|
@Override
|
||||||
public String getFullName(boolean nameSurname) {
|
public String getFullName(boolean nameSurname) {
|
||||||
if(isApplication()) {
|
if(isApplication()) {
|
||||||
String clientID = (String) getOtherClaims().getOrDefault("clientId", getUsername());
|
String clientID = getClientId();
|
||||||
|
if(clientID==null) {
|
||||||
|
clientID = getUsername();
|
||||||
|
}
|
||||||
return clientID;
|
return clientID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue