Skip to content

Commit

Permalink
Add abstract AuthScheme.schemeLength()
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Sep 23, 2024
1 parent 4e7a27a commit c588915
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/org/libj/net/AuthScheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -296,4 +306,5 @@ public final boolean matches(final String authorization) {
public abstract String encode();

abstract AuthScheme newInstance(String authorization);
abstract int schemeLength();
}

0 comments on commit c588915

Please sign in to comment.