From 434a16f374d8169571c581a2765063eeb4bfa65a Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Thu, 24 Jan 2019 15:38:57 +0100 Subject: [PATCH 01/21] Implementation of Authorization provider --- app/authorization/AuthProvider.scala | 18 ++++++++++++++++++ build.sbt | 2 ++ conf/application.conf | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/authorization/AuthProvider.scala diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala new file mode 100644 index 00000000..118ae2bf --- /dev/null +++ b/app/authorization/AuthProvider.scala @@ -0,0 +1,18 @@ +package authorization + + + +import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} +object AuthProvider { + val jwtSecretKey: String = sys.env.getOrElse("DELPHI_JWT_SECRET","changeme") + def generateJwt(validFor: Long = 1, useGenericName: Boolean = false): String = { + val claim = JwtClaim() + .issuedNow + .expiresIn(validFor * 60) + + + Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) + } + + +} diff --git a/build.sbt b/build.sbt index edb6d96a..5ba57b18 100644 --- a/build.sbt +++ b/build.sbt @@ -51,3 +51,5 @@ libraryDependencies ++= Seq( "com.google.guava" % "guava" % "25.1-jre", "org.apache.commons" % "commons-compress" % "1.16" ) + +libraryDependencies += "com.pauldijou" %% "jwt-core" % "1.0.0" diff --git a/conf/application.conf b/conf/application.conf index 4f66e17b..da47b337 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -26,7 +26,7 @@ akka { # configuration at INFO level, including defaults and overrides, so it s worth # putting at the very top. # - # Put the following in your conf/logback.xml file: + # # # From 60daff21f711cdbd45d6175b0581712b2b8cb06b Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Wed, 30 Jan 2019 21:08:22 +0100 Subject: [PATCH 02/21] Implementation of Authorization for Delphi Management refs #105 --- app/authorization/AuthProvider.scala | 35 +++++++++++++++---- .../InstanceRegistryController.scala | 11 ++++++ conf/application.conf | 5 +++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 118ae2bf..dab1331d 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -1,18 +1,39 @@ -package authorization - +// Copyright (C) 2018 The Delphi Team. +// See the LICENCE file distributed with this work for additional +// information regarding copyright ownership. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package de.upb.cs.swt.delphi.crawler.authorization import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} -object AuthProvider { - val jwtSecretKey: String = sys.env.getOrElse("DELPHI_JWT_SECRET","changeme") - def generateJwt(validFor: Long = 1, useGenericName: Boolean = false): String = { +import play.api.Configuration + + +object AuthProvider { + + + def generateJwt(validFor: Long = 1, useGenericName: Boolean = false) (implicit configuration: Configuration): String = { + val jwtSecretKey = configuration.get[String]("play.http.secret.Jwtkey") val claim = JwtClaim() .issuedNow .expiresIn(validFor * 60) + .startsNow + . + ("user_id", if (useGenericName) configuration.get[String]("instanceName")) + . + ("user_type", "Component") Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) } - -} +} \ No newline at end of file diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index f714792c..55ef8e3a 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -27,6 +27,8 @@ import play.api.libs.ws.WSClient import akka.stream.Materializer import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} +import akka.http.scaladsl.model.headers.RawHeader +import de.upb.cs.swt.delphi.crawler.authorization.AuthProvider import play.api.mvc._ import scala.concurrent.ExecutionContext @@ -140,5 +142,14 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } }(myExecutionContext) } + def authentication(userName: String, password: String ): Action[AnyContent] = Unit { + request => ws.url(instanceRegistryUri + "/authenticate").withHeaders(RawHeader("Authorization",s"Bearer ${AuthProvider.generateJwt(useGenericName = true),userName,password}")) + .post("") + .map { response => new Status(response.status) + // map { response.status match { + // case 202 => + // ok(response.body)} + } + } } diff --git a/conf/application.conf b/conf/application.conf index da47b337..e60f78b9 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -374,5 +374,10 @@ app.instanceRegistryUri = ${?INSTANCE_REGISTRY_URI} app.instanceRegistryBasePath = "localhost:8087" app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} +//JwtKey +play.http.sys.env.get="JwtKey" +play.http.secret.Jwtkey="JwtKeyForDelphiManagement" +instanceName="DelphiManagement" + include "silhouette.conf" From c0a56e146ea6e6492c8b47dd29682334dfd3cca0 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Thu, 31 Jan 2019 13:38:07 +0100 Subject: [PATCH 03/21] Implementation of authenticate on InstanceRegistryController refs #105 --- .../InstanceRegistryController.scala | 50 +++++++++++-------- conf/application.conf | 2 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 55ef8e3a..6b56a990 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -29,9 +29,11 @@ import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} import akka.http.scaladsl.model.headers.RawHeader import de.upb.cs.swt.delphi.crawler.authorization.AuthProvider +import akka.http.scaladsl.Http +import akka.http.scaladsl.model.{HttpMethods, HttpRequest, StatusCodes} import play.api.mvc._ -import scala.concurrent.ExecutionContext +import scala.concurrent.{Await, ExecutionContext} trait MyExecutionContext extends ExecutionContext @@ -64,7 +66,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma val instanceRegistryUri = config.get[String]("app.instanceRegistryUri") val instanceRegistryBasePath = config.get[String]("app.instanceRegistryBasePath") - + def instances(componentType: String): Action[AnyContent] = Action.async { ws.url(instanceRegistryUri + "/instances").addQueryStringParameters("ComponentType" -> componentType).get().map { response => @@ -94,7 +96,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma }(myExecutionContext) } - def numberOfInstances(componentType: String) : Action[AnyContent] = Action.async { + def numberOfInstances(componentType: String): Action[AnyContent] = Action.async { // TODO: handle what should happen if the instance registry is not reachable. // TODO: create constants for the urls ws.url(instanceRegistryUri + "/numberOfInstances").addQueryStringParameters("ComponentType" -> componentType).get().map { response => @@ -108,10 +110,11 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } /** - * This function is for handling all(start, stop, play, pause, resume) POST request. - * To control the instance State - * @param componentId - */ + * This function is for handling all(start, stop, play, pause, resume) POST request. + * To control the instance State + * + * @param componentId + */ def handleRequest(action: String, instanceID: String): Action[AnyContent] = Action.async { request => @@ -124,11 +127,11 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } /** - * This function is for handling an POST request for adding an instance to the Scala web server - * - * @param componentType - * @param name - */ + * This function is for handling an POST request for adding an instance to the Scala web server + * + * @param componentType + * @param name + */ def postInstance(compType: String, name: String): Action[AnyContent] = Action.async { request => ws.url(instanceRegistryUri + "/deploy") .addQueryStringParameters("ComponentType" -> compType, "InstanceName" -> name) @@ -142,14 +145,19 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } }(myExecutionContext) } - def authentication(userName: String, password: String ): Action[AnyContent] = Unit { - request => ws.url(instanceRegistryUri + "/authenticate").withHeaders(RawHeader("Authorization",s"Bearer ${AuthProvider.generateJwt(useGenericName = true),userName,password}")) - .post("") - .map { response => new Status(response.status) - // map { response.status match { - // case 202 => - // ok(response.body)} - } - } + def authentication(userName: String, password: String) = Action.async { request => + ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Delphi-Authorization", s"Bearer ${AuthProvider.generateJwt(useGenericName = true)}")) + // .addQueryStringParameters("Username" -> userName, "Password" -> Password) + .post("") + .map { response => + if (response.status == 200) { + Ok + } else { + new Status(response.status) + } + } + } } + + diff --git a/conf/application.conf b/conf/application.conf index e60f78b9..369b365f 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -376,7 +376,7 @@ app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} //JwtKey play.http.sys.env.get="JwtKey" -play.http.secret.Jwtkey="JwtKeyForDelphiManagement" +play.http.secret.Jwtkey="changeme" instanceName="DelphiManagement" include "silhouette.conf" From 4b7f532d8aafe09a34ea8ed77801bab90616d8f5 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Thu, 31 Jan 2019 17:34:46 +0100 Subject: [PATCH 04/21] Authentication of Delphi-Management refs #105 --- app/authorization/AuthProvider.scala | 12 ++++++++ .../InstanceRegistryController.scala | 29 +++++++++++++++---- conf/application.conf | 3 +- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index dab1331d..1e2ce9ce 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -35,5 +35,17 @@ object AuthProvider { Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) } + def basicAuthJwt(validFor: Long =1)(implicit configuration: Configuration): String ={ + val jwtSecretKey = configuration.get[String]("play.http.secret.Jwtkey") + val username = configuration.get[String]("play.http.user") + val password = configuration.get[String]("play.http.pass") + val claim = JwtClaim() + .issuedNow + .expiresIn(validFor * 300) + .startsNow + . + ("username", username) + . + ("password", password) + Jwt.encode(claim,jwtSecretKey,JwtAlgorithm.HS256) + } } \ No newline at end of file diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 6b56a990..aea362ad 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -27,7 +27,7 @@ import play.api.libs.ws.WSClient import akka.stream.Materializer import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} -import akka.http.scaladsl.model.headers.RawHeader +import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials, RawHeader} import de.upb.cs.swt.delphi.crawler.authorization.AuthProvider import akka.http.scaladsl.Http import akka.http.scaladsl.model.{HttpMethods, HttpRequest, StatusCodes} @@ -146,14 +146,33 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma }(myExecutionContext) } - def authentication(userName: String, password: String) = Action.async { request => + def authentication()(implicit configuration: Configuration) = Action.async { + + /*val username = configuration.get[String]("play.http.user") + val password = configuration.get[String]("play.http.pass") + request => ws.url(instanceRegistryUri + "authenticate").withHttpHeaders("Authorization",Authorization(BasicHttpCredentials(username,password))) + */ + ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.basicAuthJwt()}")) + .post("") + .map { response => + if (response.status == 200) + { + Ok(jwtauthentication()) + } else + { + new Status(response.status) + } + } + } + def jwtauthentication() = Action.async { request => ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Delphi-Authorization", s"Bearer ${AuthProvider.generateJwt(useGenericName = true)}")) - // .addQueryStringParameters("Username" -> userName, "Password" -> Password) .post("") .map { response => - if (response.status == 200) { + if (response.status == 200) + { Ok - } else { + } else + { new Status(response.status) } } diff --git a/conf/application.conf b/conf/application.conf index 369b365f..5cc7c240 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -375,8 +375,9 @@ app.instanceRegistryBasePath = "localhost:8087" app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} //JwtKey -play.http.sys.env.get="JwtKey" play.http.secret.Jwtkey="changeme" +play.http.user="Username" +play.http.pass="password" instanceName="DelphiManagement" include "silhouette.conf" From 5690662022283a80eaeb21171ddb9736d7f68f79 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Sun, 3 Feb 2019 20:00:00 +0100 Subject: [PATCH 05/21] Authentication of Delphi Management --- app/controllers/FrontendController.scala | 2 +- app/controllers/InstanceRegistryController.scala | 14 ++++++++------ conf/application.conf | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/FrontendController.scala b/app/controllers/FrontendController.scala index ad6b8af4..e407703d 100644 --- a/app/controllers/FrontendController.scala +++ b/app/controllers/FrontendController.scala @@ -39,4 +39,4 @@ class FrontendController @Inject()(assets: Assets, errorHandler: HttpErrorHandle def assetOrDefault(resource: String): Action[AnyContent] = if (resource.contains(".")) assets.at(resource) else index -} \ No newline at end of file +} diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index aea362ad..0962107f 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -148,22 +148,23 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def authentication()(implicit configuration: Configuration) = Action.async { - /*val username = configuration.get[String]("play.http.user") - val password = configuration.get[String]("play.http.pass") - request => ws.url(instanceRegistryUri + "authenticate").withHttpHeaders("Authorization",Authorization(BasicHttpCredentials(username,password))) - */ - ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.basicAuthJwt()}")) + val username = configuration.get[String]("play.http.user") + val password = configuration.get[String]("play.http.pass") + val authHeader= Authorization(BasicHttpCredentials(username, password)) + ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Authorization", s"${authHeader}"),("Delphi-Authorization", s"${AuthProvider.generateJwt(useGenericName = true)}")) + //.withHttpHeaders(("Delphi-Authorization", s"Bearer ${AuthProvider.generateJwt(useGenericName = true)}")) .post("") .map { response => if (response.status == 200) { - Ok(jwtauthentication()) + Ok(println(response)) } else { new Status(response.status) } } } + /* def jwtauthentication() = Action.async { request => ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Delphi-Authorization", s"Bearer ${AuthProvider.generateJwt(useGenericName = true)}")) .post("") @@ -177,6 +178,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } } } + */ } diff --git a/conf/application.conf b/conf/application.conf index 5cc7c240..5ee9e815 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -376,8 +376,8 @@ app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} //JwtKey play.http.secret.Jwtkey="changeme" -play.http.user="Username" -play.http.pass="password" +play.http.user="admin" +play.http.pass="admin" instanceName="DelphiManagement" include "silhouette.conf" From dc7afc1cd66b6adb5feba4b240d34ff228c6cf05 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Sun, 3 Feb 2019 20:23:27 +0100 Subject: [PATCH 06/21] Code commenting and formmating refs #105 --- app/authorization/AuthProvider.scala | 28 +++++++-------- .../InstanceRegistryController.scala | 36 ++++++------------- conf/application.conf | 4 +-- 3 files changed, 24 insertions(+), 44 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 1e2ce9ce..fb4fc404 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -23,29 +23,25 @@ import play.api.Configuration object AuthProvider { + /** This method generates JWT token for registering Delphi-Management at the Instance-Registry + * + * + * @param validFor + * @param useGenericName + * @return + */ + + def generateJwt(validFor: Long = 1, useGenericName: Boolean = false) (implicit configuration: Configuration): String = { - val jwtSecretKey = configuration.get[String]("play.http.secret.Jwtkey") + val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") + val claim = JwtClaim() .issuedNow .expiresIn(validFor * 60) .startsNow - . + ("user_id", if (useGenericName) configuration.get[String]("instanceName")) + . + ("user_id", if (useGenericName) configuration.get[String]("play.http.instance")) . + ("user_type", "Component") - Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) } - def basicAuthJwt(validFor: Long =1)(implicit configuration: Configuration): String ={ - val jwtSecretKey = configuration.get[String]("play.http.secret.Jwtkey") - val username = configuration.get[String]("play.http.user") - val password = configuration.get[String]("play.http.pass") - val claim = JwtClaim() - .issuedNow - .expiresIn(validFor * 300) - .startsNow - . + ("username", username) - . + ("password", password) - Jwt.encode(claim,jwtSecretKey,JwtAlgorithm.HS256) - } - } \ No newline at end of file diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 0962107f..a247d139 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -22,18 +22,14 @@ import akka.actor.{ActorRef, ActorSystem} import javax.inject.Inject import play.api.{Configuration, Logger} import play.api.libs.concurrent.CustomExecutionContext -import play.api.libs.json._ import play.api.libs.ws.WSClient import akka.stream.Materializer import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} -import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials, RawHeader} +import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials} import de.upb.cs.swt.delphi.crawler.authorization.AuthProvider -import akka.http.scaladsl.Http -import akka.http.scaladsl.model.{HttpMethods, HttpRequest, StatusCodes} import play.api.mvc._ - -import scala.concurrent.{Await, ExecutionContext} +import scala.concurrent.ExecutionContext trait MyExecutionContext extends ExecutionContext @@ -145,40 +141,28 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } }(myExecutionContext) } - - def authentication()(implicit configuration: Configuration) = Action.async { + /** + * This function is to authenticate Delphi-Management at the Instance Registry + * + */ + def authentication()(implicit configuration: Configuration): Action[AnyContent] = Action.async { val username = configuration.get[String]("play.http.user") val password = configuration.get[String]("play.http.pass") val authHeader= Authorization(BasicHttpCredentials(username, password)) - ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Authorization", s"${authHeader}"),("Delphi-Authorization", s"${AuthProvider.generateJwt(useGenericName = true)}")) - //.withHttpHeaders(("Delphi-Authorization", s"Bearer ${AuthProvider.generateJwt(useGenericName = true)}")) + ws.url(instanceRegistryUri + "/authenticate") + .withHttpHeaders(("Authorization", s"${authHeader}"), ("Delphi-Authorization", s"${AuthProvider.generateJwt(useGenericName = true)}")) .post("") .map { response => if (response.status == 200) { - Ok(println(response)) + Ok } else { new Status(response.status) } } } - /* - def jwtauthentication() = Action.async { request => - ws.url(instanceRegistryUri + "/authenticate").withHttpHeaders(("Delphi-Authorization", s"Bearer ${AuthProvider.generateJwt(useGenericName = true)}")) - .post("") - .map { response => - if (response.status == 200) - { - Ok - } else - { - new Status(response.status) - } - } - } - */ } diff --git a/conf/application.conf b/conf/application.conf index 5ee9e815..a295818e 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -375,10 +375,10 @@ app.instanceRegistryBasePath = "localhost:8087" app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} //JwtKey -play.http.secret.Jwtkey="changeme" +play.http.secret.JWTkey="changeme" play.http.user="admin" play.http.pass="admin" -instanceName="DelphiManagement" +play.http.instance="DelphiManagement" include "silhouette.conf" From 6250f0ec5813a8e8afb9c7eced69b6cc8af2911f Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Mon, 4 Feb 2019 18:35:04 +0100 Subject: [PATCH 07/21] Fix of ambigious implicit values --- app/authorization/AuthProvider.scala | 9 ++++----- app/controllers/InstanceRegistryController.scala | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index fb4fc404..ba20a462 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -16,13 +16,13 @@ package de.upb.cs.swt.delphi.crawler.authorization +import javax.inject.Inject import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} import play.api.Configuration object AuthProvider { - /** This method generates JWT token for registering Delphi-Management at the Instance-Registry * * @@ -32,14 +32,13 @@ object AuthProvider { */ - def generateJwt(validFor: Long = 1, useGenericName: Boolean = false) (implicit configuration: Configuration): String = { + def generateJwt() (configuration: Configuration): String = { val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") - val claim = JwtClaim() .issuedNow - .expiresIn(validFor * 60) + .expiresIn(seconds=60) .startsNow - . + ("user_id", if (useGenericName) configuration.get[String]("play.http.instance")) + . + ("user_id", configuration.get[String]("play.http.instance")) . + ("user_type", "Component") Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index a247d139..44216509 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -150,8 +150,9 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma val username = configuration.get[String]("play.http.user") val password = configuration.get[String]("play.http.pass") val authHeader= Authorization(BasicHttpCredentials(username, password)) + //val JwtHeader = ws.url(instanceRegistryUri + "/authenticate") - .withHttpHeaders(("Authorization", s"${authHeader}"), ("Delphi-Authorization", s"${AuthProvider.generateJwt(useGenericName = true)}")) + .withHttpHeaders(("Authorization", s"${authHeader}"), ("Delphi-Authorization", s"${AuthProvider.generateJwt()(_)}")) .post("") .map { response => if (response.status == 200) From db5753eb519f3ac1600d499a2aeb65ca31137492 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Thu, 7 Feb 2019 16:25:27 +0100 Subject: [PATCH 08/21] Basic Authentication of Components with IR is now working refs #105 --- app/authorization/AuthProvider.scala | 15 +++++------ .../InstanceRegistryController.scala | 26 ++++++++++++------- conf/application.conf | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index ba20a462..39b49375 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -13,12 +13,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -package de.upb.cs.swt.delphi.crawler.authorization +package authorization -import javax.inject.Inject import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} -import play.api.Configuration object AuthProvider { @@ -27,19 +25,18 @@ object AuthProvider { * * * @param validFor - * @param useGenericName * @return */ - def generateJwt() (configuration: Configuration): String = { - val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") + def generateJwt(validFor: Long = 1): String = { + val jwtSecretKey = "changeme"// configuration.get[String]("play.http.secret.JWTkey") val claim = JwtClaim() .issuedNow - .expiresIn(seconds=60) + .expiresIn(validFor*300) .startsNow - . + ("user_id", configuration.get[String]("play.http.instance")) - . + ("user_type", "Component") + . + ("user_id", "Management")// configuration.get[String]("play.http.instance")) + . + ("user_type", "Admin") Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) } diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 51aab5cc..442d2087 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -27,10 +27,9 @@ import akka.stream.Materializer import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials} -import de.upb.cs.swt.delphi.crawler.authorization.AuthProvider import play.api.mvc._ import scala.concurrent.ExecutionContext - +import authorization.AuthProvider trait MyExecutionContext extends ExecutionContext @@ -62,10 +61,13 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma val instanceRegistryUri = config.get[String]("app.instanceRegistryUri") val instanceRegistryBasePath = config.get[String]("app.instanceRegistryBasePath") + val authheader = AuthProvider.generateJwt() def instances(componentType: String): Action[AnyContent] = Action.async { - ws.url(instanceRegistryUri + "/instances").addQueryStringParameters("ComponentType" -> componentType).get().map { response => + ws.url(instanceRegistryUri + "/instances" ).addQueryStringParameters("ComponentType" -> componentType) + .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + .get().map { response => // TODO: possible handling of parsing the data can be done here Ok(response.body) @@ -81,7 +83,9 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } def getNetwork(): Action[AnyContent] = Action.async { - ws.url(instanceRegistryUri + "/network").get().map { response => + + ws.url(instanceRegistryUri +"/instances" + "/network").withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + .get().map { response => // TODO: possible handling of parsing the data can be done here Logger.debug(response.body) if (response.status == 200) { @@ -95,7 +99,9 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def numberOfInstances(componentType: String): Action[AnyContent] = Action.async { // TODO: handle what should happen if the instance registry is not reachable. // TODO: create constants for the urls - ws.url(instanceRegistryUri + "/numberOfInstances").addQueryStringParameters("ComponentType" -> componentType).get().map { response => + ws.url(instanceRegistryUri + "/instances" + "/count").addQueryStringParameters("ComponentType" -> componentType) + .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + .get().map { response => // TODO: possible handling of parsing the data can be done here if (response.status == 200) { Ok(response.body) @@ -116,6 +122,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def handleRequest(action: String, instanceID: String): Action[AnyContent] = Action.async { request => ws.url(instanceRegistryUri + action) .addQueryStringParameters("Id" -> instanceID) + .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) .post("") .map { response => new Status(response.status) @@ -129,9 +136,10 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma * @param name */ def postInstance(compType: String, name: String): Action[AnyContent] = Action.async { request => - ws.url(instanceRegistryUri + "/deploy") + ws.url(instanceRegistryUri + "/instances" + "/deploy") .addQueryStringParameters("ComponentType" -> compType, "InstanceName" -> name) - .post("") + .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + .post(Map("ComponentType" -> compType, "InstanceName" -> name)) .map { response => response.status match { // scalastyle:off magic.number @@ -147,14 +155,14 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma * This function is to authenticate Delphi-Management at the Instance Registry * */ + //This method might be helpful when User Authentication is implemented. def authentication()(implicit configuration: Configuration): Action[AnyContent] = Action.async { val username = configuration.get[String]("play.http.user") val password = configuration.get[String]("play.http.pass") val authHeader= Authorization(BasicHttpCredentials(username, password)) - //val JwtHeader = ws.url(instanceRegistryUri + "/authenticate") - .withHttpHeaders(("Authorization", s"${authHeader}"), ("Delphi-Authorization", s"${AuthProvider.generateJwt()(_)}")) + .withHttpHeaders(("Authorization", s"${authHeader}"), ("Delphi-Authorization",s"${AuthProvider.generateJwt()}")) .post("") .map { response => if (response.status == 200) diff --git a/conf/application.conf b/conf/application.conf index a295818e..60254921 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -378,7 +378,7 @@ app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} play.http.secret.JWTkey="changeme" play.http.user="admin" play.http.pass="admin" -play.http.instance="DelphiManagement" +play.http.instance="Management" include "silhouette.conf" From 544113e949ee2c7e93b4610c65161c5f0e2ea0ea Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Thu, 7 Feb 2019 19:27:58 +0100 Subject: [PATCH 09/21] Adapting Delphi Management to new API. Adding Instance now works refs #113 --- .../InstanceRegistryController.scala | 14 +++- client/package-lock.json | 77 +++++-------------- 2 files changed, 29 insertions(+), 62 deletions(-) diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 442d2087..bd329375 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -22,14 +22,18 @@ import akka.actor.{ActorRef, ActorSystem} import javax.inject.Inject import play.api.{Configuration, Logger} import play.api.libs.concurrent.CustomExecutionContext -import play.api.libs.ws.WSClient +import play.api.libs.ws.{WSClient, WSResponse} import akka.stream.Materializer import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials} import play.api.mvc._ + import scala.concurrent.ExecutionContext import authorization.AuthProvider +import play.api.http.ContentTypes +import play.api.libs.json.Json +import play.api.libs.json._ trait MyExecutionContext extends ExecutionContext @@ -135,11 +139,12 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma * @param componentType * @param name */ - def postInstance(compType: String, name: String): Action[AnyContent] = Action.async { request => + def postInstance(compType: String, name: String): Action[AnyContent] = Action.async + { + request => ws.url(instanceRegistryUri + "/instances" + "/deploy") - .addQueryStringParameters("ComponentType" -> compType, "InstanceName" -> name) .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) - .post(Map("ComponentType" -> compType, "InstanceName" -> name)) + .post(Json.obj("ComponentType" -> compType, "InstanceName" -> name)) .map { response => response.status match { // scalastyle:off magic.number @@ -151,6 +156,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } }(myExecutionContext) } + /** * This function is to authenticate Delphi-Management at the Instance Registry * diff --git a/client/package-lock.json b/client/package-lock.json index 14852c2b..58b75d9a 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1248,7 +1248,6 @@ "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", "dev": true, - "optional": true, "requires": { "delegates": "^1.0.0", "readable-stream": "^2.0.6" @@ -2464,8 +2463,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true, - "optional": true + "dev": true }, "constants-browserify": { "version": "1.0.0", @@ -2876,8 +2874,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", - "dev": true, - "optional": true + "dev": true }, "depd": { "version": "1.1.2", @@ -3957,8 +3954,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -3979,14 +3975,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4001,20 +3995,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -4131,8 +4122,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -4144,7 +4134,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4159,7 +4148,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4167,14 +4155,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -4193,7 +4179,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -4274,8 +4259,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -4287,7 +4271,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4373,8 +4356,7 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -4410,7 +4392,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4430,7 +4411,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4474,14 +4454,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -4490,7 +4468,6 @@ "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", "integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=", "dev": true, - "optional": true, "requires": { "graceful-fs": "^4.1.2", "inherits": "~2.0.0", @@ -4503,7 +4480,6 @@ "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", "dev": true, - "optional": true, "requires": { "aproba": "^1.0.3", "console-control-strings": "^1.0.0", @@ -4541,8 +4517,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz", "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=", - "dev": true, - "optional": true + "dev": true }, "get-stream": { "version": "3.0.0", @@ -4786,8 +4761,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", - "dev": true, - "optional": true + "dev": true }, "has-value": { "version": "1.0.0", @@ -5548,8 +5522,7 @@ "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=", - "dev": true, - "optional": true + "dev": true }, "is-windows": { "version": "1.0.2", @@ -6254,7 +6227,6 @@ "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "dev": true, - "optional": true, "requires": { "graceful-fs": "^4.1.2", "parse-json": "^2.2.0", @@ -6267,8 +6239,7 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", - "dev": true, - "optional": true + "dev": true } } }, @@ -6542,8 +6513,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=", - "dev": true, - "optional": true + "dev": true }, "map-visit": { "version": "1.0.0", @@ -7175,7 +7145,6 @@ "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", "dev": true, - "optional": true, "requires": { "are-we-there-yet": "~1.1.2", "console-control-strings": "~1.1.0", @@ -8302,7 +8271,6 @@ "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", "dev": true, - "optional": true, "requires": { "load-json-file": "^1.0.0", "normalize-package-data": "^2.3.2", @@ -8314,7 +8282,6 @@ "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", "dev": true, - "optional": true, "requires": { "graceful-fs": "^4.1.2", "pify": "^2.0.0", @@ -8325,8 +8292,7 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", - "dev": true, - "optional": true + "dev": true } } }, @@ -8335,7 +8301,6 @@ "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", "dev": true, - "optional": true, "requires": { "find-up": "^1.0.0", "read-pkg": "^1.0.0" @@ -8346,7 +8311,6 @@ "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", "dev": true, - "optional": true, "requires": { "path-exists": "^2.0.0", "pinkie-promise": "^2.0.0" @@ -8357,7 +8321,6 @@ "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", "dev": true, - "optional": true, "requires": { "pinkie-promise": "^2.0.0" } @@ -9648,7 +9611,6 @@ "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", "dev": true, - "optional": true, "requires": { "is-utf8": "^0.2.0" } @@ -10970,7 +10932,6 @@ "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", "dev": true, - "optional": true, "requires": { "string-width": "^1.0.2 || 2" } From d5de64e55f9c0ee2ac939ac95b64aa668734afb2 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Fri, 8 Feb 2019 16:35:19 +0100 Subject: [PATCH 10/21] Adating Delphi Management methods according to the new API refs #113 --- .../InstanceRegistryController.scala | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index bd329375..5654d5eb 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -22,7 +22,7 @@ import akka.actor.{ActorRef, ActorSystem} import javax.inject.Inject import play.api.{Configuration, Logger} import play.api.libs.concurrent.CustomExecutionContext -import play.api.libs.ws.{WSClient, WSResponse} +import play.api.libs.ws.WSClient import akka.stream.Materializer import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} @@ -31,9 +31,9 @@ import play.api.mvc._ import scala.concurrent.ExecutionContext import authorization.AuthProvider -import play.api.http.ContentTypes + import play.api.libs.json.Json -import play.api.libs.json._ + trait MyExecutionContext extends ExecutionContext @@ -67,6 +67,11 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma val instanceRegistryBasePath = config.get[String]("app.instanceRegistryBasePath") val authheader = AuthProvider.generateJwt() + /**This method maps list of instances with specific componentType. + * + * @param componentType + * @return + */ def instances(componentType: String): Action[AnyContent] = Action.async { ws.url(instanceRegistryUri + "/instances" ).addQueryStringParameters("ComponentType" -> componentType) @@ -86,9 +91,15 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } } + /**Called to fetch network graph of current registry. Contains a list of all instances and all links + * currently registered. + * + * @return + */ + def getNetwork(): Action[AnyContent] = Action.async { - ws.url(instanceRegistryUri +"/instances" + "/network").withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + ws.url(instanceRegistryUri + "/instances" + "/network").withHttpHeaders(("Authorization",s"Bearer ${authheader}")) .get().map { response => // TODO: possible handling of parsing the data can be done here Logger.debug(response.body) @@ -100,6 +111,14 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma }(myExecutionContext) } + /** + * Fetches the number of instances for the specified ComponentType. The ComponentType is an optional parameter which is passed as an query + * argument named 'ComponentType' + * + * @param componentType + * @return + */ + def numberOfInstances(componentType: String): Action[AnyContent] = Action.async { // TODO: handle what should happen if the instance registry is not reachable. // TODO: create constants for the urls @@ -117,15 +136,14 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma /** * This function is for handling all(start, stop, play, pause, resume) POST request. - * To control the instance State + * To control the instance State (E.g. /instances/42/stop ) * * @param componentId */ def handleRequest(action: String, instanceID: String): Action[AnyContent] = Action.async { request => - ws.url(instanceRegistryUri + action) - .addQueryStringParameters("Id" -> instanceID) + ws.url(instanceRegistryUri + "/instances" + "/" + instanceID + action) .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) .post("") .map { response => @@ -135,10 +153,12 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma /** * This function is for handling an POST request for adding an instance to the Scala web server + * (E.g. .../instances/deploy * * @param componentType * @param name */ + def postInstance(compType: String, name: String): Action[AnyContent] = Action.async { request => From d37dde2fd98ed6a7bba4bece626d39471d9578a8 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Fri, 8 Feb 2019 17:49:08 +0100 Subject: [PATCH 11/21] Adatpting to new API. refs #113 --- app/authorization/AuthProvider.scala | 2 +- .../InstanceRegistryController.scala | 26 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 39b49375..1f98e486 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -33,7 +33,7 @@ object AuthProvider { val jwtSecretKey = "changeme"// configuration.get[String]("play.http.secret.JWTkey") val claim = JwtClaim() .issuedNow - .expiresIn(validFor*300) + .expiresIn(validFor*1200) .startsNow . + ("user_id", "Management")// configuration.get[String]("play.http.instance")) . + ("user_type", "Admin") diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 5654d5eb..217de246 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -28,10 +28,8 @@ import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials} import play.api.mvc._ - import scala.concurrent.ExecutionContext import authorization.AuthProvider - import play.api.libs.json.Json @@ -65,7 +63,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma val instanceRegistryUri = config.get[String]("app.instanceRegistryUri") val instanceRegistryBasePath = config.get[String]("app.instanceRegistryBasePath") - val authheader = AuthProvider.generateJwt() + val authheader = ("Authorization",s"Bearer ${AuthProvider.generateJwt()}") /**This method maps list of instances with specific componentType. * @@ -74,8 +72,8 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma */ def instances(componentType: String): Action[AnyContent] = Action.async { - ws.url(instanceRegistryUri + "/instances" ).addQueryStringParameters("ComponentType" -> componentType) - .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + ws.url(instanceRegistryUri).addQueryStringParameters("ComponentType" -> componentType) + .withHttpHeaders(authheader) .get().map { response => // TODO: possible handling of parsing the data can be done here @@ -99,7 +97,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def getNetwork(): Action[AnyContent] = Action.async { - ws.url(instanceRegistryUri + "/instances" + "/network").withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + ws.url(instanceRegistryUri + "/network").withHttpHeaders(authheader) .get().map { response => // TODO: possible handling of parsing the data can be done here Logger.debug(response.body) @@ -122,8 +120,8 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def numberOfInstances(componentType: String): Action[AnyContent] = Action.async { // TODO: handle what should happen if the instance registry is not reachable. // TODO: create constants for the urls - ws.url(instanceRegistryUri + "/instances" + "/count").addQueryStringParameters("ComponentType" -> componentType) - .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + ws.url(instanceRegistryUri + "/count").addQueryStringParameters("ComponentType" -> componentType) + .withHttpHeaders(authheader) .get().map { response => // TODO: possible handling of parsing the data can be done here if (response.status == 200) { @@ -143,8 +141,8 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def handleRequest(action: String, instanceID: String): Action[AnyContent] = Action.async { request => - ws.url(instanceRegistryUri + "/instances" + "/" + instanceID + action) - .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + ws.url(instanceRegistryUri + instanceID + action) + .withHttpHeaders(authheader) .post("") .map { response => new Status(response.status) @@ -162,8 +160,8 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def postInstance(compType: String, name: String): Action[AnyContent] = Action.async { request => - ws.url(instanceRegistryUri + "/instances" + "/deploy") - .withHttpHeaders(("Authorization",s"Bearer ${authheader}")) + ws.url(instanceRegistryUri + "/deploy") + .withHttpHeaders(authheader) .post(Json.obj("ComponentType" -> compType, "InstanceName" -> name)) .map { response => response.status match { @@ -200,6 +198,4 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } } } -} - - +} \ No newline at end of file From bf97647f13e5d4652fadd6e266f622024712f241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Sun, 10 Feb 2019 20:58:39 +0100 Subject: [PATCH 12/21] updated api endpoint for getting the whole instance network --- app/controllers/InstanceRegistryController.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 217de246..205eb48f 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -97,7 +97,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def getNetwork(): Action[AnyContent] = Action.async { - ws.url(instanceRegistryUri + "/network").withHttpHeaders(authheader) + ws.url(instanceRegistryUri + "/instances/network").withHttpHeaders(authheader) .get().map { response => // TODO: possible handling of parsing the data can be done here Logger.debug(response.body) From 742faed70c5576d0188b0623c5d129fd8c33cd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Sun, 10 Feb 2019 21:10:27 +0100 Subject: [PATCH 13/21] removed unneccessary user name passwort config --- conf/application.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/conf/application.conf b/conf/application.conf index 60254921..09536b25 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -376,8 +376,6 @@ app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} //JwtKey play.http.secret.JWTkey="changeme" -play.http.user="admin" -play.http.pass="admin" play.http.instance="Management" include "silhouette.conf" From 15003f6bc36900a2122b34d6c03c4d88b53384d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Sun, 10 Feb 2019 21:10:38 +0100 Subject: [PATCH 14/21] corrected new api path for post instance --- app/controllers/InstanceRegistryController.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 205eb48f..43b3e349 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -160,7 +160,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def postInstance(compType: String, name: String): Action[AnyContent] = Action.async { request => - ws.url(instanceRegistryUri + "/deploy") + ws.url(instanceRegistryUri + "/instances/deploy") .withHttpHeaders(authheader) .post(Json.obj("ComponentType" -> compType, "InstanceName" -> name)) .map { response => From 891949958441a6fbdbaebf9440a411ad9fd64bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Mon, 11 Feb 2019 10:52:41 +0100 Subject: [PATCH 15/21] updated the handle action endpoint to new api --- app/controllers/InstanceRegistryController.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 43b3e349..a61fac0e 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -141,7 +141,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def handleRequest(action: String, instanceID: String): Action[AnyContent] = Action.async { request => - ws.url(instanceRegistryUri + instanceID + action) + ws.url(instanceRegistryUri + "/instances/" + instanceID + action) .withHttpHeaders(authheader) .post("") .map { response => From f668a3b3b7cc2618b1f6e979f5b19293ab52b2ae Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Mon, 11 Feb 2019 22:34:30 +0100 Subject: [PATCH 16/21] Now token expires after 30 minutes and Strings are loaded from Configuration file refs #105 --- app/authorization/AuthProvider.scala | 34 +++++++++---------- .../InstanceRegistryController.scala | 2 ++ conf/application.conf | 1 + 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 1f98e486..80a89fc1 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -17,27 +17,27 @@ package authorization import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} +import play.api.Configuration + object AuthProvider { -object AuthProvider { + /** This method generates JWT token for registering Delphi-Management at the Instance-Registry + * + * @param validFor + * @return + */ - /** This method generates JWT token for registering Delphi-Management at the Instance-Registry - * - * - * @param validFor - * @return - */ + def generateJwt(validFor: Long = 1)(implicit configuration: Configuration): String = { - def generateJwt(validFor: Long = 1): String = { - val jwtSecretKey = "changeme"// configuration.get[String]("play.http.secret.JWTkey") - val claim = JwtClaim() - .issuedNow - .expiresIn(validFor*1200) - .startsNow - . + ("user_id", "Management")// configuration.get[String]("play.http.instance")) - . + ("user_type", "Admin") + val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") + val claim = JwtClaim() + .issuedNow + .expiresIn(validFor * 1800) + .startsNow + . +("user_id", configuration.get[String]("play.http.instance")) + . +("user_type", "Admin") - Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) + Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) + } } -} \ No newline at end of file diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index a61fac0e..a4c076a1 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -180,6 +180,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma * */ //This method might be helpful when User Authentication is implemented. + /* def authentication()(implicit configuration: Configuration): Action[AnyContent] = Action.async { val username = configuration.get[String]("play.http.user") @@ -198,4 +199,5 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } } } + */ } \ No newline at end of file diff --git a/conf/application.conf b/conf/application.conf index 09536b25..4d1a96d3 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -378,5 +378,6 @@ app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH} play.http.secret.JWTkey="changeme" play.http.instance="Management" + include "silhouette.conf" From 8c786eafff5c93a4df4399bc85a12b7e1586c0f0 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Tue, 12 Feb 2019 01:55:57 +0100 Subject: [PATCH 17/21] Scheduling of Generation of Tokens refs #105 --- app/authorization/AuthProvider.scala | 2 +- app/controllers/InstanceRegistryController.scala | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 80a89fc1..008709d8 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -33,7 +33,7 @@ import play.api.Configuration val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") val claim = JwtClaim() .issuedNow - .expiresIn(validFor * 1800) + .expiresIn(validFor * 360) .startsNow . +("user_id", configuration.get[String]("play.http.instance")) . +("user_type", "Admin") diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index a4c076a1..7dbf36a1 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -26,11 +26,11 @@ import play.api.libs.ws.WSClient import akka.stream.Materializer import play.api.libs.streams.ActorFlow import actors.{ClientSocketActor, PublishSocketMessageActor} -import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials} import play.api.mvc._ import scala.concurrent.ExecutionContext import authorization.AuthProvider import play.api.libs.json.Json +import scala.concurrent.duration._ trait MyExecutionContext extends ExecutionContext @@ -63,7 +63,13 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma val instanceRegistryUri = config.get[String]("app.instanceRegistryUri") val instanceRegistryBasePath = config.get[String]("app.instanceRegistryBasePath") - val authheader = ("Authorization",s"Bearer ${AuthProvider.generateJwt()}") + var authheader = ("Authorization", s"Bearer ${newJWTtoken()}") + system.scheduler.schedule(0 seconds,5 minutes){ + newJWTtoken() + } + def newJWTtoken(): String ={ + AuthProvider.generateJwt() + } /**This method maps list of instances with specific componentType. * From a02df69480406412f7e9a99daf245a065f42a9a9 Mon Sep 17 00:00:00 2001 From: ayybeeshafi Date: Tue, 12 Feb 2019 23:31:04 +0100 Subject: [PATCH 18/21] Generation of token at each method call --- app/authorization/AuthProvider.scala | 2 +- .../InstanceRegistryController.scala | 47 +++---------------- 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 008709d8..19a57524 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -33,7 +33,7 @@ import play.api.Configuration val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") val claim = JwtClaim() .issuedNow - .expiresIn(validFor * 360) + .expiresIn(validFor * 300) .startsNow . +("user_id", configuration.get[String]("play.http.instance")) . +("user_type", "Admin") diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 7dbf36a1..1912ef40 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -30,7 +30,7 @@ import play.api.mvc._ import scala.concurrent.ExecutionContext import authorization.AuthProvider import play.api.libs.json.Json -import scala.concurrent.duration._ + trait MyExecutionContext extends ExecutionContext @@ -63,13 +63,6 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma val instanceRegistryUri = config.get[String]("app.instanceRegistryUri") val instanceRegistryBasePath = config.get[String]("app.instanceRegistryBasePath") - var authheader = ("Authorization", s"Bearer ${newJWTtoken()}") - system.scheduler.schedule(0 seconds,5 minutes){ - newJWTtoken() - } - def newJWTtoken(): String ={ - AuthProvider.generateJwt() - } /**This method maps list of instances with specific componentType. * @@ -77,9 +70,8 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma * @return */ def instances(componentType: String): Action[AnyContent] = Action.async { - ws.url(instanceRegistryUri).addQueryStringParameters("ComponentType" -> componentType) - .withHttpHeaders(authheader) + .withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}")) .get().map { response => // TODO: possible handling of parsing the data can be done here @@ -102,8 +94,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma */ def getNetwork(): Action[AnyContent] = Action.async { - - ws.url(instanceRegistryUri + "/instances/network").withHttpHeaders(authheader) + ws.url(instanceRegistryUri + "/instances/network").withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}")) .get().map { response => // TODO: possible handling of parsing the data can be done here Logger.debug(response.body) @@ -127,7 +118,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma // TODO: handle what should happen if the instance registry is not reachable. // TODO: create constants for the urls ws.url(instanceRegistryUri + "/count").addQueryStringParameters("ComponentType" -> componentType) - .withHttpHeaders(authheader) + .withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}")) .get().map { response => // TODO: possible handling of parsing the data can be done here if (response.status == 200) { @@ -148,7 +139,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma def handleRequest(action: String, instanceID: String): Action[AnyContent] = Action.async { request => ws.url(instanceRegistryUri + "/instances/" + instanceID + action) - .withHttpHeaders(authheader) + .withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}")) .post("") .map { response => new Status(response.status) @@ -167,7 +158,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma { request => ws.url(instanceRegistryUri + "/instances/deploy") - .withHttpHeaders(authheader) + .withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}")) .post(Json.obj("ComponentType" -> compType, "InstanceName" -> name)) .map { response => response.status match { @@ -180,30 +171,4 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } }(myExecutionContext) } - - /** - * This function is to authenticate Delphi-Management at the Instance Registry - * - */ - //This method might be helpful when User Authentication is implemented. - /* - def authentication()(implicit configuration: Configuration): Action[AnyContent] = Action.async { - - val username = configuration.get[String]("play.http.user") - val password = configuration.get[String]("play.http.pass") - val authHeader= Authorization(BasicHttpCredentials(username, password)) - ws.url(instanceRegistryUri + "/authenticate") - .withHttpHeaders(("Authorization", s"${authHeader}"), ("Delphi-Authorization",s"${AuthProvider.generateJwt()}")) - .post("") - .map { response => - if (response.status == 200) - { - Ok - } else - { - new Status(response.status) - } - } - } - */ } \ No newline at end of file From 84ae01f9892196e684cb8823ba2f15fb3348ccb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Wed, 13 Feb 2019 17:30:27 +0100 Subject: [PATCH 19/21] auto refreshing expired token --- app/authorization/AuthProvider.scala | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 19a57524..1990ef72 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -20,6 +20,7 @@ import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} import play.api.Configuration object AuthProvider { + var token = "" /** This method generates JWT token for registering Delphi-Management at the Instance-Registry * @@ -28,16 +29,17 @@ import play.api.Configuration */ def generateJwt(validFor: Long = 1)(implicit configuration: Configuration): String = { - - val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") - val claim = JwtClaim() - .issuedNow - .expiresIn(validFor * 300) - .startsNow - . +("user_id", configuration.get[String]("play.http.instance")) - . +("user_type", "Admin") - - Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) + if (token == "" || !Jwt.isValid(token, jwtSecretKey, Seq(JwtAlgorithm.HS256))) { + val claim = JwtClaim() + .issuedNow + .expiresIn(validFor * 300) + .startsNow + . +("user_id", configuration.get[String]("play.http.instance")) + . +("user_type", "Admin") + + token = Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) + } + return token } } From 88d758e61943f127a1667e72437db4c69c8a02ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Thu, 14 Feb 2019 10:34:30 +0100 Subject: [PATCH 20/21] fixed style issue regarding return --- app/authorization/AuthProvider.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index 1990ef72..fde8a574 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -40,6 +40,6 @@ import play.api.Configuration token = Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) } - return token + token } } From 7215ab30e1e1bfbcb72ec9bbdff838c19551b734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Thu, 14 Feb 2019 11:03:46 +0100 Subject: [PATCH 21/21] scala style fixes --- app/authorization/AuthProvider.scala | 9 +++++---- app/controllers/InstanceRegistryController.scala | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/authorization/AuthProvider.scala b/app/authorization/AuthProvider.scala index fde8a574..7607a411 100644 --- a/app/authorization/AuthProvider.scala +++ b/app/authorization/AuthProvider.scala @@ -20,7 +20,8 @@ import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} import play.api.Configuration object AuthProvider { - var token = "" + + var Token = "" // scalastyle:ignore /** This method generates JWT token for registering Delphi-Management at the Instance-Registry * @@ -30,7 +31,7 @@ import play.api.Configuration def generateJwt(validFor: Long = 1)(implicit configuration: Configuration): String = { val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey") - if (token == "" || !Jwt.isValid(token, jwtSecretKey, Seq(JwtAlgorithm.HS256))) { + if (Token == "" || !Jwt.isValid(Token, jwtSecretKey, Seq(JwtAlgorithm.HS256))) { val claim = JwtClaim() .issuedNow .expiresIn(validFor * 300) @@ -38,8 +39,8 @@ import play.api.Configuration . +("user_id", configuration.get[String]("play.http.instance")) . +("user_type", "Admin") - token = Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) + Token = Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256) } - token + Token } } diff --git a/app/controllers/InstanceRegistryController.scala b/app/controllers/InstanceRegistryController.scala index 1912ef40..e464a81c 100644 --- a/app/controllers/InstanceRegistryController.scala +++ b/app/controllers/InstanceRegistryController.scala @@ -171,4 +171,4 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma } }(myExecutionContext) } -} \ No newline at end of file +}