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
9bee3626
Commit
9bee3626
authored
Dec 13, 2017
by
Julien Perret
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mongoDB session storage
parent
7c82b4bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
16 deletions
+75
-16
build.sbt
build.sbt
+1
-0
Launcher.scala
server/src/main/scala/server/Launcher.scala
+27
-3
Servlet.scala
server/src/main/scala/server/Servlet.scala
+47
-13
No files found.
build.sbt
View file @
9bee3626
...
@@ -45,6 +45,7 @@ lazy val server = project.in(file("server")) settings(
...
@@ -45,6 +45,7 @@ lazy val server = project.in(file("server")) settings(
version
:=
Version
,
version
:=
Version
,
scalaVersion
:=
ScalaVersion
,
scalaVersion
:=
ScalaVersion
,
libraryDependencies
++=
Seq
(
libraryDependencies
++=
Seq
(
"org.mongodb"
%%
"casbah"
%
"3.1.1"
,
"com.lihaoyi"
%%
"autowire"
%
autowireVersion
,
"com.lihaoyi"
%%
"autowire"
%
autowireVersion
,
"com.lihaoyi"
%%
"upickle"
%
upickleVersion
,
"com.lihaoyi"
%%
"upickle"
%
upickleVersion
,
"com.lihaoyi"
%%
"scalatags"
%
scalatagsVersion
,
"com.lihaoyi"
%%
"scalatags"
%
scalatagsVersion
,
...
...
server/src/main/scala/server/Launcher.scala
View file @
9bee3626
package
server
package
server
import
java.net.URI
import
javax.servlet.ServletContext
import
javax.servlet.ServletContext
import
com.mongodb.casbah.MongoClient
import
com.mongodb.
{
MongoCredential
,
ServerAddress
}
import
org.eclipse.jetty.server.Server
import
org.eclipse.jetty.server.Server
import
org.eclipse.jetty.webapp.WebAppContext
import
org.eclipse.jetty.webapp.WebAppContext
import
org.openmole.gate.server.Servlet
import
org.openmole.gate.server.Servlet
import
org.scalatra.LifeCycle
import
org.scalatra.LifeCycle
import
org.scalatra.servlet.ScalatraListener
import
org.scalatra.servlet.ScalatraListener
import
server.Launcher.MongoDB
object
Launcher
extends
App
{
object
Launcher
extends
App
{
case
class
MongoDB
(
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"
))
println
(
mongoURI
)
val
mongoDB
=
{
val
host
=
mongoURI
.
getHost
println
(
host
)
val
port
=
mongoURI
.
getPort
println
(
port
)
println
(
"path="
+
mongoURI
.
getPath
)
val
db
=
mongoURI
.
getPath
.
drop
(
1
)
println
(
"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
)
}
val
server
=
new
Server
(
8080
)
val
server
=
new
Server
(
8080
)
val
context
=
new
WebAppContext
()
val
context
=
new
WebAppContext
()
context
.
setAttribute
(
mongoDBArguments
,
mongoDB
)
val
webapp
=
getClass
.
getClassLoader
.
getResource
(
"webapp"
).
toExternalForm
val
webapp
=
getClass
.
getClassLoader
.
getResource
(
"webapp"
).
toExternalForm
context
setContextPath
"/"
context
setContextPath
"/"
...
@@ -26,9 +50,9 @@ object Launcher extends App {
...
@@ -26,9 +50,9 @@ object Launcher extends App {
}
}
class
GateBootstrap
extends
LifeCycle
{
class
GateBootstrap
extends
LifeCycle
{
override
def
init
(
context
:
ServletContext
)
{
override
def
init
(
context
:
ServletContext
)
{
context
.
mount
(
new
Servlet
,
"/*"
)
val
mongoDB
=
context
.
get
(
Launcher
.
mongoDBArguments
).
get
.
asInstanceOf
[
MongoDB
]
context
.
mount
(
new
Servlet
(
mongoDB
),
"/*"
)
}
}
}
}
\ No newline at end of file
server/src/main/scala/server/Servlet.scala
View file @
9bee3626
package
org.openmole.gate.server
package
org.openmole.gate.server
import
com.mongodb.
{
MongoCredential
,
ServerAddress
}
import
com.mongodb.casbah.Imports.
{
MongoCollection
,
MongoDBObject
}
import
com.mongodb.casbah.MongoClient
import
org.openmole.gate.server.Data.User
import
org.openmole.gate.server.Data.User
import
org.scalatra._
import
org.scalatra._
import
org.scalatra.auth.
{
ScentryConfig
,
ScentrySupport
}
import
org.scalatra.auth.
{
ScentryConfig
,
ScentrySupport
}
import
org.scalatra.auth.strategy.
{
BasicAuthStrategy
,
BasicAuthSupport
}
import
org.scalatra.auth.strategy.
{
BasicAuthStrategy
,
BasicAuthSupport
}
import
server.DBStrategy
import
server.DBStrategy
import
server.Launcher.MongoDB
import
scala.concurrent.duration._
import
scala.concurrent.duration._
import
scala.concurrent.Await
import
scala.concurrent.Await
...
@@ -18,24 +22,54 @@ object AutowireServer extends autowire.Server[String, upickle.default.Reader, up
...
@@ -18,24 +22,54 @@ object AutowireServer extends autowire.Server[String, upickle.default.Reader, up
def
write
[
Result:
upickle.default.Writer
](
r
:
Result
)
=
upickle
.
default
.
write
(
r
)
def
write
[
Result:
upickle.default.Writer
](
r
:
Result
)
=
upickle
.
default
.
write
(
r
)
}
}
class
Servlet
extends
ScalatraServlet
with
AuthenticationSupport
{
class
Servlet
(
mongoDB
:
MongoDB
)
extends
ScalatraServlet
with
AuthenticationSupport
{
val
basePath
=
"shared"
val
basePath
=
"shared"
val
head
=
tags
.
head
(
tags
.
meta
(
tags
.
httpEquiv
:=
"Content-Type"
,
tags
.
content
:=
"text/html; charset=UTF-8"
),
tags
.
link
(
tags
.
rel
:=
"stylesheet"
,
tags
.
`type`
:=
"text/css"
,
href
:=
"css/bootstrap.min.css"
),
tags
.
script
(
tags
.
`type`
:=
"text/javascript"
,
tags
.
src
:=
"js/gate.js"
)
)
get
(
"/"
)
{
get
(
"/"
)
{
val
user
:
User
=
auth
(
"DB"
).
get
contentType
=
"text/html"
contentType
=
"text/html"
tags
.
html
(
auth
(
"DB"
)
match
{
tags
.
head
(
case
Some
(
user
)
=>
tags
.
meta
(
tags
.
httpEquiv
:=
"Content-Type"
,
tags
.
content
:=
"text/html; charset=UTF-8"
),
val
userSession
=
MongoDBObject
(
user
.
login
->
session
.
getId
)
tags
.
link
(
tags
.
rel
:=
"stylesheet"
,
tags
.
`type`
:=
"text/css"
,
href
:=
"css/bootstrap.min.css"
),
println
(
mongoDB
.
host
+
" => "
+
mongoDB
.
port
)
tags
.
script
(
tags
.
`type`
:=
"text/javascript"
,
tags
.
src
:=
"js/gate.js"
)
val
server
=
new
ServerAddress
(
mongoDB
.
host
,
mongoDB
.
port
)
),
val
credentials
=
MongoCredential
.
createCredential
(
"accountUser"
,
"products"
,
"password"
.
toCharArray
)
tags
.
body
(
val
mongoClient
=
MongoClient
(
server
,
List
(
credentials
))
div
(
"authenticated: "
+
user
.
login
),
println
(
mongoDB
.
db
+
" ? "
+
mongoDB
.
dataSet
)
script
(
"client.Gate.run();"
)
val
mongoColl
=
mongoClient
(
mongoDB
.
db
)(
mongoDB
.
dataSet
)
)
mongoColl
.
findOne
(
userSession
)
match
{
)
case
Some
(
x
)
=>
tags
.
html
(
head
,
tags
.
body
(
div
(
"already authenticated: "
+
user
.
login
),
script
(
"client.Gate.run();"
)
)
)
case
None
=>
mongoColl
+=
userSession
tags
.
html
(
head
,
tags
.
body
(
div
(
"authenticated: "
+
user
.
login
),
script
(
"client.Gate.run();"
)
)
)
}
case
None
=>
tags
.
html
(
head
,
tags
.
body
(
div
(
"Failed to authenticate"
)
)
)
}
}
}
post
(
s
"/$basePath/*"
)
{
post
(
s
"/$basePath/*"
)
{
...
...
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