Improvements in App registration flow

Pasindu Rupasinghe 1 year ago
parent bc97c6e212
commit a21fc35860

@ -230,7 +230,8 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true,
VirtualFireAlarmConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD, null);
VirtualFireAlarmConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD, null, null,
null, null , false);
} finally {
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.utils.multitenancy.MultitenantConstants;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MQTTAdapterListener implements MqttCallback, Runnable {
@ -129,6 +131,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
String password = this.mqttBrokerConnectionConfiguration.getPassword();
String dcrUrlString = this.mqttBrokerConnectionConfiguration.getDcrUrl();
String scopes = this.mqttBrokerConnectionConfiguration.getBrokerScopes();
List<String> supportedGrantTypes = this.mqttBrokerConnectionConfiguration.getSupportedGrantTypes();
//getJWT Client Parameters.
if (dcrUrlString != null && !dcrUrlString.isEmpty()) {
try {
@ -136,7 +139,8 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
String applicationName = MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
+ mqttBrokerConnectionConfiguration.getAdapterName();
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());
connectionOptions.setUserName(accessToken.substring(0, 18));
connectionOptions.setPassword(accessToken.substring(19).toCharArray());

@ -20,6 +20,8 @@ package io.entgra.device.mgt.plugins.input.adapter.mqtt.util;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration;
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
@ -38,6 +40,7 @@ public class MQTTBrokerConnectionConfiguration {
private String contentTransformerType;
private String adapterName;
private boolean globalCredentailSet;
private List<String> supportedGrantTypes;
public String getBrokerScopes() {
return brokerScopes;
@ -83,6 +86,14 @@ public class MQTTBrokerConnectionConfiguration {
return adapterName;
}
public List<String> getSupportedGrantTypes() {
return supportedGrantTypes;
}
public void setSupportedGrantTypes(List<String> supportedGrantTypes) {
this.supportedGrantTypes = supportedGrantTypes;
}
public MQTTBrokerConnectionConfiguration(InputEventAdapterConfiguration eventAdapterConfiguration,
Map<String, String> globalProperties) throws InputEventAdapterException {

@ -50,6 +50,9 @@ import io.entgra.device.mgt.core.identity.jwt.client.extension.exception.JWTClie
import io.entgra.device.mgt.core.identity.jwt.client.extension.service.JWTClientManagerService;
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.
*/
@ -151,6 +154,7 @@ public class MQTTAdapterPublisher {
String username = this.mqttBrokerConnectionConfiguration.getUsername();
String password = this.mqttBrokerConnectionConfiguration.getPassword();
String dcrUrlString = this.mqttBrokerConnectionConfiguration.getDcrUrl();
List<String> supportedGrantTypes = this.mqttBrokerConnectionConfiguration.getSupportedGrantTypes();
if (dcrUrlString != null && !dcrUrlString.isEmpty()) {
try {
@ -158,7 +162,8 @@ public class MQTTAdapterPublisher {
String applicationName = MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
+ mqttBrokerConnectionConfiguration.getAdapterName();
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());
// connectionOptions.setUserName(accessToken.substring(0, 18));
// connectionOptions.setPassword(accessToken.substring(19).toCharArray());

@ -20,6 +20,7 @@ package io.entgra.device.mgt.plugins.output.adapter.mqtt.util;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
import java.util.List;
import java.util.Map;
public class MQTTBrokerConnectionConfiguration {
@ -35,6 +36,7 @@ public class MQTTBrokerConnectionConfiguration {
private int keepAlive;
private boolean globalCredentailSet;
private int qos;
private List<String> supportedGrantTypes;
public String getTokenUrl() {
return tokenUrl;
@ -79,6 +81,16 @@ public class MQTTBrokerConnectionConfiguration {
public int getQos() {
return qos;
}
public List<String> getSupportedGrantTypes() {
return supportedGrantTypes;
}
public void setSupportedGrantTypes(List<String> supportedGrantTypes) {
this.supportedGrantTypes = supportedGrantTypes;
}
public MQTTBrokerConnectionConfiguration(OutputEventAdapterConfiguration eventAdapterConfiguration,
Map<String, String> globalProperties) {
adapterName = eventAdapterConfiguration.getName();

Loading…
Cancel
Save