Fix configuration retrieval issue with non default admin credentials

feature/appm-store/pbac
Charitha Goonetilleke 5 years ago
parent 20dd0b88d2
commit cc2eccae5d

@ -35,6 +35,9 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.keymanager.KeyManagerConfigurations;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
@ -163,13 +166,13 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig
private void setAccessTokenToDeviceConfigurations(DeviceConfiguration devicesConfiguration)
throws DeviceManagementException {
try {
AppRegistrationCredentials credentials =
DeviceManagerUtil.getApplicationRegistrationCredentials(
System.getProperty(DeviceManagementConstants
.ConfigurationManagement.IOT_GATEWAY_HOST),
System.getProperty(DeviceManagementConstants
.ConfigurationManagement.IOT_GATEWAY_HTTPS_PORT),
DeviceManagementConstants.ConfigurationManagement.ADMIN_CREDENTIALS);
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
KeyManagerConfigurations kmConfig = deviceManagementConfig.getKeyManagerConfigurations();
AppRegistrationCredentials credentials = DeviceManagerUtil.getApplicationRegistrationCredentials(
System.getProperty(DeviceManagementConstants.ConfigurationManagement.IOT_GATEWAY_HOST),
System.getProperty(DeviceManagementConstants.ConfigurationManagement.IOT_GATEWAY_HTTPS_PORT),
kmConfig.getAdminUsername(),
kmConfig.getAdminPassword());
AccessTokenInfo accessTokenForAdmin = DeviceManagerUtil.getAccessTokenForDeviceOwner(
DeviceManagementConstants.ConfigurationManagement.SCOPES_FOR_TOKEN,
credentials.getClient_id(), credentials.getClient_secret(),

@ -31,11 +31,9 @@ public final class DeviceManagementConstants {
private ConfigurationManagement(){
throw new AssertionError();
}
public static final String ADMIN_CREDENTIALS = "admin:admin";
public static final String SCOPES_FOR_TOKEN = "perm:device:operations perm:device:publish-event";
public static final String IOT_GATEWAY_HOST = "iot.gateway.host";
public static final String IOT_GATEWAY_HTTPS_PORT = "iot.gateway.https.port";
public static final String MQTT_ENDPOINTS = "mqttEndpoints";
public static final String APPLICATION_REGISTRATION_API_ENDPOINT =
"/api-application-registration/register";
public static final String AUTHORIZATION_HEADER = "authorization";

@ -606,7 +606,7 @@ public final class DeviceManagerUtil {
*/
@SuppressWarnings("PackageAccessibility")
public static AppRegistrationCredentials getApplicationRegistrationCredentials(String host, String port,
String credentials)
String username, String password)
throws ApplicationRegistrationException {
if (host == null || port == null) {
String msg = "Required gatewayHost or gatewayPort system property is null";
@ -622,7 +622,7 @@ public final class DeviceManagerUtil {
apiEndpoint.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
apiEndpoint.setHeader(DeviceManagementConstants.ConfigurationManagement.AUTHORIZATION_HEADER,
DeviceManagementConstants.ConfigurationManagement.BASIC_AUTH.concat(" ")
.concat(getBase64EncodedCredentials(credentials)));
.concat(getBase64EncodedCredentials(username + ":" + password)));
apiEndpoint.setEntity(constructApplicationRegistrationPayload());
HttpResponse response = client.execute(apiEndpoint);
if (response != null) {

Loading…
Cancel
Save