Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
ExternalAPIs
OAI
Commits
24d9475b
Commit
24d9475b
authored
Sep 11, 2020
by
Günter Hipler
Browse files
first implementation resumption token
parent
7c6b8973
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/org/swissbib/memobase/oai/common/util/ResumptionToken.scala
View file @
24d9475b
package
org.swissbib.memobase.oai.common.util
import
java.time.
{
Clock
,
ZoneId
}
import
pdi.jwt.
{
Jwt
,
JwtAlgorithm
,
JwtClaim
,
JwtHeader
}
import
play.api.libs.json.Json
import
play.api.libs.json._
import
play.api.libs.json.Reads._
class
ResumptionToken
{
import
scala.util.
{
Failure
,
Success
,
Try
}
case
class
ResumptionToken
(
issuer
:
String
,
issuedAt
:
Long
,
expiration
:
Long
,
subject
:
String
,
claim
:
JwtClaim
)
object
ESResumptionTokenHelper
{
implicit
val
clock
:
Clock
=
Clock
.
system
(
ZoneId
.
of
(
"Europe/Zurich"
))
def
apply
(
esCursor
:
String
,
expiresInSeconds
:
Long
=
180
)
:
ResumptionToken
=
{
val
jwtClaim
=
JwtClaim
(
subject
=
Option
(
esCursor
),
issuer
=
Option
(
"memobase OAI server"
)
).
issuedNow
.
expiresIn
(
expiresInSeconds
)
ResumptionToken
(
jwtClaim
.
issuer
.
get
,
jwtClaim
.
issuedAt
.
get
,
jwtClaim
.
expiration
.
get
,
jwtClaim
.
subject
.
get
,
jwtClaim
)
}
def
createOaiToken
(
rt
:
ResumptionToken
,
key
:
String
=
"oaimemobase"
)
:
String
=
{
Jwt
.
encode
(
JwtHeader
(
JwtAlgorithm
.
HS384
),
rt
.
claim
,
key
)
}
def
createResumptionToken
(
oaiToken
:
String
,
key
:
String
=
"oaimemobase"
)
:
Try
[
ResumptionToken
]
=
{
val
decoded
=
Jwt
.
decodeRaw
(
oaiToken
,
key
,
Seq
(
JwtAlgorithm
.
HS384
))
decoded
match
{
case
Success
(
value
)
=>
val
jsnonNode
:
JsValue
=
Json
.
parse
(
value
)
//val issuer = (jsnonNode \ "iss").as[String]
//val subject = (jsnonNode \ "sub").as[String]
val
expiration
=
(
jsnonNode
\
"exp"
).
as
[
Long
]
val
issuedAt
=
(
jsnonNode
\
"iat"
).
as
[
Long
]
Success
(
ResumptionToken
(
"lll"
,
expiration
,
issuedAt
,
"mySubject"
,
JwtClaim
(
"lll"
).
issuedNow
.
expiresIn
(
10
)))
case
Failure
(
value
)
=>
Failure
(
value
)
}
}
}
object
Test
extends
App
{
val
rt
=
ESResumptionTokenHelper
(
"1234"
,
5
)
val
token
=
ESResumptionTokenHelper
.
createOaiToken
(
rt
)
//Thread.sleep(6000)
ESResumptionTokenHelper
.
createResumptionToken
(
token
)
match
{
case
Success
(
value
)
=>
println
(
value
)
case
Failure
(
value
)
=>
println
(
value
)
}
}
app/org/swissbib/memobase/oai/runner/ResultData.scala
0 → 100644
View file @
24d9475b
package
org.swissbib.memobase.oai.runner
import
scala.xml.Node
case
class
ResultList
(
repositoryToken
:
Option
[
String
],
result
:
Option
[
Seq
[(
String
,
Node
)]])
case
class
Result
()
app/scripts/jwt.sc
0 → 100644
View file @
24d9475b
import
java.time.
{
Clock
,
ZoneId
}
import
com.fasterxml.jackson.databind.JsonNode
import
pdi.jwt.
{
Jwt
,
JwtAlgorithm
,
JwtClaim
,
JwtHeader
,
JwtOptions
}
import
org.joda.time.
{
DateTime
,
Duration
,
Instant
,
LocalDateTime
}
import
play.api.libs.json.Json
import
play.api.libs.json._
import
play.api.libs.json.Reads._
import
play.api.libs.functional.syntax._
import
scala.util.
{
Failure
,
Success
}
val
token
=
Jwt
.
encode
(
"""{"user":1}"""
,
"secretKey"
,
JwtAlgorithm
.
HS256
)
implicit
val
clock
:
Clock
=
Clock
.
system
(
ZoneId
.
of
(
"Europe/Zurich"
))
val
jwtClaim
=
JwtClaim
(
subject
=
Option
(
"DnF1ZXJ5VGhlbkZldGNoAwAAAAAAAShoFlVKdDRxRWdGUk5XVjRtblYzMXd5V0EAAAAAAAYJKRZuWVYyeWFBWlNDQzhsQ3RBd0dDZ1BBAAAAAAAGCSgWbllWMnlhQVpTQ0M4bEN0QXdHQ2dQQQ=="
),
issuer
=
Option
(
"memobase OAI server"
)
).
issuedNow
.
expiresIn
(
10
)
val
key
=
"swortfish"
//
val
tokenWithClaim
=
Jwt
.
encode
(
jwtClaim
,
key
,
JwtAlgorithm
.
HS384
)
val
tokenWithClaim
=
Jwt
.
encode
(
JwtHeader
(
JwtAlgorithm
.
HS384
),
jwtClaim
,
key
)
//
Thread
.
sleep
(
3000
)
//
Jwt
.
decode
(
tokenWithClaim
,
key
)
//
val
decoded
=
Jwt
.
decodeAll
(
tokenWithClaim
,
"swortfish"
,
Seq
(
JwtAlgorithm
.
HS384
))
val
decoded
=
Jwt
.
decodeRaw
(
tokenWithClaim
,
"swortfish"
,
Seq
(
JwtAlgorithm
.
HS384
))
decoded
match
{
case
Success
(
value
)
=>
//
val
j
=
JwtClaim
(
value
)
//
println
(
j
.
subject
)
//
val
(
header
,
claim
,
string
)
=
decoded
.
get
//
println
(
"is valid: "
+
Jwt
.
isValid
(
tokenWithClaim
))
val
jsnonNode
:
JsValue
=
Json
.
parse
(
value
)
val
issuer
=
(
jsnonNode
\
"iss"
).
as
[
String
]
val
subject
=
(
jsnonNode
\
"sub"
).
as
[
String
]
println
(
issuer
)
println
(
subject
)
//
println
(
decoded
)
println
(
jsnonNode
)
case
Failure
(
exception
)
=>
println
(
exception
)
}
build.sbt
View file @
24d9475b
...
...
@@ -35,7 +35,8 @@ lazy val root = (project in file("."))
json2xml
,
scala_xml_module
,
upickl
,
httprequests
httprequests
,
jwtcore
),
scalacOptions
++=
Seq
(
"-feature"
,
...
...
notes/allgemein.txt
0 → 100644
View file @
24d9475b
Nutzung von Kibana
docker run --network host -e elasticsearch.hosts:http://localhost:8080 -p 5601:5601 docker.elastic.co/kibana/kibana:7.6.1
\ No newline at end of file
notes/aufrufe.oai.swissbib.txt
View file @
24d9475b
...
...
@@ -29,3 +29,26 @@ http://localhost:9000/?verb=ListSets
http://localhost:9000/?verb=ListSets&resumptionToken=1234
http://localhost:9000/?verb=Identify
Aufrufe ES scroll api
POST documents-v8/_search?scroll=1m
{
"size": 100,
"query": {
"match_all": {}
}
}
POST /_search/scroll
{
"scroll" : "1m",
"scroll_id" : "DnF1ZXJ5VGhlbkZldGNoAwAAAAAAAB5dFlp2eUpoaWZzUURTMGRteTl6bHN0ckEAAAAAAAYITRZuWVYyeWFBWlNDQzhsQ3RBd0dDZ1BBAAAAAAAAHl4WWnZ5SmhpZnNRRFMwZG15OXpsc3RyQQ=="
}
_scroll_id in response
{
"_scroll_id" : "DnF1ZXJ5VGhlbkZldGNoAwAAAAAAAB5dFlp2eUpoaWZzUURTMGRteTl6bHN0ckEAAAAAAAYITRZuWVYyeWFBWlNDQzhsQ3RBd0dDZ1BBAAAAAAAAHl4WWnZ5SmhpZnNRRFMwZG15OXpsc3RyQQ==",
"took" : 9,
project/Dependencies.scala
View file @
24d9475b
...
...
@@ -40,5 +40,7 @@ object Dependencies {
lazy
val
scala_xml_module
=
"org.scala-lang.modules"
%%
"scala-xml"
%
"1.3.0"
lazy
val
httprequests
=
"com.lihaoyi"
%%
"requests"
%
"0.6.5"
lazy
val
jwtcore
=
"com.pauldijou"
%%
"jwt-core"
%
"4.3.0"
}
Write
Preview
Supports
Markdown
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