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

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

Loading…
Cancel
Save