From 890879cb112d73e3fcb091aab9d2a0c4d60af0ae Mon Sep 17 00:00:00 2001
From: Brandon Chapman <bchapman@bridge2solutions.com>
Date: Sun, 14 Jul 2013 00:03:31 +0100
Subject: [PATCH] Added support for authorization

Closes #25.
Closes #26.
---
 .../embedmongo/StartEmbeddedMongoMojo.java    | 28 +++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java b/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java
index 1d25f8e..2ee89da 100644
--- a/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java
+++ b/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java
@@ -15,7 +15,7 @@
  */
 package com.github.joelittlejohn.embedmongo;
 
-import static java.util.Collections.singletonList;
+import static java.util.Collections.*;
 
 import java.io.File;
 import java.io.IOException;
@@ -53,9 +53,11 @@ import de.flapdoodle.embed.mongo.distribution.Version;
 import de.flapdoodle.embed.process.config.IRuntimeConfig;
 import de.flapdoodle.embed.process.config.io.ProcessOutput;
 import de.flapdoodle.embed.process.config.store.IDownloadConfig;
+import de.flapdoodle.embed.process.distribution.Distribution;
 import de.flapdoodle.embed.process.distribution.GenericVersion;
 import de.flapdoodle.embed.process.distribution.IVersion;
 import de.flapdoodle.embed.process.exceptions.DistributionException;
+import de.flapdoodle.embed.process.runtime.ICommandLinePostProcessor;
 import de.flapdoodle.embed.process.runtime.Network;
 import de.flapdoodle.embed.process.store.IArtifactStore;
 
@@ -188,6 +190,13 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
      */
     private String proxyPassword;
 
+    /**
+     * Should authorization be enabled for MongoDB
+     * 
+     * @parameter expression="${embedmongo.authEnabled}" default-value="false"
+     */
+    private boolean authEnabled;
+
     /**
      * The maven project.
      * 
@@ -207,10 +216,25 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
         MongodExecutable executable;
         try {
 
+            final ICommandLinePostProcessor commandLinePostProcessor;
+            if (authEnabled) {
+                commandLinePostProcessor = new ICommandLinePostProcessor() {
+                    @Override
+                    public List<String> process(final Distribution distribution, final List<String> args) {
+                        args.remove("--noauth");
+                        args.add("--auth");
+                        return args;
+                    }
+                };
+            } else {
+                commandLinePostProcessor = new ICommandLinePostProcessor.Noop();
+            }
+
             IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
                     .defaults(Command.MongoD)
                     .processOutput(getOutputConfig())
                     .artifactStore(getArtifactStore())
+                    .commandLinePostProcessor(commandLinePostProcessor)
                     .build();
 
             if (randomPort) {
@@ -274,7 +298,7 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
         }
 
     }
-    
+
     private IArtifactStore getArtifactStore()
     {
         IDownloadConfig downloadConfig = new DownloadConfigBuilder()
-- 
GitLab