From c3cbf4a3b3e1fb802685b7981dcc6b537132be55 Mon Sep 17 00:00:00 2001 From: Sergio Sanchez Date: Thu, 7 Sep 2017 15:18:15 +0300 Subject: [PATCH] Fixed base 64 decode exception for project's member groups Some groups ids (the projects members groups) were being decoded even when they were not encoded. Change-Id: I1c93030b09ecd558027500e1e933a09e0f23fb3d Reviewed-on: http://bellevue-ci.eng.vmware.com:8080/16751 Closures-Verified: jenkins Upgrade-Verified: jenkins Bellevue-Verified: jenkins CS-Verified: jenkins Reviewed-by: Lazarin Lazarov --- .../java/com/vmware/admiral/auth/util/PrincipalUtil.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/auth/src/main/java/com/vmware/admiral/auth/util/PrincipalUtil.java b/auth/src/main/java/com/vmware/admiral/auth/util/PrincipalUtil.java index 37786c054..e5dfad336 100644 --- a/auth/src/main/java/com/vmware/admiral/auth/util/PrincipalUtil.java +++ b/auth/src/main/java/com/vmware/admiral/auth/util/PrincipalUtil.java @@ -131,7 +131,8 @@ public static Pair toNameAndDomain(String principalId) { return new Pair<>(parts[1], parts[0]); } - throw new IllegalArgumentException("Invalid principalId format: '" + decodedPrincipalId + "'"); + throw new IllegalArgumentException( + "Invalid principalId format: '" + decodedPrincipalId + "'"); } public static String toPrincipalId(String name, String domain) { @@ -199,7 +200,8 @@ public static DeferredResult getOrCreateUser(Service service, String .thenCompose(user -> UserGroupsUpdater.create() .setService(service) .setGroupLink(AuthUtil.BASIC_USERS_USER_GROUP_LINK) - .setUsersToAdd(Collections.singletonList(encodedPrincipalId)) + .setUsersToAdd( + Collections.singletonList(encodedPrincipalId)) .update()) .thenCompose(ignore -> service.sendWithDeferredResult(getUser, UserState.class)); @@ -326,7 +328,8 @@ public static String decode(String principalId) { return new String(Base64.getUrlDecoder().decode( principalId.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); } catch (IllegalArgumentException iae) { - if (iae.getMessage().contains("Illegal base64 character")) { + if (iae.getMessage().contains("Illegal base64 character") + || (iae.getMessage().contains("Last unit does not have enough valid bits"))) { // In this case principal id is not encoded string without @ sign in it // so the decoding is failing, we return the same string. return principalId;