|
|
|
@ -23,6 +23,10 @@ import io.entgra.device.mgt.core.apimgt.application.extension.APIManagementProvi
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.APIManagementProviderServiceImpl;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.keymgt.extension.DCRResponse;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.keymgt.extension.TokenRequest;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.keymgt.extension.TokenResponse;
|
|
|
|
@ -794,21 +798,27 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
String applicationName = type.replace(" ", "").replace("_", "")
|
|
|
|
|
+ "_" + tenantDomain;
|
|
|
|
|
|
|
|
|
|
if (!username.contains("@")) {
|
|
|
|
|
username += "@" + tenantDomain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KeyMgtService keyMgtService = new KeyMgtServiceImpl();
|
|
|
|
|
try {
|
|
|
|
|
//todo - lasantha - can't get password from here
|
|
|
|
|
ApiApplicationKey apiApplicationKey;
|
|
|
|
|
try {
|
|
|
|
|
DCRResponse adminDCRResponse = keyMgtService.dynamicClientRegistration(applicationName,
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
|
.getRealmConfiguration().getAdminUserName(),
|
|
|
|
|
"client_credentials", null, new String[] {"device_management"}, false, validityTime, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
|
.getRealmConfiguration().getAdminPassword());
|
|
|
|
|
// DCRResponse adminDCRResponse = keyMgtService.dynamicClientRegistration("TestDevice01",
|
|
|
|
|
// PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
|
// .getRealmConfiguration().getAdminUserName(),
|
|
|
|
|
// "jwt", null, new String[] {"device_management"}, false, validityTime, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
|
// .getRealmConfiguration().getAdminPassword());
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
APIApplicationKey adminDCRResponse = apiApplicationServices.createAndRetrieveApplicationCredentials();
|
|
|
|
|
|
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
|
JWTClientManagerService jwtClientManagerService = (JWTClientManagerService) ctx.
|
|
|
|
@ -816,7 +826,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
|
JWTClient jwtClient = jwtClientManagerService.getJWTClient();
|
|
|
|
|
AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(adminDCRResponse.getClientId(),
|
|
|
|
|
adminDCRResponse.getClientSecret(),
|
|
|
|
|
username, "appm:subscribe");
|
|
|
|
|
username, "appm:subscribe apim:subscribe openid");
|
|
|
|
|
|
|
|
|
|
APIManagementProviderService apiManagementProviderService = DeviceMgtAPIUtils.getAPIManagementService();
|
|
|
|
|
apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(applicationName,
|
|
|
|
@ -828,7 +838,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
} catch (APIServicesException e) {
|
|
|
|
|
String msg = "Error while getting user credentials.";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|