Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openmole
gate
Commits
64b96b20
Commit
64b96b20
authored
Dec 14, 2017
by
Julien Perret
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handling user credentials i URI
parent
7d1a0298
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
9 deletions
+11
-9
Launcher.scala
server/src/main/scala/server/Launcher.scala
+10
-6
Servlet.scala
server/src/main/scala/server/Servlet.scala
+1
-3
No files found.
server/src/main/scala/server/Launcher.scala
View file @
64b96b20
...
...
@@ -13,24 +13,28 @@ import org.scalatra.servlet.ScalatraListener
import
server.Launcher.MongoDB
object
Launcher
extends
App
{
case
class
MongoDB
(
host
:
String
,
port
:
Int
,
db
:
String
,
dataSet
:
String
)
case
class
MongoDB
(
user
:
String
,
password
:
String
,
host
:
String
,
port
:
Int
,
db
:
String
,
dataSet
:
String
)
val
mongoDBArguments
=
"mongoDBArguments"
val
option
=
args
.
headOption
val
mongoURI
=
new
URI
(
option
.
getOrElse
(
"mongodb://localhost:27017/openmole?login"
))
val
mongoURI
=
new
URI
(
option
.
getOrElse
(
"mongodb://
openmole:rocks@
localhost:27017/openmole?login"
))
println
(
mongoURI
)
val
mongoDB
=
{
println
(
"TTTT userinfo = "
+
mongoURI
.
getUserInfo
)
val
userInfos
=
mongoURI
.
getUserInfo
.
split
(
':'
)
val
user
=
userInfos
(
0
)
val
password
=
userInfos
(
1
)
val
host
=
mongoURI
.
getHost
println
(
host
)
println
(
"TTTT host = "
+
host
)
val
port
=
mongoURI
.
getPort
println
(
port
)
println
(
"path="
+
mongoURI
.
getPath
)
println
(
"
TTTT
path="
+
mongoURI
.
getPath
)
val
db
=
mongoURI
.
getPath
.
drop
(
1
)
println
(
"query="
+
mongoURI
.
getQuery
)
println
(
"
TTTT
query="
+
mongoURI
.
getQuery
)
val
dataSet
=
mongoURI
.
getQuery
//if (mongoURI.getHost== null || mongoURI.getHost.isEmpty) None
//else Some(MongoDB(host, port, db, dataSet))
MongoDB
(
host
,
port
,
db
,
dataSet
)
MongoDB
(
user
,
password
,
host
,
port
,
db
,
dataSet
)
}
val
server
=
new
Server
(
8080
)
val
context
=
new
WebAppContext
()
...
...
server/src/main/scala/server/Servlet.scala
View file @
64b96b20
...
...
@@ -35,11 +35,9 @@ class Servlet(mongoDB: MongoDB) extends ScalatraServlet with AuthenticationSuppo
case
class
MongoData
(
collection
:
MongoCollection
,
userSession
:
DBObject
)
def
getMongoData
(
user
:
User
)
=
{
val
userSession
=
MongoDBObject
(
user
.
login
->
session
.
getId
)
println
(
mongoDB
.
host
+
" => "
+
mongoDB
.
port
)
val
server
=
new
ServerAddress
(
mongoDB
.
host
,
mongoDB
.
port
)
val
credentials
=
MongoCredential
.
createCredential
(
"accountUser"
,
"products"
,
"password"
.
toCharArray
)
val
credentials
=
MongoCredential
.
createCredential
(
mongoDB
.
user
,
"admin"
,
mongoDB
.
password
.
toCharArray
)
val
mongoClient
=
MongoClient
(
server
,
List
(
credentials
))
println
(
mongoDB
.
db
+
" ? "
+
mongoDB
.
dataSet
)
MongoData
(
mongoClient
(
mongoDB
.
db
)(
mongoDB
.
dataSet
),
userSession
)
}
get
(
"/"
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment