Skip to content

Commit

Permalink
SelfTokenRestTemplate: Added config option to disable (#184)
Browse files Browse the repository at this point in the history
Signed-off-by: Lalith Kota <[email protected]>
  • Loading branch information
lalithkota committed Mar 21, 2024
1 parent 789181e commit 65d1140
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main/java/io/mosip/mimoto/util/RestApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public class RestApiClient {
@Value("${mosip.iam.adapter.appid}")
private String appId;

@Value("${mosip.iam.adapter.disable-self-token-rest-template:false}")
private boolean disableSelfTokenRestTemplate;

@Autowired
Environment environment;

Expand All @@ -90,9 +93,13 @@ public class RestApiClient {
@SuppressWarnings("unchecked")
public <T> T getApi(URI uri, Class<?> responseType) throws Exception {
T result = null;
RestTemplate rt = restTemplate;
if (disableSelfTokenRestTemplate) {
rt = plainRestTemplate;
}
try {
logger.info("RestApiClient::getApi()::entry uri: {}", uri);
result = (T) restTemplate.exchange(uri, HttpMethod.GET, setRequestHeader(null, null), responseType)
result = (T) rt.exchange(uri, HttpMethod.GET, setRequestHeader(null, null), responseType)
.getBody();
} catch (Exception e) {
logger.error("RestApiClient::getApi()::error uri: {} {} {}", uri, e.getMessage(), e);
Expand All @@ -111,8 +118,12 @@ public <T> T getApi(URI uri, Class<?> responseType) throws Exception {
@SuppressWarnings("unchecked")
public <T> T getApi(String url, Class<?> responseType) {
T result = null;
RestTemplate rt = restTemplate;
if (disableSelfTokenRestTemplate) {
rt = plainRestTemplate;
}
try {
result = (T) restTemplate.getForObject(url, responseType);
result = (T) rt.getForObject(url, responseType);
} catch (Exception e) {
logger.error("RestApiClient::getApi()::error uri:{} {} {}", url, e.getMessage(), e);
}
Expand All @@ -133,9 +144,13 @@ public <T> T getApi(String url, Class<?> responseType) {
@SuppressWarnings("unchecked")
public <T> T postApi(String uri, MediaType mediaType, Object requestType, Class<?> responseClass) throws Exception {
T result = null;
RestTemplate rt = restTemplate;
if (disableSelfTokenRestTemplate) {
rt = plainRestTemplate;
}
try {
logger.info("RestApiClient::postApi()::entry uri: {}", uri);
result = (T) restTemplate.postForObject(uri, setRequestHeader(requestType, mediaType), responseClass);
result = (T) rt.postForObject(uri, setRequestHeader(requestType, mediaType), responseClass);
} catch (Exception e) {
logger.error("RestApiClient::postApi()::error uri: {} {} {}", uri, e.getMessage(), e);
}
Expand Down

0 comments on commit 65d1140

Please sign in to comment.