mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-16 19:28:21 +00:00
Fix user creation through openmetadata-ops.sh (#23879)
This commit is contained in:
parent
a3e5190f69
commit
949cc32eef
@ -54,4 +54,5 @@ else
|
||||
fi
|
||||
|
||||
${JAVA} -Dbootstrap.dir=$BOOTSTRAP_DIR -cp ${CLASSPATH} ${OPENMETADATA_SETUP_MAIN_CLASS} -c $CONFIG_FILE_PATH "$@"
|
||||
exit $?
|
||||
|
||||
|
@ -436,17 +436,18 @@ public class OpenMetadataOperations implements Callable<Integer> {
|
||||
throw new IllegalArgumentException("Invalid email address: " + email);
|
||||
}
|
||||
parseConfig();
|
||||
initializeCollectionRegistry();
|
||||
initializeSecurityConfig();
|
||||
AuthProvider authProvider = SecurityConfigurationManager.getCurrentAuthConfig().getProvider();
|
||||
if (!authProvider.equals(AuthProvider.BASIC)) {
|
||||
LOG.error("Authentication is not set to basic. User creation is not supported.");
|
||||
return 1;
|
||||
}
|
||||
initializeCollectionRegistry();
|
||||
UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
|
||||
try {
|
||||
userRepository.getByEmail(null, email, EntityUtil.Fields.EMPTY_FIELDS);
|
||||
LOG.error("User {} already exists.", email);
|
||||
return 1;
|
||||
LOG.info("User {} already exists.", email);
|
||||
return 0;
|
||||
} catch (EntityNotFoundException ex) {
|
||||
// Expected – continue to create the user.
|
||||
}
|
||||
@ -477,6 +478,29 @@ public class OpenMetadataOperations implements Callable<Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeSecurityConfig() {
|
||||
try {
|
||||
var authConfig =
|
||||
Entity.getSystemRepository()
|
||||
.getConfigWithKey(SettingsType.AUTHENTICATION_CONFIGURATION.value());
|
||||
if (authConfig != null) {
|
||||
SecurityConfigurationManager.getInstance()
|
||||
.setCurrentAuthConfig(
|
||||
JsonUtils.convertValue(
|
||||
authConfig.getConfigValue(),
|
||||
org.openmetadata.schema.api.security.AuthenticationConfiguration.class));
|
||||
} else if (config.getAuthenticationConfiguration() != null) {
|
||||
SecurityConfigurationManager.getInstance()
|
||||
.setCurrentAuthConfig(config.getAuthenticationConfiguration());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (config.getAuthenticationConfiguration() != null) {
|
||||
SecurityConfigurationManager.getInstance()
|
||||
.setCurrentAuthConfig(config.getAuthenticationConfiguration());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAppInstalled(AppRepository appRepository, String appName) {
|
||||
try {
|
||||
appRepository.findByName(appName, Include.NON_DELETED);
|
||||
|
@ -37,6 +37,7 @@ import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.jdbi3.AppRepository;
|
||||
import org.openmetadata.service.jdbi3.CollectionDAO;
|
||||
import org.openmetadata.service.search.IndexMappingVersionTracker;
|
||||
import org.openmetadata.service.security.auth.SecurityConfigurationManager;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@Slf4j
|
||||
@ -234,6 +235,22 @@ public class OpenMetadataOperationsTest {
|
||||
"Should update versions after successful reindexing");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateUser_NullAuthConfigThrowsException() throws Exception {
|
||||
try (MockedStatic<SecurityConfigurationManager> securityManagerMock =
|
||||
Mockito.mockStatic(SecurityConfigurationManager.class)) {
|
||||
securityManagerMock.when(SecurityConfigurationManager::getCurrentAuthConfig).thenReturn(null);
|
||||
|
||||
OpenMetadataOperations ops = new OpenMetadataOperations();
|
||||
char[] password = "testPassword123".toCharArray();
|
||||
String email = "test@example.com";
|
||||
|
||||
int result = ops.createUser(email, password, false);
|
||||
|
||||
assertEquals(1, result);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper methods using reflection to access private fields for testing
|
||||
private String getVersionFromTracker(IndexMappingVersionTracker tracker) throws Exception {
|
||||
Field versionField = IndexMappingVersionTracker.class.getDeclaredField("version");
|
||||
|
Loading…
x
Reference in New Issue
Block a user