Skip to content

Commit 8b57fd4

Browse files
Signed-off-by: Stepan Ermakov <[email protected]>
##Fixes issue In case when Keycloack configured, if you create a user with non-ascii names (first name, last name, e-mail address) then these names will be displayed using non-readable symbols in the list of users in the Administration console. ##Changes introduced with this PR In case when External SSO is configured we re-encode the names from ISO_8859_1 to UTF8 ##Are you the owner of the code you are sending in, or do you have permission of the owner? Yes
1 parent 7d868bf commit 8b57fd4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

Diff for: backend/manager/modules/enginesso/src/main/java/org/ovirt/engine/core/sso/service/NegotiateAuthService.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,21 @@ private AuthResult doAuth(HttpServletRequest req, HttpServletResponse rsp, Deque
132132
.mput(
133133
Authz.InvokeKeys.QUERY_FLAGS,
134134
Authz.QueryFlags.RESOLVE_GROUPS | Authz.QueryFlags.RESOLVE_GROUPS_RECURSIVE);
135-
if (SsoService.getSsoContext(req)
135+
boolean externalSso = SsoService.getSsoContext(req)
136136
.getSsoLocalConfig()
137-
.getBoolean("ENGINE_SSO_ENABLE_EXTERNAL_SSO")) {
137+
.getBoolean("ENGINE_SSO_ENABLE_EXTERNAL_SSO");
138+
if (externalSso) {
138139
input.put(Authz.InvokeKeys.HTTP_SERVLET_REQUEST, req);
139140
}
140141
ExtMap outputMap = profile.getAuthz().invoke(input);
141142
token = SsoService.getTokenFromHeader(req);
143+
ExtMap principalRecord = outputMap.get(Authz.InvokeKeys.PRINCIPAL_RECORD);
142144
SsoSession ssoSession = SsoService.persistAuthInfoInContextWithToken(req,
143145
token,
144146
null,
145147
profile.getName(),
146148
authRecord,
147-
outputMap.get(Authz.InvokeKeys.PRINCIPAL_RECORD));
149+
SsoService.fixExternalNames(principalRecord, externalSso));
148150
log.info("User {}@{} with profile [{}] successfully logged in with scopes : {} ",
149151
SsoService.getUserId(outputMap.get(Authz.InvokeKeys.PRINCIPAL_RECORD)),
150152
profile.getAuthzName(),

Diff for: backend/manager/modules/enginesso/src/main/java/org/ovirt/engine/core/sso/service/SsoService.java

+31
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.http.impl.client.CloseableHttpClient;
3636
import org.apache.http.message.BasicNameValuePair;
3737
import org.apache.http.util.EntityUtils;
38+
import org.ovirt.engine.api.extensions.ExtKey;
3839
import org.ovirt.engine.api.extensions.ExtMap;
3940
import org.ovirt.engine.api.extensions.aaa.Authn;
4041
import org.ovirt.engine.api.extensions.aaa.Authz;
@@ -925,4 +926,34 @@ private static Set<String> processGroupMemberships(
925926
}
926927
return membershipIds;
927928
}
929+
930+
/**
931+
* Convert principal record names from ISO_8859_1 to UTF-8 in case when the "External SSO provider" configured
932+
* Apache (httpd) encodes all names using ISO_8859_1 but ovirt-engine tries to work with the data using UTF-8.
933+
* This causes names (like first name, last name, e-mail address) corruption if non-ascii characters are used in
934+
* these names. This routine converts the names to avoid the corruption.
935+
* @param principalRecord Principal Record content to update
936+
* @param externalSso Flag that signals if the "External SSO provider" (Keycloak) configured for the system.
937+
* If the flag is 'false' then no any changes performed.
938+
* @return Updated Principal Record content with fixed names (first name, last name, e-mail address)
939+
*/
940+
public static ExtMap fixExternalNames(ExtMap principalRecord, boolean externalSso) {
941+
if (externalSso && principalRecord != null) {
942+
//If the principal record came from external system, this means it was passed via the mod_auth_openidc
943+
//plugin of the Apache service. This plugin sends all claims using the ISO_8859_1 encoding. This corrupts
944+
//non-ascii characters in names. We need to fix the names:
945+
fixExternalName(principalRecord, Authz.PrincipalRecord.FIRST_NAME);
946+
fixExternalName(principalRecord, Authz.PrincipalRecord.LAST_NAME);
947+
fixExternalName(principalRecord, Authz.PrincipalRecord.EMAIL);
948+
}
949+
return principalRecord;
950+
}
951+
952+
private static void fixExternalName(ExtMap principalRecord, ExtKey key) {
953+
String value = principalRecord.get(key);
954+
if (value != null) {
955+
String valueFixed = new String(value.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
956+
principalRecord.put(key, valueFixed);
957+
}
958+
}
928959
}

0 commit comments

Comments
 (0)