Error Invalid credentials when using bootstrap user

Java Microservice on Cumulocity 10.17

I’m trying to make my java microservice dynamic and supports multi-tenancy, and therefore would like to get all tenants subscribed to the application and their service username/passwords.

In order to do that, I’m using for authentication the bootstrap username and password provided by the Autowired Environment. I’m doing a GET call to the endpoint: /application/currentApplication/subscriptions.

For that I’m also using the baseurl provided by the environment for the domain, for the request to look like this: GET http://cumulocity:8111/application/currentApplication/subscriptions HTTP/1.1.

I made sure that the username and password are the bootstrap correct credentials, and made sure when making the call from postman using the real tenant domain, I would get the needed response. But when hosting the microservice, when the http request is executed, I get back the 401 error: “error”:“security/Unauthorized”,“message”:“Invalid credentials!”. I tried doing the authentication using the credentials provider, and using the base64 header, but both ways returned the same error.

Could someone help me with what am I doing wrong here?

My suspicion is that you’re missing to specify the Tenant ID in the username. To be sure, try making the request with User {C8Y_BOOTSTRAP_TENANT}/{C8Y_BOOTSTRAP_USER}.

As you are using Java and probably the SDK, you could also take a look at MicroserviceSubscriptionsService. Below snippet should output all your services subscriptions:

@Component
public class OmarsService {
    @Autowired
    MicroserviceSubscriptionsService subscriptionsService;

    @EventListener
    public void onSubscriptionsInitialized(MicroserviceSubscriptionsInitializedEvent event) {
        log.info("Subscriptions initialized.");
        Collection<MicroserviceCredentials> allActiveSubscriptions = subscriptionsService.getAll();
        for(MicroserviceCredentials mc : allActiveSubscriptions){
            log.info("Tenant: " + mc.getTenant());
            log.info("User: " + mc.getUsername());
            log.info("Pass: " + mc.getPassword());
        }
        // execute some runnable on all tenants
        subscriptionService.runForEachTenant(...);
        // execute in specific tenant
        subscriptionService.runForTenant("t1234", ...);
    }
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.