Skip to content
Snippets Groups Projects
Commit 6af3a4a2 authored by Julian Horner's avatar Julian Horner
Browse files

Add module options to variably select collection and database

parent 0bebf51e
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,12 @@ import com.mongodb.client.model.Filters;
public class MongoDBLoginModule extends UsernamePasswordLoginModule {
//----------------------------------------------------------------------------------------------
private String database;
private String collection;
//----------------------------------------------------------------------------------------------
/**
* {@inheritDoc}
*/
......@@ -31,6 +37,9 @@ public class MongoDBLoginModule extends UsernamePasswordLoginModule {
public void initialize(Subject subject, CallbackHandler callbackHandler,
Map<String, ?> sharedState, Map<String, ?> options) {
super.initialize(subject, callbackHandler, sharedState, options);
database = (String) options.get("database");
collection = (String) options.get("collection");
}
//----------------------------------------------------------------------------------------------
......@@ -41,8 +50,9 @@ public class MongoDBLoginModule extends UsernamePasswordLoginModule {
@Override
protected String getUsersPassword() throws LoginException {
MongoClient mongoClient = MongoClients.create("mongodb://localhost");
MongoDatabase database = mongoClient.getDatabase("my-aktion");
MongoCollection<Document> organizerCollection = database.getCollection("Organizer");
MongoDatabase database = mongoClient.getDatabase(this.database);
MongoCollection<Document> organizerCollection = database.getCollection(this.collection);
Document organizerDocument =
organizerCollection.find(Filters.eq("email", getUsername())).first();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment