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) {
|
||||
Set<String> invalids = new HashSet<>();
|
||||
List<Property> properties = datasourceConfiguration.getProperties();
|
||||
DBAuth authentication = (DBAuth) datasourceConfiguration.getAuthentication();
|
||||
if (isUsingURI(datasourceConfiguration)) {
|
||||
if (!hasNonEmptyURI(datasourceConfiguration)) {
|
||||
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) {
|
||||
invalids.add("Mongo Connection String URI does not seem to be in the correct format. " +
|
||||
"Please check the URI once.");
|
||||
} else {
|
||||
} else if (!isAuthenticated(authentication, mongoUri)) {
|
||||
String mongoUriWithHiddenPassword = buildURIfromExtractedInfo(extractedInfo, "****");
|
||||
properties.get(DATASOURCE_CONFIG_MONGO_URI_PROPERTY_INDEX).setValue(mongoUriWithHiddenPassword);
|
||||
DBAuth authentication = datasourceConfiguration.getAuthentication() == null ?
|
||||
new DBAuth() : (DBAuth) datasourceConfiguration.getAuthentication();
|
||||
authentication = (authentication == null) ? new DBAuth(): authentication;
|
||||
authentication.setUsername((String) extractedInfo.get(KEY_USERNAME));
|
||||
authentication.setPassword((String) extractedInfo.get(KEY_PASSWORD));
|
||||
authentication.setDatabaseName((String) extractedInfo.get(KEY_URI_DBNAME));
|
||||
|
|
@ -746,8 +746,7 @@ public class MongoPlugin extends BasePlugin {
|
|||
" directly.");
|
||||
}
|
||||
}
|
||||
|
||||
DBAuth authentication = (DBAuth) datasourceConfiguration.getAuthentication();
|
||||
|
||||
if (authentication != null) {
|
||||
DBAuth.Type authType = authentication.getAuthType();
|
||||
|
||||
|
|
@ -1013,5 +1012,14 @@ public class MongoPlugin extends BasePlugin {
|
|||
|
||||
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.ApplicationService;
|
||||
import com.appsmith.server.services.ConfigService;
|
||||
import com.appsmith.server.services.DatasourceContextService;
|
||||
import com.appsmith.server.services.DatasourceService;
|
||||
import com.appsmith.server.services.LayoutActionService;
|
||||
import com.appsmith.server.services.NewActionService;
|
||||
|
|
@ -60,7 +59,6 @@ public class ExamplesOrganizationCloner {
|
|||
private final UserService userService;
|
||||
private final ApplicationService applicationService;
|
||||
private final ApplicationPageService applicationPageService;
|
||||
private final DatasourceContextService datasourceContextService;
|
||||
private final NewPageRepository newPageRepository;
|
||||
private final NewActionService newActionService;
|
||||
private final LayoutActionService layoutActionService;
|
||||
|
|
@ -403,9 +401,7 @@ public class ExamplesOrganizationCloner {
|
|||
.switchIfEmpty(Mono.defer(() -> {
|
||||
// No matching existing datasource found, so create a new one.
|
||||
makePristine(templateDatasource);
|
||||
|
||||
templateDatasource.setOrganizationId(toOrganizationId);
|
||||
|
||||
return createSuffixedDatasource(templateDatasource);
|
||||
}));
|
||||
});
|
||||
|
|
@ -458,7 +454,7 @@ public class ExamplesOrganizationCloner {
|
|||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
// 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);
|
||||
public final String INVALID_JSON_FILE = "invalid json file";
|
||||
private enum PublishType {
|
||||
UNPUBLISH, PUBLISH
|
||||
UNPUBLISHED, PUBLISHED
|
||||
}
|
||||
|
||||
public Mono<ApplicationJson> exportApplicationById(String applicationId) {
|
||||
|
|
@ -141,7 +141,7 @@ public class ImportExportApplicationService {
|
|||
|
||||
if (newPage.getUnpublishedPage() != null) {
|
||||
pageIdToNameMap.put(
|
||||
newPage.getId() + PublishType.UNPUBLISH, newPage.getUnpublishedPage().getName()
|
||||
newPage.getId() + PublishType.UNPUBLISHED, newPage.getUnpublishedPage().getName()
|
||||
);
|
||||
PageDTO unpublishedPageDTO = newPage.getUnpublishedPage();
|
||||
if (StringUtils.equals(
|
||||
|
|
@ -160,7 +160,7 @@ public class ImportExportApplicationService {
|
|||
|
||||
if (newPage.getPublishedPage() != null) {
|
||||
pageIdToNameMap.put(
|
||||
newPage.getId() + PublishType.PUBLISH, newPage.getPublishedPage().getName()
|
||||
newPage.getId() + PublishType.PUBLISHED, newPage.getPublishedPage().getName()
|
||||
);
|
||||
PageDTO publishedPageDTO = newPage.getPublishedPage();
|
||||
if (applicationJson.getPublishedDefaultPageName() != null &&
|
||||
|
|
@ -215,11 +215,11 @@ public class ImportExportApplicationService {
|
|||
}
|
||||
if (newAction.getUnpublishedAction() != null) {
|
||||
ActionDTO actionDTO = newAction.getUnpublishedAction();
|
||||
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.UNPUBLISH));
|
||||
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.UNPUBLISHED));
|
||||
}
|
||||
if (newAction.getPublishedAction() != null) {
|
||||
ActionDTO actionDTO = newAction.getPublishedAction();
|
||||
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.PUBLISH));
|
||||
actionDTO.setPageId(pageIdToNameMap.get(actionDTO.getPageId() + PublishType.PUBLISHED));
|
||||
}
|
||||
});
|
||||
applicationJson
|
||||
|
|
@ -363,8 +363,8 @@ public class ImportExportApplicationService {
|
|||
.flatMap(savedApp -> {
|
||||
importedApplication.setId(savedApp.getId());
|
||||
Map<PublishType, List<ApplicationPage>> applicationPages = Map.of(
|
||||
PublishType.UNPUBLISH, new ArrayList<>(),
|
||||
PublishType.PUBLISH, new ArrayList<>()
|
||||
PublishType.UNPUBLISHED, new ArrayList<>(),
|
||||
PublishType.PUBLISHED, new ArrayList<>()
|
||||
);
|
||||
|
||||
return importAndSavePages(
|
||||
|
|
@ -396,16 +396,16 @@ public class ImportExportApplicationService {
|
|||
publishedAppPage.setId(newPage.getId());
|
||||
pageNameMap.put(newPage.getPublishedPage().getName(), newPage);
|
||||
}
|
||||
applicationPages.get(PublishType.UNPUBLISH).add(unpublishedAppPage);
|
||||
applicationPages.get(PublishType.PUBLISH).add(publishedAppPage);
|
||||
applicationPages.get(PublishType.UNPUBLISHED).add(unpublishedAppPage);
|
||||
applicationPages.get(PublishType.PUBLISHED).add(publishedAppPage);
|
||||
return applicationPages;
|
||||
})
|
||||
.then()
|
||||
.thenReturn(applicationPages);
|
||||
})
|
||||
.flatMap(applicationPageMap -> {
|
||||
importedApplication.setPages(applicationPageMap.get(PublishType.UNPUBLISH));
|
||||
importedApplication.setPublishedPages(applicationPageMap.get(PublishType.PUBLISH));
|
||||
importedApplication.setPages(applicationPageMap.get(PublishType.UNPUBLISHED));
|
||||
importedApplication.setPublishedPages(applicationPageMap.get(PublishType.PUBLISHED));
|
||||
|
||||
importedNewActionList.forEach(newAction -> {
|
||||
NewPage parentPage = new NewPage();
|
||||
|
|
|
|||
|
|
@ -473,6 +473,7 @@ public class ExamplesOrganizationClonerTests {
|
|||
final Datasource ds1 = new Datasource();
|
||||
ds1.setName("datasource 1");
|
||||
ds1.setOrganizationId(organization.getId());
|
||||
ds1.setPluginId(installedPlugin.getId());
|
||||
final DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
|
||||
ds1.setDatasourceConfiguration(datasourceConfiguration);
|
||||
datasourceConfiguration.setUrl("http://httpbin.org/get");
|
||||
|
|
@ -483,6 +484,7 @@ public class ExamplesOrganizationClonerTests {
|
|||
final Datasource ds2 = new Datasource();
|
||||
ds2.setName("datasource 2");
|
||||
ds2.setOrganizationId(organization.getId());
|
||||
ds2.setPluginId(installedPlugin.getId());
|
||||
ds2.setDatasourceConfiguration(new DatasourceConfiguration());
|
||||
DBAuth auth = new DBAuth();
|
||||
auth.setPassword("answer-to-life");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user