|
35 | 35 | import org.apache.http.impl.client.CloseableHttpClient;
|
36 | 36 | import org.apache.http.message.BasicNameValuePair;
|
37 | 37 | import org.apache.http.util.EntityUtils;
|
| 38 | +import org.ovirt.engine.api.extensions.ExtKey; |
38 | 39 | import org.ovirt.engine.api.extensions.ExtMap;
|
39 | 40 | import org.ovirt.engine.api.extensions.aaa.Authn;
|
40 | 41 | import org.ovirt.engine.api.extensions.aaa.Authz;
|
@@ -925,4 +926,34 @@ private static Set<String> processGroupMemberships(
|
925 | 926 | }
|
926 | 927 | return membershipIds;
|
927 | 928 | }
|
| 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 | + } |
928 | 959 | }
|
0 commit comments