Product/components used and version/fix level:
Cumulocity Production
Detailed explanation of the problem:
Hi, I have this microservice deployed on Cumulocity. I am calling REST Endpoints of Cumulocity to get all the users of the current Tenant, but I am getting unauthorized. Can you please tell me what am I doing wrong?
String auth = tenantId + "/" + name + ":" + pass;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", encodedAuth);
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
HttpEntity<String> entity = new HttpEntity<>(headers);
int currentPage = 1;
String path = String.format("/user/%s/users?currentPage=%s&pageSize=2000&withTotalPages=true", tenantId, currentPage);
String url = getCurrentTenant() + path;
logger.info("Fetching users for tenant {} , id {}, currentPage {}", getCurrentTenant(), tenantId, currentPage);
ResponseEntity<Map> response = restTemplate.exchange(
url,
HttpMethod.GET,
entity,
Map.class
);
When this call gets hit, I get unauthorized, i tried without passing the tenant id in username but i get the same error. i am calling this endpoint from a different service in local, however i tried to call via postman as well but got same issues. This user has admin role in cumulocity.
I get this erorr: org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 Unauthorized: "{"error":"security/Unauthorized","message":"Full authentication is required to access this resource","info":"https://cumulocity.com/guides/users-guide/getting-started/"}"
Can you please help me understand the cause?
Thanks,
Samanyu