When I JWT by JwtGenerator and profile is OidcProfile, It faild to rebuild profile.

39 views
Skip to first unread message

Augustus

unread,
Sep 23, 2021, 5:57:35 AM9/23/21
to Pac4j users mailing list
Hi 
My pac4j version is 5.1.3

I use JwtGenerator want to generate an token,like code below:

final SecretSignatureConfiguration secretSignatureConfiguration = new SecretSignatureConfiguration(salt);
final SecretEncryptionConfiguration secretEncryptionConfiguration = new SecretEncryptionConfiguration(salt);
final JwtGenerator generator = new JwtGenerator();
generator.setSignatureConfiguration(secretSignatureConfiguration);
generator.setEncryptionConfiguration(secretEncryptionConfiguration);
String token = "";
 saved by an indirect client (from the UserInterfaceApplication)
final Optional<UserProfile> profile = profileManager.getProfile();
profileManager.removeProfiles();
if (profile.isPresent()) {
token = generator.generate(profile.get());
}


And I add this parameter to Header and user by HeaderClient.
I find it is faild In OidcProfile 166L method getTokenExpirationAdvance()

public int getTokenExpirationAdvance() {
var tokenExpirationAdvance = getAttribute(OidcProfileDefinition.TOKEN_EXPIRATION_ADVANCE);
return tokenExpirationAdvance != null ? (int) tokenExpirationAdvance : -1;
}


because nimbus parse all Number to Long  and in this code it compulsory type a Long to int.

So it turn "nested exception is java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer"

I believe it is easy to fix this bug . But other bug cause by nimbus parse all Number to Long maybe still not found. 

Regards
Augustus

Jérôme LELEU

unread,
Sep 23, 2021, 12:12:21 PM9/23/21
to Augustus, Pac4j users mailing list
Hi,

This might be. Can you provide a simple test class which reproduces the bug?
Thanks.
Best regards,
Jérôme


--
You received this message because you are subscribed to the Google Groups "Pac4j users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pac4j-users/14f7ec7c-34d4-462c-932a-214b3095fa33n%40googlegroups.com.

Augustus

unread,
Sep 23, 2021, 11:52:15 PM9/23/21
to Pac4j users mailing list
Hi,

My test code is:

@Test
void contextLoads() {
GoogleOidcProfile googleOidcProfile = new GoogleOidcProfile();
googleOidcProfile.setTokenExpirationAdvance(-1);

final SecretSignatureConfiguration secretSignatureConfiguration = new SecretSignatureConfiguration("12345678901234567890123456789012");
final SecretEncryptionConfiguration secretEncryptionConfiguration = new SecretEncryptionConfiguration("12345678901234567890123456789012");

final JwtGenerator generator = new JwtGenerator();
generator.setSignatureConfiguration(secretSignatureConfiguration);
generator.setEncryptionConfiguration(secretEncryptionConfiguration);
String token = generator.generate(googleOidcProfile);

JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
jwtAuthenticator.setSignatureConfiguration(secretSignatureConfiguration);
jwtAuthenticator.setEncryptionConfiguration(secretEncryptionConfiguration);


UserProfile userProfile = jwtAuthenticator.validateToken(token);
boolean expired= userProfile.isExpired();
}

and it will throw java.lang.ClassCastException at last row(“ boolean expired= userProfile.isExpired();  ”)
Reply all
Reply to author
Forward
0 new messages