Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specifiy authentication database different to database #19

Open
brucke opened this issue Feb 20, 2018 · 4 comments · May be fixed by #20
Open

specifiy authentication database different to database #19

brucke opened this issue Feb 20, 2018 · 4 comments · May be fixed by #20
Labels

Comments

@brucke
Copy link

brucke commented Feb 20, 2018

Hi,

create Job!!

But we need the possibility to change the authentication database. E.g.
The users are managed in database 'admin' and the data are stored in db 'myData'.
Is it possible to configure 2 database: one for Data and one for authSource=db1

Thanks!!

@ctrimble
Copy link
Contributor

You can add more than one instance of the bundle, to configure it for multiple databases. For example, your configuration could be like this:

  @JsonProperty
  protected MongoConfiguration mongoA;
  @JsonProperty
  protected MongoConfiguration mongoB;

  public MongoConfiguration getMongoA() {
    return mongo;
  }

  public MongoConfiguration getMongoB() {
    return mongo;
  }

and then you would create two bundles in your service like this:

MongoBundle<ExampleConfiguration> mongoBundleA;
MongoBundle<ExampleConfiguration> mongoBundleA;

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
  bootstrap.addBundle(mongoBundleA = MongoBundle.<ExampleConfiguration>builder()
    .withConfiguration(ExampleConfiguration::getMongoA)
    .build());
  bootstrap.addBundle(mongoBundleB = MongoBundle.<ExampleConfiguration>builder()
    .withConfiguration(ExampleConfiguration::getMongoB)
    .build());
}

Does that answer your question?

@brucke
Copy link
Author

brucke commented Feb 21, 2018

Hi Thanks!
But is not completely answered.

We configure our Mongo Database User in the Mongo System Database admin

BUT in this case the MongoClient needs the information about the authenticationDatabase. See following command

mongo --port 27017 -u myUserAdmin -p 'abc123' --authenticationDatabase 'admin'

Or in Java

import com.mongodb.MongoCredential;

// ...

String user;        // the user name
String database;    // the name of the database in which the user is defined
char[] password;    // the password as a character array
// ...
MongoCredential credential = MongoCredential.createCredential(user,
                                                             database,
                                                              password);

http://mongodb.github.io/mongo-java-driver/3.0/driver/reference/connecting/authenticating/

But we can not configure the Database for data and a different database for Users (like admin)

How does you enable authentication on MongoDB side? Does you store the user in the specific Data-Database?

@brucke brucke changed the title change ?authSource=db1 to specifiy authentication database different to database Feb 21, 2018
@ctrimble
Copy link
Contributor

ctrimble commented Feb 21, 2018

After reading the link, I think I understand the issue now. This library does not support that currently, but PRs are welcome. You would need to add authenticationDatabase to the configuration object, and then update MongoClientBuilder to select the database with something like:

  Optional.ofNullable(credentialConfig.getAuthenticationDatabase()).orElse(configuration.getDatabase())

https://github.com/meltmedia/dropwizard-mongo/blob/develop/bundle/src/main/java/com/meltmedia/dropwizard/mongo/MongoClientBuilder.java#L106

@brucke
Copy link
Author

brucke commented Feb 23, 2018

Thanks.
i will implement the feature next week.

@nightowlengineer nightowlengineer linked a pull request Oct 25, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants