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
9c460a4a
Commit
9c460a4a
authored
Dec 13, 2017
by
Mathieu leclaire
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic DBStrategy
parent
28693bcb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
3 deletions
+64
-3
build.sbt
build.sbt
+1
-0
DBStrategy.scala
server/src/main/scala/server/DBStrategy.scala
+22
-0
Servlet.scala
server/src/main/scala/server/Servlet.scala
+41
-3
No files found.
build.sbt
View file @
9c460a4a
...
...
@@ -49,6 +49,7 @@ lazy val server = project.in(file("server")) settings(
"com.lihaoyi"
%%
"upickle"
%
upickleVersion
,
"com.lihaoyi"
%%
"scalatags"
%
scalatagsVersion
,
"org.scalatra"
%%
"scalatra"
%
scalatraVersion
,
"org.scalatra"
%%
"scalatra-auth"
%
scalatraVersion
,
"ch.qos.logback"
%
"logback-classic"
%
"1.1.3"
%
"runtime"
,
"javax.servlet"
%
"javax.servlet-api"
%
"3.1.0"
%
"provided"
,
"org.eclipse.jetty"
%
"jetty-webapp"
%
jettyVersion
,
...
...
server/src/main/scala/server/DBStrategy.scala
0 → 100644
View file @
9c460a4a
package
server
import
javax.servlet.http.
{
HttpServletRequest
,
HttpServletResponse
}
import
org.openmole.gate.server.Data.User
import
org.scalatra.auth.strategy.
{
BasicAuthStrategy
}
import
org.scalatra.ScalatraBase
class
DBStrategy
(
protected
override
val
app
:
ScalatraBase
,
realm
:
String
)
extends
BasicAuthStrategy
[
User
](
app
,
realm
)
{
override
protected
def
getUserId
(
user
:
User
)(
implicit
request
:
HttpServletRequest
,
response
:
HttpServletResponse
)
:
String
=
user
.
login
override
protected
def
validate
(
userName
:
String
,
password
:
String
)(
implicit
request
:
HttpServletRequest
,
response
:
HttpServletResponse
)
:
Option
[
User
]
=
{
//Check whether user is in DB
//stub
if
(
userName
==
"scalatra"
&&
password
==
"scalatra"
)
Some
(
User
(
userName
))
else
None
}
}
\ No newline at end of file
server/src/main/scala/server/Servlet.scala
View file @
9c460a4a
package
org.openmole.gate.server
import
org.scalatra._
import
org.scalatra.auth.
{
ScentryConfig
,
ScentrySupport
}
import
org.scalatra.auth.strategy.BasicAuthSupport
import
server.DBStrategy
import
scala.concurrent.duration._
import
scala.concurrent.Await
import
scalatags.Text.all._
...
...
@@ -13,13 +17,12 @@ object AutowireServer extends autowire.Server[String, upickle.default.Reader, up
def
write
[
Result:
upickle.default.Writer
](
r
:
Result
)
=
upickle
.
default
.
write
(
r
)
}
class
Servlet
extends
ScalatraServlet
{
class
Servlet
extends
ScalatraServlet
with
AuthenticationSupport
{
val
basePath
=
"shared"
get
(
"/"
)
{
contentType
=
"text/html"
tags
.
html
(
tags
.
head
(
tags
.
meta
(
tags
.
httpEquiv
:=
"Content-Type"
,
tags
.
content
:=
"text/html; charset=UTF-8"
),
...
...
@@ -27,6 +30,7 @@ class Servlet extends ScalatraServlet {
tags
.
script
(
tags
.
`type`
:=
"text/javascript"
,
tags
.
src
:=
"js/gate.js"
)
),
tags
.
body
(
div
(
"authenticated: "
+
basicAuth
),
script
(
"client.Gate.run();"
)
)
)
...
...
@@ -40,3 +44,37 @@ class Servlet extends ScalatraServlet {
}
}
object
Data
{
type
Login
=
String
type
Password
=
String
case
class
User
(
login
:
Login
)
}
trait
AuthenticationSupport
extends
ScentrySupport
[
Data.User
]
with
BasicAuthSupport
[
Data.User
]
{
this:
Servlet
⇒
val
realm
=
"Gate authentication"
protected
def
fromSession
=
{
case
id
:
String
⇒
Data.User
(
id
)
}
protected
def
toSession
=
{
case
usr
:
Data.User
⇒
usr.login
}
protected
val
scentryConfig
=
(
new
ScentryConfig
{}).
asInstanceOf
[
ScentryConfiguration
]
override
protected
def
configureScentry
=
{
scentry
.
unauthenticated
{
scentry
.
strategies
(
"DB"
).
unauthenticated
()
}
}
override
protected
def
registerAuthStrategies
=
{
scentry
.
register
(
"DB"
,
app
⇒
new
DBStrategy
(
app
,
realm
))
}
}
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