Skip to content

Commit 2607136

Browse files
committed
Implementation of /authenticate endpoint at Delphi Management end refs #117
1 parent 88d758e commit 2607136

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

app/controllers/InstanceRegistryController.scala

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import play.api.libs.ws.WSClient
2626
import akka.stream.Materializer
2727
import play.api.libs.streams.ActorFlow
2828
import actors.{ClientSocketActor, PublishSocketMessageActor}
29+
import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials}
2930
import play.api.mvc._
31+
3032
import scala.concurrent.ExecutionContext
3133
import authorization.AuthProvider
3234
import play.api.libs.json.Json
@@ -63,8 +65,11 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
6365

6466
val instanceRegistryUri = config.get[String]("app.instanceRegistryUri")
6567
val instanceRegistryBasePath = config.get[String]("app.instanceRegistryBasePath")
68+
val username = config.get[String]("play.http.user")
69+
val password = config.get[String]("play.http.password")
70+
val authHeader = Authorization(BasicHttpCredentials(username, password))
6671

67-
/**This method maps list of instances with specific componentType.
72+
/** This method maps list of instances with specific componentType.
6873
*
6974
* @param componentType
7075
* @return
@@ -87,7 +92,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
8792
}
8893
}
8994

90-
/**Called to fetch network graph of current registry. Contains a list of all instances and all links
95+
/** Called to fetch network graph of current registry. Contains a list of all instances and all links
9196
* currently registered.
9297
*
9398
* @return
@@ -154,21 +159,35 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
154159
* @param name
155160
*/
156161

157-
def postInstance(compType: String, name: String): Action[AnyContent] = Action.async
158-
{
162+
def postInstance(compType: String, name: String): Action[AnyContent] = Action.async {
159163
request =>
160-
ws.url(instanceRegistryUri + "/instances/deploy")
161-
.withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}"))
162-
.post(Json.obj("ComponentType" -> compType, "InstanceName" -> name))
164+
ws.url(instanceRegistryUri + "/instances/deploy")
165+
.withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}"))
166+
.post(Json.obj("ComponentType" -> compType, "InstanceName" -> name))
167+
.map { response =>
168+
response.status match {
169+
// scalastyle:off magic.number
170+
case 202 =>
171+
// scalastyle:on magic.number
172+
Ok(response.body)
173+
case x: Any =>
174+
new Status(x)
175+
}
176+
}(myExecutionContext)
177+
}
178+
179+
//This method might be helpful when User Authentication is implemented.
180+
181+
def authentication(): Action[AnyContent] = Action.async {
182+
ws.url(instanceRegistryUri + "/users" + "/authenticate")
183+
.withHttpHeaders(("Authorization", s"${authHeader}"), ("Delphi-Authorization", s"Bearer ${AuthProvider.generateJwt()}"))
184+
.post("")
163185
.map { response =>
164-
response.status match {
165-
// scalastyle:off magic.number
166-
case 202 =>
167-
// scalastyle:on magic.number
168-
Ok(response.body)
169-
case x: Any =>
170-
new Status(x)
186+
if (response.status == 200) {
187+
Ok(response.body)
188+
} else {
189+
new Status(response.status)
171190
}
172-
}(myExecutionContext)
191+
}
173192
}
174193
}

conf/application.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ app.instanceRegistryBasePath = ${?INSTANCE_REGISTRY_BASE_PATH}
377377
//JwtKey
378378
play.http.secret.JWTkey="changeme"
379379
play.http.instance="Management"
380+
play.http.user="admin"
381+
play.http.user="admin"
380382

381383

382384
include "silhouette.conf"

0 commit comments

Comments
 (0)