Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Implemented ssl setting #52
Browse files Browse the repository at this point in the history
The ssl setting works by setting the socket factory to javax.net.ssl.SSLSocketFactory
  • Loading branch information
Leon Radley committed Nov 18, 2013
1 parent 501d77f commit 6f117fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/se/radley/plugin/salat/OptionsFromConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package se.radley.plugin.salat
import play.api.Configuration
import com.mongodb.casbah.MongoOptions
import com.mongodb._
import javax.net.ssl.SSLSocketFactory
import scala.Some

object OptionsFromConfig {
Expand Down Expand Up @@ -43,6 +44,7 @@ object OptionsFromConfig {
config.getInt("socketTimeout").map(v => builder.socketTimeout(v))
config.getInt("threadsAllowedToBlockForConnectionMultiplier").map(v => builder.threadsAllowedToBlockForConnectionMultiplier(v))
config.getString("writeConcern").map(name => WriteConcern.valueOf(name)).map(v => builder.writeConcern(v))
config.getBoolean("ssl").map(v => if (v) builder.socketFactory(SSLSocketFactory.getDefault()))

Some(builder.build())
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/scala/se/radley/plugin/salat/OptionsFromConfigSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.mongodb._
import play.api.Configuration
import javax.net.SocketFactory
import org.specs2.specification.AllExpectations
import javax.net.ssl.SSLSocketFactory

class OptionsFromConfigSpec extends Specification with AllExpectations {

Expand Down Expand Up @@ -54,6 +55,20 @@ class OptionsFromConfigSpec extends Specification with AllExpectations {
val options = OptionsFromConfig(Configuration.empty)
options must beNone
}

"Set SSL factory is ssl = true" in {
val conf = Map(
("mongodb.default.options.ssl" -> "true")
)

val configuration = Configuration.from(conf).getConfig("mongodb.default.options").get
val optionsOpt = OptionsFromConfig(configuration)

optionsOpt must beSome
val options = optionsOpt.get

options.getSocketFactory must haveClass[SSLSocketFactory]
}
}

}
Expand Down

0 comments on commit 6f117fc

Please sign in to comment.