Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Fixed base 64 decode exception for project's member groups
Browse files Browse the repository at this point in the history
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 <jenkins@vmware.com>
Upgrade-Verified: jenkins <jenkins@vmware.com>
Bellevue-Verified: jenkins <jenkins@vmware.com>
CS-Verified: jenkins <jenkins@vmware.com>
Reviewed-by: Lazarin Lazarov <llazarov@vmware.com>
  • Loading branch information
Sergio Sanchez committed Sep 7, 2017
1 parent 09124f0 commit c3cbf4a
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public static Pair<String, String> 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) {
Expand Down Expand Up @@ -199,7 +200,8 @@ public static DeferredResult<UserState> 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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c3cbf4a

Please sign in to comment.