feat(common) Add BASIC auth decode functions.
MODIFY
common/util/src/main/java/io/apiman/common/util/Basic.java
common/util/src/main/java/io/apiman/common/util/Basic.java
package io.apiman.common.util;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
@SuppressWarnings("nls")
public class Basic {
@@ -32,4 +33,22 @@ public class Basic {
return builder.toString();
}
+ public static String[] decodeWithScheme(String input) {
+ String[] split = StringUtils.split(input, null);
+ if ("Basic".equalsIgnoreCase(split[0])) {
+ if (split.length == 2) {
+ return decode(split[1]);
+ } else {
+ throw new IllegalArgumentException("Authorization header invalid for BASIC");
+ }
+ } else {
+ throw new IllegalArgumentException("Auth scheme was not BASIC");
+ }
+ }
+
+ public static String[] decode(String input) {
+ String decoded = new String(java.util.Base64.getDecoder().decode(input));
+ return StringUtils.split(decoded, ":");
+ }
+
}

feat(common) Add BASIC auth decode functions.