mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-11 23:36:25 +00:00
Proper error message when bearer token is empty (#23903)
* Proper error message when bearer token is empty * Refactored the method --------- Co-authored-by: sonika-shah <58761340+sonika-shah@users.noreply.github.com>
This commit is contained in:
parent
3760a2d612
commit
a481b33264
@ -278,24 +278,23 @@ public class JwtFilter implements ContainerRequestFilter {
|
|||||||
protected static String extractToken(MultivaluedMap<String, String> headers) {
|
protected static String extractToken(MultivaluedMap<String, String> headers) {
|
||||||
LOG.debug("Request Headers:{}", headers);
|
LOG.debug("Request Headers:{}", headers);
|
||||||
String source = headers.getFirst(AUTHORIZATION_HEADER);
|
String source = headers.getFirst(AUTHORIZATION_HEADER);
|
||||||
if (nullOrEmpty(source)) {
|
return extractTokenFromString(source);
|
||||||
throw AuthenticationException.getTokenNotPresentException();
|
|
||||||
}
|
|
||||||
// Extract the bearer token
|
|
||||||
if (source.startsWith(TOKEN_PREFIX)) {
|
|
||||||
return source.substring(TOKEN_PREFIX.length() + 1);
|
|
||||||
}
|
|
||||||
throw AuthenticationException.getTokenNotPresentException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String extractToken(String tokenFromHeader) {
|
public static String extractToken(String tokenFromHeader) {
|
||||||
LOG.debug("Request Token:{}", tokenFromHeader);
|
LOG.debug("Request Token:{}", tokenFromHeader);
|
||||||
if (nullOrEmpty(tokenFromHeader)) {
|
return extractTokenFromString(tokenFromHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String extractTokenFromString(String tokenString) {
|
||||||
|
if (nullOrEmpty(tokenString)) {
|
||||||
throw AuthenticationException.getTokenNotPresentException();
|
throw AuthenticationException.getTokenNotPresentException();
|
||||||
}
|
}
|
||||||
// Extract the bearer token
|
if (tokenString.startsWith(TOKEN_PREFIX)) {
|
||||||
if (tokenFromHeader.startsWith(TOKEN_PREFIX)) {
|
if (tokenString.length() <= TOKEN_PREFIX.length() + 1) {
|
||||||
return tokenFromHeader.substring(TOKEN_PREFIX.length() + 1);
|
throw AuthenticationException.getTokenNotPresentException();
|
||||||
|
}
|
||||||
|
return tokenString.substring(TOKEN_PREFIX.length() + 1);
|
||||||
}
|
}
|
||||||
throw AuthenticationException.getTokenNotPresentException();
|
throw AuthenticationException.getTokenNotPresentException();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user