File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
amqp-client-auth/src/main/java/io/streamnative/rabbitmq/authentication Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 2929 */
3030@ Slf4j
3131public class TokenCredentialsProvider implements CredentialsProvider {
32+
33+ private static final String JOSE_HEADER_UNSECURED_ENCODED = "eyJhbGciOiJub25lIn0" ;
3234 private final Supplier <String > tokenSupplier ;
3335 private String token ;
3436 private Jwt <Header , Claims > jwt ;
@@ -40,12 +42,20 @@ public TokenCredentialsProvider(Supplier<String> tokenSupplier) {
4042
4143 private void load (Supplier <String > tokenSupplier ) {
4244 String token = tokenSupplier .get ();
43- int i = token .lastIndexOf ('.' );
44- String withoutSignature = token .substring (0 , i + 1 );
45- this .jwt = Jwts .parserBuilder ().build ().parseClaimsJwt (withoutSignature );
45+ this .jwt = Jwts .parser ().unsecured ().build ().parseClaimsJwt (transformToUnsecuredJwt (token ));
4646 this .token = token ;
4747 }
4848
49+ public static String transformToUnsecuredJwt (String token ) {
50+ String [] parts = token .split ("\\ ." );
51+ if (parts .length != 3 ) {
52+ throw new IllegalArgumentException ("Invalid JWT token" );
53+ }
54+ StringBuilder sb = new StringBuilder (128 );
55+ sb .append (JOSE_HEADER_UNSECURED_ENCODED ).append ('.' ).append (parts [1 ]).append ('.' );
56+ return sb .toString ();
57+ }
58+
4959 @ Override
5060 public String getUsername () {
5161 return null ;
You can’t perform that action at this time.
0 commit comments