类com.mongodb.AuthenticationMechanism源码实例Demo

下面列出了怎么用com.mongodb.AuthenticationMechanism的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Quicksql   文件: MongoSchemaFactory.java
private MongoCredential createCredentials(Map<String, Object> map) {
  final String authMechanismName = (String) map.get("authMechanism");
  final AuthenticationMechanism authenticationMechanism =
      AuthenticationMechanism.fromMechanismName(authMechanismName);
  final String username = (String) map.get("userName");
  final String authDatabase = (String) map.get("dbName");
  final String password = (String) map.get("password");

  switch (authenticationMechanism) {
  case PLAIN:
    return MongoCredential.createPlainCredential(username, authDatabase,
        password.toCharArray());
  case SCRAM_SHA_1:
    return MongoCredential.createScramSha1Credential(username, authDatabase,
        password.toCharArray());
  case GSSAPI:
    return MongoCredential.createGSSAPICredential(username);
  case MONGODB_CR:
    return MongoCredential.createMongoCRCredential(username, authDatabase,
        password.toCharArray());
  case MONGODB_X509:
    return MongoCredential.createMongoX509Credential(username);
  }
  throw new IllegalArgumentException("Unsupported authentication mechanism "
      + authMechanismName);
}
 
源代码2 项目: calcite   文件: MongoSchemaFactory.java
private MongoCredential createCredential(Map<String, Object> map) {
  final String authMechanismName = (String) map.get("authMechanism");
  final AuthenticationMechanism authenticationMechanism =
      AuthenticationMechanism.fromMechanismName(authMechanismName);
  final String username = (String) map.get("username");
  final String authDatabase = (String) map.get("authDatabase");
  final String password = (String) map.get("password");

  switch (authenticationMechanism) {
  case PLAIN:
    return MongoCredential.createPlainCredential(username, authDatabase,
        password.toCharArray());
  case SCRAM_SHA_1:
    return MongoCredential.createScramSha1Credential(username, authDatabase,
        password.toCharArray());
  case SCRAM_SHA_256:
    return MongoCredential.createScramSha256Credential(username, authDatabase,
        password.toCharArray());
  case GSSAPI:
    return MongoCredential.createGSSAPICredential(username);
  case MONGODB_X509:
    return MongoCredential.createMongoX509Credential(username);
  }
  throw new IllegalArgumentException("Unsupported authentication mechanism "
      + authMechanismName);
}
 
@Test
public void testAuth_GSSAPI() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("authSource", authSource);
  config.put("authMechanism", "GSSAPI");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertNotEquals(authSource, credential.getSource()); // It should ignore the source we pass in

  assertEquals(AuthenticationMechanism.GSSAPI, credential.getAuthenticationMechanism());
}
 
@Test
public void testAuth_GSSAPI_WithServiceName() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String authSource = TestUtils.randomAlphaString(10);
  String serviceName = TestUtils.randomAlphaString(11);
  config.put("username", username);
  config.put("authSource", authSource);
  config.put("authMechanism", "GSSAPI");
  config.put("gssapiServiceName", serviceName);

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertNotEquals(authSource, credential.getSource()); // It should ignore the source we pass in

  assertEquals(AuthenticationMechanism.GSSAPI, credential.getAuthenticationMechanism());
  assertEquals(serviceName, credential.getMechanismProperty("SERVICE_NAME", null));
}
 
@Test
public void testAuth_PLAIN() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("password", password);
  config.put("authSource", authSource);
  config.put("authMechanism", "PLAIN");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  assertEquals(authSource, credential.getSource());

  assertEquals(AuthenticationMechanism.PLAIN, credential.getAuthenticationMechanism());
}
 
@Test
public void testAuth_MONGODB_X509() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("authSource", authSource);
  config.put("authMechanism", "MONGODB-X509");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertNotEquals(authSource, credential.getSource()); // It should ignore the source we pass in

  assertEquals(AuthenticationMechanism.MONGODB_X509, credential.getAuthenticationMechanism());
}
 
@Test
public void testAuth_SCRAM_SHA_1() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("password", password);
  config.put("authSource", authSource);
  config.put("authMechanism", "SCRAM-SHA-1");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  assertEquals(authSource, credential.getSource());

  assertEquals(AuthenticationMechanism.SCRAM_SHA_1, credential.getAuthenticationMechanism());
}
 
@Test
public void testAuth_SCRAM_SHA_256() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("password", password);
  config.put("authSource", authSource);
  config.put("authMechanism", "SCRAM-SHA-256");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  assertEquals(authSource, credential.getSource());

  assertEquals(AuthenticationMechanism.SCRAM_SHA_256, credential.getAuthenticationMechanism());
}
 
源代码9 项目: nosql4idea   文件: MongoAuthenticationPanel.java
@Override
public void load(AuthenticationSettings settings) {
    usernameField.setText(settings.getUsername());
    passwordField.setText(settings.getPassword());
    MongoExtraSettings mongoExtraSettings = new MongoExtraSettings(settings.getExtras());
    authenticationDatabaseField.setText(mongoExtraSettings.getAuthenticationDatabase());
    sslConnectionField.setSelected(mongoExtraSettings.isSsl());
    AuthenticationMechanism authentificationMethod = mongoExtraSettings.getAuthenticationMechanism();
    if (AuthenticationMechanism.MONGODB_CR.equals(authentificationMethod)) {
        mongoCRAuthRadioButton.setSelected(true);
    } else if (AuthenticationMechanism.SCRAM_SHA_1.equals(authentificationMethod)) {
        scramSHA1AuthRadioButton.setSelected(true);
    } else {
        defaultAuthMethodRadioButton.setSelected(true);
    }
}
 
源代码10 项目: quarkus   文件: MongoClients.java
private AuthenticationMechanism getAuthenticationMechanism(String authMechanism) {
    AuthenticationMechanism mechanism;
    try {
        mechanism = AuthenticationMechanism.fromMechanismName(authMechanism.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Invalid authMechanism '" + authMechanism + "'");
    }
    return mechanism;
}
 
源代码11 项目: jpa-unit   文件: KunderaConfigurationTest.java
@Test
public void testMongoCredentials() {
    // GIVEN
    final Map<String, Object> properties = new HashMap<>();
    when(descriptor.getProperties()).thenReturn(properties);

    properties.put("kundera.keyspace", "foo");
    properties.put("kundera.username", "user");
    properties.put("kundera.password", "pass");

    final ConfigurationFactory factory = new ConfigurationFactoryImpl();

    // WHEN
    final Configuration configuration = factory.createConfiguration(descriptor);

    // THEN
    assertThat(configuration, notNullValue());

    final List<MongoCredential> credentials = configuration.getCredentials();
    assertThat(credentials, notNullValue());
    assertThat(credentials.size(), equalTo(1));

    final MongoCredential mongoCredential = credentials.get(0);
    assertThat(mongoCredential, notNullValue());
    assertThat(mongoCredential.getUserName(), equalTo("user"));
    assertThat(mongoCredential.getPassword(), equalTo("pass".toCharArray()));
    assertThat(mongoCredential.getSource(), equalTo("admin"));
    assertThat(mongoCredential.getAuthenticationMechanism(), equalTo(AuthenticationMechanism.PLAIN));
}
 
源代码12 项目: jpa-unit   文件: DataNucleusConfigurationTest.java
@Test
public void testMongoCredentials() {
    // GIVEN
    final Map<String, Object> properties = new HashMap<>();
    when(descriptor.getProperties()).thenReturn(properties);

    properties.put("datanucleus.ConnectionURL", "mongodb:/foo");
    properties.put("datanucleus.ConnectionUserName", "user");
    properties.put("datanucleus.ConnectionPassword", "pass");

    final ConfigurationFactory factory = new ConfigurationFactoryImpl();

    // WHEN
    final Configuration configuration = factory.createConfiguration(descriptor);

    // THEN
    assertThat(configuration, notNullValue());

    final List<MongoCredential> credentials = configuration.getCredentials();
    assertThat(credentials, notNullValue());
    assertThat(credentials.size(), equalTo(1));

    final MongoCredential mongoCredential = credentials.get(0);
    assertThat(mongoCredential, notNullValue());
    assertThat(mongoCredential.getUserName(), equalTo("user"));
    assertThat(mongoCredential.getPassword(), equalTo("pass".toCharArray()));
    assertThat(mongoCredential.getSource(), equalTo("admin"));
    assertThat(mongoCredential.getAuthenticationMechanism(), equalTo(AuthenticationMechanism.PLAIN));
}
 
源代码13 项目: jpa-unit   文件: HibernateOgmConfigurationTest.java
@Test
public void testMongoCredentialsWithoutSpecifyingAuthenticationDatabase() {
    // GIVEN
    final Map<String, Object> properties = new HashMap<>();
    when(descriptor.getProperties()).thenReturn(properties);

    properties.put("hibernate.ogm.datastore.database", "foo");
    properties.put("hibernate.ogm.datastore.username", "user");
    properties.put("hibernate.ogm.datastore.password", "pass");

    final ConfigurationFactory factory = new ConfigurationFactoryImpl();

    // WHEN
    final Configuration configuration = factory.createConfiguration(descriptor);

    // THEN
    assertThat(configuration, notNullValue());

    final List<MongoCredential> credentials = configuration.getCredentials();
    assertThat(credentials, notNullValue());
    assertThat(credentials.size(), equalTo(1));

    final MongoCredential mongoCredential = credentials.get(0);
    assertThat(mongoCredential, notNullValue());
    assertThat(mongoCredential.getUserName(), equalTo("user"));
    assertThat(mongoCredential.getPassword(), equalTo("pass".toCharArray()));
    assertThat(mongoCredential.getSource(), equalTo("admin"));
    assertThat(mongoCredential.getAuthenticationMechanism(), equalTo(AuthenticationMechanism.PLAIN));
}
 
源代码14 项目: jpa-unit   文件: HibernateOgmConfigurationTest.java
@Test
public void testMongoCredentialsWithAuthenticationDatabaseSet() {
    // GIVEN
    final Map<String, Object> properties = new HashMap<>();
    when(descriptor.getProperties()).thenReturn(properties);

    properties.put("hibernate.ogm.datastore.database", "foo");
    properties.put("hibernate.ogm.datastore.username", "user");
    properties.put("hibernate.ogm.datastore.password", "pass");
    properties.put("hibernate.ogm.mongodb.authentication_database", "auth");

    final ConfigurationFactory factory = new ConfigurationFactoryImpl();

    // WHEN
    final Configuration configuration = factory.createConfiguration(descriptor);

    // THEN
    assertThat(configuration, notNullValue());

    final List<MongoCredential> credentials = configuration.getCredentials();
    assertThat(credentials, notNullValue());
    assertThat(credentials.size(), equalTo(1));

    final MongoCredential mongoCredential = credentials.get(0);
    assertThat(mongoCredential, notNullValue());
    assertThat(mongoCredential.getUserName(), equalTo("user"));
    assertThat(mongoCredential.getPassword(), equalTo("pass".toCharArray()));
    assertThat(mongoCredential.getSource(), equalTo("auth"));
    assertThat(mongoCredential.getAuthenticationMechanism(), equalTo(AuthenticationMechanism.PLAIN));
}
 
源代码15 项目: jpa-unit   文件: EclipseLinkConfigurationTest.java
@Test
public void testMongoCredentials() {
    // GIVEN
    final Map<String, Object> properties = new HashMap<>();
    when(descriptor.getProperties()).thenReturn(properties);

    properties.put("eclipselink.nosql.property.mongo.db", "foo");
    properties.put("eclipselink.nosql.property.user", "user");
    properties.put("eclipselink.nosql.property.password", "pass");

    final ConfigurationFactory factory = new ConfigurationFactoryImpl();

    // WHEN
    final Configuration configuration = factory.createConfiguration(descriptor);

    // THEN
    assertThat(configuration, notNullValue());

    final List<MongoCredential> credentials = configuration.getCredentials();
    assertThat(credentials, notNullValue());
    assertThat(credentials.size(), equalTo(1));

    final MongoCredential mongoCredential = credentials.get(0);
    assertThat(mongoCredential, notNullValue());
    assertThat(mongoCredential.getUserName(), equalTo("user"));
    assertThat(mongoCredential.getPassword(), equalTo("pass".toCharArray()));
    assertThat(mongoCredential.getSource(), equalTo("admin"));
    assertThat(mongoCredential.getAuthenticationMechanism(), equalTo(AuthenticationMechanism.PLAIN));
}
 
源代码16 项目: vertx-mongo-client   文件: CredentialListParser.java
private AuthenticationMechanism getAuthenticationMechanism(String authMechanism) {
  AuthenticationMechanism mechanism;
  try {
    mechanism = AuthenticationMechanism.fromMechanismName(authMechanism);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException("Invalid authMechanism '" + authMechanism + "'");
  }
  return mechanism;
}
 
@Test
public void testAuth_MONGODB_X509_without_username() {
  JsonObject config = new JsonObject();
  String authSource = TestUtils.randomAlphaString(10);
  config.put("authSource", authSource);
  config.put("authMechanism", "MONGODB-X509");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertNull(credential.getUserName());
  assertNotEquals(authSource, credential.getSource()); // It should ignore the source we pass in

  assertEquals(AuthenticationMechanism.MONGODB_X509, credential.getAuthenticationMechanism());
}
 
源代码18 项目: nosql4idea   文件: MongoAuthenticationPanel.java
private AuthenticationMechanism getAuthenticationMechanism() {
    if (mongoCRAuthRadioButton.isSelected()) {
        return AuthenticationMechanism.MONGODB_CR;
    } else if (scramSHA1AuthRadioButton.isSelected()) {
        return AuthenticationMechanism.SCRAM_SHA_1;
    }
    return null;
}
 
源代码19 项目: nosql4idea   文件: ServerConfigurationPanelTest.java
@Test
public void createMongoConfiguration() throws Exception {
    frameFixture.textBox("labelField").setText("Localhost");

    frameFixture.label("databaseVendorLabel").requireText("MongoDB");
    frameFixture.label("databaseTipsLabel").requireText("format: host:port. If replicat set: host:port1,host:port2,...");

    frameFixture.textBox("serverUrlField").setText("localhost:25");
    frameFixture.textBox("usernameField").setText("john");
    frameFixture.textBox("passwordField").setText("johnpassword");

    frameFixture.textBox("userDatabaseField").setText("mydatabase");

    frameFixture.textBox("authenticationDatabaseField").setText("admin");
    frameFixture.radioButton("defaultAuthMethod").requireSelected();
    frameFixture.radioButton("mongoCRAuthField").click();

    frameFixture.checkBox("sslConnectionField").check();
    frameFixture.checkBox("autoConnectField").check();
    ServerConfiguration configuration = new ServerConfiguration();

    configurationPanel.applyConfigurationData(configuration);

    assertEquals("Localhost", configuration.getLabel());
    assertEquals(DatabaseVendor.MONGO, configuration.getDatabaseVendor());
    assertEquals("localhost:25", configuration.getServerUrl());
    AuthenticationSettings authenticationSettings = configuration.getAuthenticationSettings();
    assertEquals("john", authenticationSettings.getUsername());
    assertEquals("johnpassword", authenticationSettings.getPassword());

    MongoExtraSettings mongoExtraSettings = new MongoExtraSettings(authenticationSettings.getExtras());

    assertEquals("admin", mongoExtraSettings.getAuthenticationDatabase());
    assertEquals(AuthenticationMechanism.MONGODB_CR, mongoExtraSettings.getAuthenticationMechanism());
    assertEquals("mydatabase", configuration.getUserDatabase());
    assertTrue(configuration.isConnectOnIdeStartup());
}
 
源代码20 项目: nosql4idea   文件: ServerConfigurationPanelTest.java
@Test
public void loadMongoConfiguration() throws Exception {
    ServerConfiguration configuration = new ServerConfiguration();
    configuration.setLabel("Localhost");
    configuration.setDatabaseVendor(DatabaseVendor.MONGO);
    configuration.setServerUrl("localhost:25");

    AuthenticationSettings authenticationSettings = new AuthenticationSettings();
    authenticationSettings.setUsername("john");
    authenticationSettings.setPassword("johnpassword");
    MongoExtraSettings mongoExtraSettings = new MongoExtraSettings();
    mongoExtraSettings.setAuthenticationDatabase("admin");
    mongoExtraSettings.setAuthenticationMechanism(AuthenticationMechanism.SCRAM_SHA_1);
    mongoExtraSettings.setSsl(true);

    authenticationSettings.setExtras(mongoExtraSettings.get());

    configuration.setAuthenticationSettings(authenticationSettings);
    configuration.setUserDatabase("mydatabase");

    configurationPanel.loadConfigurationData(configuration);

    frameFixture.textBox("labelField").requireText("Localhost");
    frameFixture.textBox("serverUrlField").requireText("localhost:25");
    frameFixture.textBox("usernameField").requireText("john");
    frameFixture.textBox("passwordField").requireText("johnpassword");
    frameFixture.textBox("authenticationDatabaseField").requireText("admin");
    frameFixture.checkBox("sslConnectionField").requireSelected();
    frameFixture.radioButton("scramSHA1AuthField").requireSelected();
}
 
源代码21 项目: nosql4idea   文件: MongoClientURIBuilderTest.java
@Test
public void withSpecificAuthentication() throws Exception {
    assertEquals(
            "mongodb://toto:[email protected]:27018/?authMechanism=MONGODB-CR&authSource=userdb",
            MongoClientURIBuilder.builder()
                    .setServerAddresses("localhost:27018")
                    .setCredential("toto", "pass", "userdb")
                    .setAuthenticationMecanism(AuthenticationMechanism.MONGODB_CR)
                    .build());
}
 
源代码22 项目: quarkus   文件: MongoClients.java
private MongoCredential createMongoCredential(MongoClientConfig config) {
    String username = config.credentials.username.orElse(null);
    if (username == null) {
        return null;
    }

    char[] password = config.credentials.password.map(String::toCharArray).orElse(null);
    // get the authsource, or the database from the config, or 'admin' as it is the default auth source in mongo
    // and null is not allowed
    String authSource = config.credentials.authSource.orElse(config.database.orElse("admin"));
    // AuthMechanism
    AuthenticationMechanism mechanism = null;
    Optional<String> maybeMechanism = config.credentials.authMechanism;
    if (maybeMechanism.isPresent()) {
        mechanism = getAuthenticationMechanism(maybeMechanism.get());
    }

    // Create the MongoCredential instance.
    MongoCredential credential;
    if (mechanism == GSSAPI) {
        credential = MongoCredential.createGSSAPICredential(username);
    } else if (mechanism == PLAIN) {
        credential = MongoCredential.createPlainCredential(username, authSource, password);
    } else if (mechanism == MONGODB_X509) {
        credential = MongoCredential.createMongoX509Credential(username);
    } else if (mechanism == SCRAM_SHA_1) {
        credential = MongoCredential.createScramSha1Credential(username, authSource, password);
    } else if (mechanism == null) {
        credential = MongoCredential.createCredential(username, authSource, password);
    } else {
        throw new IllegalArgumentException("Unsupported authentication mechanism " + mechanism);
    }

    //add the properties
    if (!config.credentials.authMechanismProperties.isEmpty()) {
        for (Map.Entry<String, String> entry : config.credentials.authMechanismProperties.entrySet()) {
            credential = credential.withMechanismProperty(entry.getKey(), entry.getValue());
        }
    }

    return credential;
}
 
源代码23 项目: vertx-mongo-client   文件: CredentialListParser.java
public CredentialListParser(JsonObject config) {
  String username = config.getString("username");
  // AuthMechanism
  AuthenticationMechanism mechanism = null;
  String authMechanism = config.getString("authMechanism");
  if (authMechanism != null) {
    mechanism = getAuthenticationMechanism(authMechanism);
  }
  credentials = new ArrayList<>();
  if (username == null) {
    if (mechanism == MONGODB_X509) {
      credentials.add(MongoCredential.createMongoX509Credential());
    }
  } else {
    String passwd = config.getString("password");
    char[] password = (passwd == null) ? null : passwd.toCharArray();
    // See https://github.com/vert-x3/vertx-mongo-client/issues/46 - 'admin' as default is a security
    // concern, use  the 'db_name' if none is set.
    String authSource = config.getString("authSource",
      config.getString("db_name", MongoClientImpl.DEFAULT_DB_NAME));

    // MongoCredential
    String gssapiServiceName = config.getString("gssapiServiceName");
    MongoCredential credential;
    if (mechanism == GSSAPI) {
      credential = MongoCredential.createGSSAPICredential(username);
      credential = getMongoCredential(gssapiServiceName, credential);
    } else if (mechanism == PLAIN) {
      credential = MongoCredential.createPlainCredential(username, authSource, password);
    } else if (mechanism == MONGODB_X509) {
      credential = MongoCredential.createMongoX509Credential(username);
    } else if (mechanism == SCRAM_SHA_1) {
      credential = MongoCredential.createScramSha1Credential(username, authSource, password);
    } else if (mechanism == SCRAM_SHA_256) {
      credential = MongoCredential.createScramSha256Credential(username, authSource, password);
    } else if (mechanism == null) {
      credential = MongoCredential.createCredential(username, authSource, password);
    } else {
      throw new IllegalArgumentException("Unsupported authentication mechanism " + mechanism);
    }

    credentials.add(credential);
  }
}
 
源代码24 项目: nosql4idea   文件: MongoConsoleRunner.java
@Nullable
@Override
protected Process createProcess() throws ExecutionException {

    NoSqlConfiguration noSqlConfiguration = NoSqlConfiguration.getInstance(getProject());
    String shellPath = noSqlConfiguration.getShellPath(DatabaseVendor.MONGO);
    final GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(shellPath);

    commandLine.addParameter(MongoUtils.buildMongoUrl(serverConfiguration, database));

    String shellWorkingDir = serverConfiguration.getShellWorkingDir();
    if (StringUtils.isNotBlank(shellWorkingDir)) {
        commandLine.withWorkDirectory(shellWorkingDir);
    }

    AuthenticationSettings authenticationSettings = serverConfiguration.getAuthenticationSettings();

    String username = authenticationSettings.getUsername();
    if (StringUtils.isNotBlank(username)) {
        commandLine.addParameter("--username");
        commandLine.addParameter(username);
    }

    String password = authenticationSettings.getPassword();
    if (StringUtils.isNotBlank(password)) {
        commandLine.addParameter("--password");
        commandLine.addParameter(password);
    }

    MongoExtraSettings mongoExtraSettings = new MongoExtraSettings(authenticationSettings.getExtras());
    String authenticationDatabase = mongoExtraSettings.getAuthenticationDatabase();
    if (StringUtils.isNotBlank(authenticationDatabase)) {
        commandLine.addParameter("--authenticationDatabase");
        commandLine.addParameter(authenticationDatabase);
    }

    AuthenticationMechanism authenticationMecanism = mongoExtraSettings.getAuthenticationMechanism();
    if (authenticationMecanism != null) {
        commandLine.addParameter("--authenticationMecanism");
        commandLine.addParameter(authenticationMecanism.getMechanismName());
    }

    String shellArgumentsLine = serverConfiguration.getShellArgumentsLine();
    if (StringUtils.isNotBlank(shellArgumentsLine)) {
        commandLine.addParameters(shellArgumentsLine.split(" "));
    }

    return commandLine.createProcess();
}
 
源代码25 项目: nosql4idea   文件: MongoExtraSettings.java
public AuthenticationMechanism getAuthenticationMechanism() {
    String authMecanism = extras.get(AUTH_MECHANISM);
    return authMecanism == null ? null : AuthenticationMechanism.valueOf(authMecanism);
}
 
源代码26 项目: nosql4idea   文件: MongoExtraSettings.java
public void setAuthenticationMechanism(AuthenticationMechanism authenticationMechanism) {
    if (authenticationMechanism != null) {
        extras.put(AUTH_MECHANISM, authenticationMechanism.name());
    }
}
 
源代码27 项目: nosql4idea   文件: MongoClientURIBuilder.java
public MongoClientURIBuilder setAuthenticationMecanism(@NotNull AuthenticationMechanism authenticationMecanism) {
    this.authenticationMecanism = authenticationMecanism;
    return this;
}
 
 类所在包
 同包方法