Avoiding null pointer exceptions
This commit is contained in:
parent
d2d8686259
commit
3fbcaf37ad
|
@ -99,7 +99,7 @@ public class JWTSecret extends Secret {
|
||||||
AccessTokenProvider.instance.reset();
|
AccessTokenProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AccessToken getAccessToken() throws Exception {
|
protected AccessToken getAccessToken() {
|
||||||
if(accessToken==null) {
|
if(accessToken==null) {
|
||||||
String realUmaTokenEncoded = token.split("\\.")[1];
|
String realUmaTokenEncoded = token.split("\\.")[1];
|
||||||
String realUmaToken = new String(Base64.getDecoder().decode(realUmaTokenEncoded.getBytes()));
|
String realUmaToken = new String(Base64.getDecoder().decode(realUmaTokenEncoded.getBytes()));
|
||||||
|
@ -108,7 +108,7 @@ public class JWTSecret extends Secret {
|
||||||
accessToken = mapper.readValue(realUmaToken, AccessToken.class);
|
accessToken = mapper.readValue(realUmaToken, AccessToken.class);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Error parsing JWT token",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;
|
return accessToken;
|
||||||
|
@ -193,7 +193,7 @@ public class JWTSecret extends Secret {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return isExpired(accessToken);
|
return isExpired(getAccessToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -214,7 +214,7 @@ public class JWTSecret extends Secret {
|
||||||
if(user==null) {
|
if(user==null) {
|
||||||
try {
|
try {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String accessTokenString = objectMapper.writeValueAsString(accessToken);
|
String accessTokenString = objectMapper.writeValueAsString(getAccessToken());
|
||||||
user = objectMapper.readValue(accessTokenString, KeycloakUser.class);
|
user = objectMapper.readValue(accessTokenString, KeycloakUser.class);
|
||||||
user.setRoles(getRoles());
|
user.setRoles(getRoles());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue