I have went through the documentation of jwt and implemented a login module which uses jwt to fulfil my authentication and authorisation. The problem is now, my module is high load input module where concurrent users will access the module at a time, So i want to know that jwt is thread safe? If it is not thread safe, what kind of technique i can use to make thread and NOT
coarse-grained synchronisation. So, both are important for me.
Here is my code snippet in java
private String generateJWTToken( User user, Long expiryTimeInMillis ) {
try {
Long currentTimeInMillis = currentContext;
Date currentDate = new Date( currentTimeInMillis );
Date expiryDate = new Date( currentTimeInMillis + expiryTimeInMillis );
if ( user.getUsername() == null || user.getUserRoles() == null || user.getUserRoles().isEmpty() || secretKey == null ) {
return null;
}
String roles = prepareRoleIds( user.getUserRoles() );
return Jwts.builder().setSubject( user.getUsername() ).setIssuedAt( currentDate ).claim( "Role", roles ).setExpiration( expiryDate ).signWith( secretKey ).compact();
}
catch ( Exception e ) {
return null;
}
}
I didn’t tried any method to overcome this issue, i want insight from some experienced people where good at technique like Lock striping and related ones. So , i am expecting simple technique to overcome my issue.