Skip to content

Commit

Permalink
Use the same charset for decode and encode principal ID.
Browse files Browse the repository at this point in the history
Change-Id: Id5a4b6b8a082341a9ad27a97d42af55fbdf30be2
Reviewed-on: http://bellevue-ci.eng.vmware.com:8080/16522
Closures-Verified: jenkins <[email protected]>
Upgrade-Verified: jenkins <[email protected]>
Bellevue-Verified: jenkins <[email protected]>
Reviewed-by: Sergio Sanchez <[email protected]>
CS-Verified: jenkins <[email protected]>
  • Loading branch information
angel-ivanov committed Sep 4, 2017
1 parent dd6e070 commit bdb5de8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions auth/src/main/java/com/vmware/admiral/auth/util/PrincipalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import static com.vmware.admiral.auth.util.AuthUtil.addReplicationFactor;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
Expand Down Expand Up @@ -42,7 +42,6 @@

public class PrincipalUtil {
public static final String ENCODE_MARKER = "@";
public static final String ENCODE_CHARSET = "UTF-8";

public static Principal fromLocalPrincipalToPrincipal(LocalPrincipalState state) {

Expand Down Expand Up @@ -310,11 +309,8 @@ public static String encode(String principalId) {
return principalId;
}

try {
return Base64.getUrlEncoder().encodeToString(principalId.getBytes(ENCODE_CHARSET));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return new String(Base64.getUrlEncoder().encode(
principalId.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
}

public static String decode(String principalId) {
Expand All @@ -327,9 +323,8 @@ public static String decode(String principalId) {
}

try {
return new String(Base64.getUrlDecoder().decode(principalId), ENCODE_CHARSET);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
return new String(Base64.getUrlDecoder().decode(
principalId.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
} catch (IllegalArgumentException iae) {
if (iae.getMessage().contains("Illegal base64 character")) {
// In this case principal id is not encoded string without @ sign in it
Expand Down

0 comments on commit bdb5de8

Please sign in to comment.