Bugfix for applications with MongoDB datasources authenticated with SRV string (#4944)
* Avoid updating authenticationDTO for mongo-plugin with SRV if the authentication object is already present
This commit is contained in:
parent
9c75596957
commit
0246563bd2
|
|
@ -688,6 +688,7 @@ public class MongoPlugin extends BasePlugin {
|
||||||
public Set<String> validateDatasource(DatasourceConfiguration datasourceConfiguration) {
|
public Set<String> validateDatasource(DatasourceConfiguration datasourceConfiguration) {
|
||||||
Set<String> invalids = new HashSet<>();
|
Set<String> invalids = new HashSet<>();
|
||||||
List<Property> properties = datasourceConfiguration.getProperties();
|
List<Property> properties = datasourceConfiguration.getProperties();
|
||||||
|
DBAuth authentication = (DBAuth) datasourceConfiguration.getAuthentication();
|
||||||
if (isUsingURI(datasourceConfiguration)) {
|
if (isUsingURI(datasourceConfiguration)) {
|
||||||
if (!hasNonEmptyURI(datasourceConfiguration)) {
|
if (!hasNonEmptyURI(datasourceConfiguration)) {
|
||||||
invalids.add("'Mongo Connection String URI' field is empty. Please edit the 'Mongo Connection " +
|
invalids.add("'Mongo Connection String URI' field is empty. Please edit the 'Mongo Connection " +
|
||||||
|
|
@ -702,11 +703,10 @@ public class MongoPlugin extends BasePlugin {
|
||||||
if (extractedInfo == null) {
|
if (extractedInfo == null) {
|
||||||
invalids.add("Mongo Connection String URI does not seem to be in the correct format. " +
|
invalids.add("Mongo Connection String URI does not seem to be in the correct format. " +
|
||||||
"Please check the URI once.");
|
"Please check the URI once.");
|
||||||
} else {
|
} else if (!isAuthenticated(authentication, mongoUri)) {
|
||||||
String mongoUriWithHiddenPassword = buildURIfromExtractedInfo(extractedInfo, "****");
|
String mongoUriWithHiddenPassword = buildURIfromExtractedInfo(extractedInfo, "****");
|
||||||
properties.get(DATASOURCE_CONFIG_MONGO_URI_PROPERTY_INDEX).setValue(mongoUriWithHiddenPassword);
|
properties.get(DATASOURCE_CONFIG_MONGO_URI_PROPERTY_INDEX).setValue(mongoUriWithHiddenPassword);
|
||||||
DBAuth authentication = datasourceConfiguration.getAuthentication() == null ?
|
authentication = (authentication == null) ? new DBAuth(): authentication;
|
||||||
new DBAuth() : (DBAuth) datasourceConfiguration.getAuthentication();
|
|
||||||
authentication.setUsername((String) extractedInfo.get(KEY_USERNAME));
|
authentication.setUsername((String) extractedInfo.get(KEY_USERNAME));
|
||||||
authentication.setPassword((String) extractedInfo.get(KEY_PASSWORD));
|
authentication.setPassword((String) extractedInfo.get(KEY_PASSWORD));
|
||||||
authentication.setDatabaseName((String) extractedInfo.get(KEY_URI_DBNAME));
|
authentication.setDatabaseName((String) extractedInfo.get(KEY_URI_DBNAME));
|
||||||
|
|
@ -746,8 +746,7 @@ public class MongoPlugin extends BasePlugin {
|
||||||
" directly.");
|
" directly.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DBAuth authentication = (DBAuth) datasourceConfiguration.getAuthentication();
|
|
||||||
if (authentication != null) {
|
if (authentication != null) {
|
||||||
DBAuth.Type authType = authentication.getAuthType();
|
DBAuth.Type authType = authentication.getAuthType();
|
||||||
|
|
||||||
|
|
@ -1013,5 +1012,14 @@ public class MongoPlugin extends BasePlugin {
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAuthenticated(DBAuth authentication, String mongoUri) {
|
||||||
|
if (authentication != null && authentication.getUsername() != null
|
||||||
|
&& authentication.getPassword() != null && mongoUri.contains("****")) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import com.appsmith.server.repositories.OrganizationRepository;
|
||||||
import com.appsmith.server.services.ApplicationPageService;
|
import com.appsmith.server.services.ApplicationPageService;
|
||||||
import com.appsmith.server.services.ApplicationService;
|
import com.appsmith.server.services.ApplicationService;
|
||||||
import com.appsmith.server.services.ConfigService;
|
import com.appsmith.server.services.ConfigService;
|
||||||
import com.appsmith.server.services.DatasourceContextService;
|
|
||||||
import com.appsmith.server.services.DatasourceService;
|
import com.appsmith.server.services.DatasourceService;
|
||||||
import com.appsmith.server.services.LayoutActionService;
|
import com.appsmith.server.services.LayoutActionService;
|
||||||
import com.appsmith.server.services.NewActionService;
|
import com.appsmith.server.services.NewActionService;
|
||||||
|
|
@ -60,7 +59,6 @@ public class ExamplesOrganizationCloner {
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final ApplicationService applicationService;
|
private final ApplicationService applicationService;
|
||||||
private final ApplicationPageService applicationPageService;
|
private final ApplicationPageService applicationPageService;
|
||||||
private final DatasourceContextService datasourceContextService;
|
|
||||||
private final NewPageRepository newPageRepository;
|
private final NewPageRepository newPageRepository;
|
||||||
private final NewActionService newActionService;
|
private final NewActionService newActionService;
|
||||||
private final LayoutActionService layoutActionService;
|
private final LayoutActionService layoutActionService;
|
||||||
|
|
@ -403,9 +401,7 @@ public class ExamplesOrganizationCloner {
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
.switchIfEmpty(Mono.defer(() -> {
|
||||||
// No matching existing datasource found, so create a new one.
|
// No matching existing datasource found, so create a new one.
|
||||||
makePristine(templateDatasource);
|
makePristine(templateDatasource);
|
||||||
|
|
||||||
templateDatasource.setOrganizationId(toOrganizationId);
|
templateDatasource.setOrganizationId(toOrganizationId);
|
||||||
|
|
||||||
return createSuffixedDatasource(templateDatasource);
|
return createSuffixedDatasource(templateDatasource);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
@ -458,7 +454,7 @@ public class ExamplesOrganizationCloner {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void makePristine(BaseDomain domain) {
|
public void makePristine(BaseDomain domain) {
|
||||||
// Set the ID to null for this domain object so that it is saved a new document in the database (as opposed to
|
// Set the ID to null for this domain object so that it is saved a new document in the database (as opposed to
|
||||||
// updating an existing document). If it contains any policies, they are also reset.
|
// updating an existing document). If it contains any policies, they are also reset.
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class ImportExportApplicationService {
|
||||||
private static final Set<MediaType> ALLOWED_CONTENT_TYPES = Set.of(MediaType.APPLICATION_JSON);
|
private static final Set<MediaType> ALLOWED_CONTENT_TYPES = Set.of(MediaType.APPLICATION_JSON);
|
||||||
public final String INVALID_JSON_FILE = "invalid json file";
|
public final String INVALID_JSON_FILE = "invalid json file";
|
||||||
private enum PublishType {
|
private enum PublishType {
|
||||||
UNPUBLISH, PUBLISH
|
UNPUBLISHED, PUBLISHED
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<ApplicationJson> exportApplicationById(String applicationId) {
|
public Mono<ApplicationJson> exportApplicationById(String applicationId) {
|
||||||
|
|
@ -141,7 +141,7 @@ public class ImportExportApplicationService {
|
||||||
|
|
||||||
if (newPage.getUnpublishedPage() != null) {
|
if (newPage.getUnpublishedPage() != null) {
|
||||||
pageIdToNameMap.put(
|
pageIdToNameMap.put(
|
||||||
newPage.getId() + PublishType.UNPUBLISH, newPage.getUnpublishedPage().getName()
|
newPage.getId() + PublishType.UNPUBLISHED, newPage.getUnpublishedPage().getName()
|
||||||
);
|
);
|
||||||
PageDTO unpublishedPageDTO = newPage.getUnpublishedPage();
|
PageDTO unpublishedPageDTO = newPage.getUnpublishedPage();
|
||||||
if (StringUtils.equals(
|
if (StringUtils.equals(
|
||||||
|
|
@ -160,7 +160,7 @@ public class ImportExportApplicationService {
|
||||||
|
|
||||||
if (newPage.getPublishedPage() != null) {
|
if (newPage.getPublishedPage() != null) {
|
||||||
pageIdToNameMap.put(
|
pageIdToNameMap.put(
|
||||||
newPage.getId() + PublishType.PUBLISH, newPage.getPublishedPage().getName()
|
newPage.getId() + PublishType.PUBLISHED, newPage.getPublishedPage().getName()
|
||||||
);
|
);
|
||||||
PageDTO publishedPageDTO = newPage.getPublishedPage();
|
PageDTO publishedPageDTO = newPage.getPublishedPage();
|
||||||
if (applicationJson.getPublishedDefaultPageName() != null &&
|
if (applicationJson.getPublishedDefaultPageName() != null &&
|
||||||
|
|
@ -215,11 +215,11 @@ public class ImportExportApplicationService {
|
||||||
}
|
}
|
||||||
if (newAction.getUnpublishedAction() != null) {
|
if (newAction.getUnpublishedAction() != null) {
|
||||||
ActionDTO actionDTO = newAction.getUnpublishedAction();
|
ActionDTO actionDTO = newAction.getUnpublishedAction();
|
||||||
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.UNPUBLISH));
|
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.UNPUBLISHED));
|
||||||
}
|
}
|
||||||
if (newAction.getPublishedAction() != null) {
|
if (newAction.getPublishedAction() != null) {
|
||||||
ActionDTO actionDTO = newAction.getPublishedAction();
|
ActionDTO actionDTO = newAction.getPublishedAction();
|
||||||
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.PUBLISH));
|
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.PUBLISHED));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
applicationJson
|
applicationJson
|
||||||
|
|
@ -363,8 +363,8 @@ public class ImportExportApplicationService {
|
||||||
.flatMap(savedApp -> {
|
.flatMap(savedApp -> {
|
||||||
importedApplication.setId(savedApp.getId());
|
importedApplication.setId(savedApp.getId());
|
||||||
Map<PublishType, List<ApplicationPage>> applicationPages = Map.of(
|
Map<PublishType, List<ApplicationPage>> applicationPages = Map.of(
|
||||||
PublishType.UNPUBLISH, new ArrayList<>(),
|
PublishType.UNPUBLISHED, new ArrayList<>(),
|
||||||
PublishType.PUBLISH, new ArrayList<>()
|
PublishType.PUBLISHED, new ArrayList<>()
|
||||||
);
|
);
|
||||||
|
|
||||||
return importAndSavePages(
|
return importAndSavePages(
|
||||||
|
|
@ -396,16 +396,16 @@ public class ImportExportApplicationService {
|
||||||
publishedAppPage.setId(newPage.getId());
|
publishedAppPage.setId(newPage.getId());
|
||||||
pageNameMap.put(newPage.getPublishedPage().getName(), newPage);
|
pageNameMap.put(newPage.getPublishedPage().getName(), newPage);
|
||||||
}
|
}
|
||||||
applicationPages.get(PublishType.UNPUBLISH).add(unpublishedAppPage);
|
applicationPages.get(PublishType.UNPUBLISHED).add(unpublishedAppPage);
|
||||||
applicationPages.get(PublishType.PUBLISH).add(publishedAppPage);
|
applicationPages.get(PublishType.PUBLISHED).add(publishedAppPage);
|
||||||
return applicationPages;
|
return applicationPages;
|
||||||
})
|
})
|
||||||
.then()
|
.then()
|
||||||
.thenReturn(applicationPages);
|
.thenReturn(applicationPages);
|
||||||
})
|
})
|
||||||
.flatMap(applicationPageMap -> {
|
.flatMap(applicationPageMap -> {
|
||||||
importedApplication.setPages(applicationPageMap.get(PublishType.UNPUBLISH));
|
importedApplication.setPages(applicationPageMap.get(PublishType.UNPUBLISHED));
|
||||||
importedApplication.setPublishedPages(applicationPageMap.get(PublishType.PUBLISH));
|
importedApplication.setPublishedPages(applicationPageMap.get(PublishType.PUBLISHED));
|
||||||
|
|
||||||
importedNewActionList.forEach(newAction -> {
|
importedNewActionList.forEach(newAction -> {
|
||||||
NewPage parentPage = new NewPage();
|
NewPage parentPage = new NewPage();
|
||||||
|
|
|
||||||
|
|
@ -473,6 +473,7 @@ public class ExamplesOrganizationClonerTests {
|
||||||
final Datasource ds1 = new Datasource();
|
final Datasource ds1 = new Datasource();
|
||||||
ds1.setName("datasource 1");
|
ds1.setName("datasource 1");
|
||||||
ds1.setOrganizationId(organization.getId());
|
ds1.setOrganizationId(organization.getId());
|
||||||
|
ds1.setPluginId(installedPlugin.getId());
|
||||||
final DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
|
final DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
|
||||||
ds1.setDatasourceConfiguration(datasourceConfiguration);
|
ds1.setDatasourceConfiguration(datasourceConfiguration);
|
||||||
datasourceConfiguration.setUrl("http://httpbin.org/get");
|
datasourceConfiguration.setUrl("http://httpbin.org/get");
|
||||||
|
|
@ -483,6 +484,7 @@ public class ExamplesOrganizationClonerTests {
|
||||||
final Datasource ds2 = new Datasource();
|
final Datasource ds2 = new Datasource();
|
||||||
ds2.setName("datasource 2");
|
ds2.setName("datasource 2");
|
||||||
ds2.setOrganizationId(organization.getId());
|
ds2.setOrganizationId(organization.getId());
|
||||||
|
ds2.setPluginId(installedPlugin.getId());
|
||||||
ds2.setDatasourceConfiguration(new DatasourceConfiguration());
|
ds2.setDatasourceConfiguration(new DatasourceConfiguration());
|
||||||
DBAuth auth = new DBAuth();
|
DBAuth auth = new DBAuth();
|
||||||
auth.setPassword("answer-to-life");
|
auth.setPassword("answer-to-life");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user