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

@ -31,11 +31,9 @@ public final class DeviceManagementConstants {
private ConfigurationManagement(){ private ConfigurationManagement(){
throw new AssertionError(); 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 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_HOST = "iot.gateway.host";
public static final String IOT_GATEWAY_HTTPS_PORT = "iot.gateway.https.port"; 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 = public static final String APPLICATION_REGISTRATION_API_ENDPOINT =
"/api-application-registration/register"; "/api-application-registration/register";
public static final String AUTHORIZATION_HEADER = "authorization"; public static final String AUTHORIZATION_HEADER = "authorization";

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

Loading…
Cancel
Save