Fix dynamic client registration bugs

apim420
Lasantha Dharmakeerthi 12 months ago
commit 11aac018cc

@ -221,6 +221,7 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
.getTenantDomain(); .getTenantDomain();
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
String[] tags = {VirtualFireAlarmConstants.DEVICE_TYPE}; String[] tags = {VirtualFireAlarmConstants.DEVICE_TYPE};
ArrayList<String> supportedGrantTypes = new ArrayList<>();
try { try {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantAdminDomainName); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantAdminDomainName);
@ -230,7 +231,8 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true, VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true,
VirtualFireAlarmConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD, null); VirtualFireAlarmConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD, null, null,
supportedGrantTypes, null, false);
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }

@ -43,7 +43,9 @@ import io.entgra.device.mgt.core.identity.jwt.client.extension.exception.JWTClie
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class MQTTAdapterListener implements MqttCallback, Runnable { public class MQTTAdapterListener implements MqttCallback, Runnable {
@ -129,6 +131,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
String password = this.mqttBrokerConnectionConfiguration.getPassword(); String password = this.mqttBrokerConnectionConfiguration.getPassword();
String dcrUrlString = this.mqttBrokerConnectionConfiguration.getDcrUrl(); String dcrUrlString = this.mqttBrokerConnectionConfiguration.getDcrUrl();
String scopes = this.mqttBrokerConnectionConfiguration.getBrokerScopes(); String scopes = this.mqttBrokerConnectionConfiguration.getBrokerScopes();
List<String> supportedGrantTypes = new ArrayList<>();
//getJWT Client Parameters. //getJWT Client Parameters.
if (dcrUrlString != null && !dcrUrlString.isEmpty()) { if (dcrUrlString != null && !dcrUrlString.isEmpty()) {
try { try {
@ -136,7 +139,8 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
String applicationName = MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX String applicationName = MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
+ mqttBrokerConnectionConfiguration.getAdapterName(); + mqttBrokerConnectionConfiguration.getAdapterName();
DCRResponse dcrResponse = keyMgtService.dynamicClientRegistration(applicationName, username, DCRResponse dcrResponse = keyMgtService.dynamicClientRegistration(applicationName, username,
"client_credentials", null, new String[]{"device_management"}, false, Integer.MAX_VALUE, password); "client_credentials", null, new String[]{"device_management"}, false, Integer.MAX_VALUE, password,
supportedGrantTypes, dcrUrlString);
String accessToken = getToken(dcrResponse.getClientId(), dcrResponse.getClientSecret()); String accessToken = getToken(dcrResponse.getClientId(), dcrResponse.getClientSecret());
connectionOptions.setUserName(accessToken.substring(0, 18)); connectionOptions.setUserName(accessToken.substring(0, 18));
connectionOptions.setPassword(accessToken.substring(19).toCharArray()); connectionOptions.setPassword(accessToken.substring(19).toCharArray());

@ -41,6 +41,9 @@ import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterExc
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterRuntimeException; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterRuntimeException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import java.util.ArrayList;
import java.util.List;
/** /**
* MQTT publisher related configuration initialization and publishing capabilties are implemented here. * MQTT publisher related configuration initialization and publishing capabilties are implemented here.
*/ */
@ -142,6 +145,7 @@ public class MQTTAdapterPublisher {
String username = this.mqttBrokerConnectionConfiguration.getUsername(); String username = this.mqttBrokerConnectionConfiguration.getUsername();
String password = this.mqttBrokerConnectionConfiguration.getPassword(); String password = this.mqttBrokerConnectionConfiguration.getPassword();
String dcrUrlString = this.mqttBrokerConnectionConfiguration.getDcrUrl(); String dcrUrlString = this.mqttBrokerConnectionConfiguration.getDcrUrl();
List<String> supportedGrantTypes = new ArrayList<>();
if (dcrUrlString != null && !dcrUrlString.isEmpty()) { if (dcrUrlString != null && !dcrUrlString.isEmpty()) {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
@ -151,7 +155,8 @@ public class MQTTAdapterPublisher {
String applicationName = MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX String applicationName = MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
+ mqttBrokerConnectionConfiguration.getAdapterName(); + mqttBrokerConnectionConfiguration.getAdapterName();
DCRResponse dcrResponse = keyMgtService.dynamicClientRegistration(applicationName, username, DCRResponse dcrResponse = keyMgtService.dynamicClientRegistration(applicationName, username,
"client_credentials", null, new String[]{"device_management"}, false, Integer.MAX_VALUE, password); "client_credentials", null, new String[]{"device_management"}, false, Integer.MAX_VALUE, password,
supportedGrantTypes, dcrUrlString);
return getToken(dcrResponse.getClientId(), dcrResponse.getClientSecret()); return getToken(dcrResponse.getClientId(), dcrResponse.getClientSecret());
// connectionOptions.setUserName(accessToken.substring(0, 18)); // connectionOptions.setUserName(accessToken.substring(0, 18));
// connectionOptions.setPassword(accessToken.substring(19).toCharArray()); // connectionOptions.setPassword(accessToken.substring(19).toCharArray());

Loading…
Cancel
Save