Avoiding null pointer exceptions

This commit is contained in:
Luca Frosini 2022-03-24 14:30:16 +01:00
parent d2d8686259
commit 3fbcaf37ad
1 changed files with 4 additions and 4 deletions

View File

@ -99,7 +99,7 @@ public class JWTSecret extends Secret {
AccessTokenProvider.instance.reset();
}
protected AccessToken getAccessToken() throws Exception {
protected AccessToken getAccessToken() {
if(accessToken==null) {
String realUmaTokenEncoded = token.split("\\.")[1];
String realUmaToken = new String(Base64.getDecoder().decode(realUmaTokenEncoded.getBytes()));
@ -108,7 +108,7 @@ public class JWTSecret extends Secret {
accessToken = mapper.readValue(realUmaToken, AccessToken.class);
}catch(Exception e){
logger.error("Error parsing JWT token",e);
throw new Exception("Error parsing JWT token", e);
throw new RuntimeException("Error parsing JWT token", e);
}
}
return accessToken;
@ -193,7 +193,7 @@ public class JWTSecret extends Secret {
@Override
public boolean isExpired() {
return isExpired(accessToken);
return isExpired(getAccessToken());
}
@Override
@ -214,7 +214,7 @@ public class JWTSecret extends Secret {
if(user==null) {
try {
ObjectMapper objectMapper = new ObjectMapper();
String accessTokenString = objectMapper.writeValueAsString(accessToken);
String accessTokenString = objectMapper.writeValueAsString(getAccessToken());
user = objectMapper.readValue(accessTokenString, KeycloakUser.class);
user.setRoles(getRoles());
} catch (Exception e) {