From c5889150705767d1d6604b1958d3f6bff0254353 Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Mon, 23 Sep 2024 12:57:46 -0500 Subject: [PATCH] Add abstract AuthScheme.schemeLength() --- src/main/java/org/libj/net/AuthScheme.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libj/net/AuthScheme.java b/src/main/java/org/libj/net/AuthScheme.java index 0a9f497..be8b867 100644 --- a/src/main/java/org/libj/net/AuthScheme.java +++ b/src/main/java/org/libj/net/AuthScheme.java @@ -123,6 +123,11 @@ Basic newInstance(final String authorization) { return decode(authorization); } + @Override + int schemeLength() { + return 6; + } + @Override public boolean equals(final Object obj) { if (obj == this) @@ -182,7 +187,7 @@ public static String encode(final String token) { * @throws IllegalArgumentException If {@code authorization} is not in valid Base64 scheme. */ public static Bearer decode(final String authorization) { - return prototype.matches(Objects.requireNonNull(authorization)) ? new Bearer(authorization.substring(7)) : null; + return prototype.matches(Objects.requireNonNull(authorization)) ? new Bearer(authorization.substring(prototype.schemeLength() + 1)) : null; } private final String token; @@ -225,6 +230,11 @@ Bearer newInstance(final String authorization) { return decode(authorization); } + @Override + int schemeLength() { + return 6; + } + @Override public boolean equals(final Object obj) { if (obj == this) @@ -296,4 +306,5 @@ public final boolean matches(final String authorization) { public abstract String encode(); abstract AuthScheme newInstance(String authorization); + abstract int schemeLength(); } \ No newline at end of file