feign_client_impl | Update the requested changes in PR comments.

pull/1/head
Tharusha Sandeepa 2 months ago
parent 7f549492a9
commit 25acefd4f4

@ -60,8 +60,8 @@ public class TokenService {
@Value("${refresh-token}")
private String refreshToken;
@Value("${jwt-token}")
private String jwtToken;
// @Value("${jwt-token}")
// private String jwtToken;
@Value("${saml2-assertion}")
private String saml2Assertion;
@ -100,11 +100,6 @@ public class TokenService {
switch (grantType) {
case "implicit":
return createErrorResponse(501,
"Not Implemented",
"Implicit grant type not handled directly.");
case "password":
authHeader = "Basic " + encodedAuth;
body = "grant_type=" + grantType + "&username=" + userName + "&password=" + password + "&scope=" + scope;
@ -120,10 +115,10 @@ public class TokenService {
body = "grant_type=refresh_token&refresh_token=" + refreshToken;
break;
case "urn:ietf:params:oauth:grant-type:jwt-bearer":
authHeader = "Basic " + encodedAuth;
body = "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=" + jwtToken;
break;
// case "urn:ietf:params:oauth:grant-type:jwt-bearer":
// authHeader = "Basic " + encodedAuth;
// body = "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=" + jwtToken;
// break;
case "urn:ietf:params:oauth:grant-type:saml2-bearer":
authHeader = "Basic " + encodedAuth;
@ -151,9 +146,9 @@ public class TokenService {
if (response != null) {
String accessToken = response.get("access_token");
if (accessToken != null) {
tokenDataHolder.setAccess_token(accessToken);
tokenDataHolder.setToken_type(response.get("token_type"));
tokenDataHolder.setExpires_in(Integer.parseInt(response.get("expires_in")));
tokenDataHolder.setAccessToken(accessToken);
tokenDataHolder.setTokenType(response.get("token_type"));
tokenDataHolder.setExpiresIn(Integer.parseInt(response.get("expires_in")));
tokenDataHolder.setScope(response.get("scope"));
log.info("Access token stored in the DataHolder");
return accessToken;
@ -165,10 +160,24 @@ public class TokenService {
}
}
} catch (FeignException e) {
log.error("Error while fetching token:{}", e.getMessage());
String errorMessage = e.getMessage();
if (errorMessage != null && errorMessage.contains("[401]")) {
log.error("Client credentials or client secret is incorrect: {}", errorMessage);
return createErrorResponse(500,
"Client Credentials Error",
"Client credentials or client secret is incorrect.");
} else if (errorMessage.contains("Connection refused")) {
log.error("Resource server is not working: {}", errorMessage);
return createErrorResponse(500,
"Resource Server Error",
"Resource server is not working.");
} else {
log.error("Error while fetching token: {}", errorMessage);
return createErrorResponse(500,
"Feign Client Error",
e.getMessage());
errorMessage); // Return the original Feign exception message if not matched
}
} catch (Exception e) {
log.error("An unexpected error occurred:{}", e.getMessage());
return createErrorResponse(500,

@ -25,8 +25,8 @@ import org.springframework.stereotype.Component;
@Component
public class TokenDataHolder {
private String access_token;
private String accessToken;
private String scope;
private int expires_in;
private String token_type;
private int expiresIn;
private String tokenType;
}

Loading…
Cancel
Save