Skip to content

Commit b8a817c

Browse files
Merge pull request #115 from delphi-hub/authTest
Authentication tests, additional user management endpoints
2 parents e778e6e + 05cbc66 commit b8a817c

File tree

10 files changed

+779
-54
lines changed

10 files changed

+779
-54
lines changed

OpenAPISpecification.yaml

Lines changed: 101 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ paths:
3131
tags:
3232
- Meta
3333
summary: Retreives general configuration information
34-
description: Retrieves an object containing the most important configuration values of the registry. This contains the docker and traefik URIs.
34+
description: >-
35+
Retrieves an object containing the most important configuration values
36+
of the registry. This contains the docker and traefik URIs.
3537
operationId: configurationInfo
3638
responses:
3739
'200':
@@ -41,51 +43,52 @@ paths:
4143
properties:
4244
DockerHttpApi:
4345
type: string
44-
example: "172.0.2.1:9095"
46+
example: '172.0.2.1:9095'
4547
TraefikProxyUri:
4648
type: string
47-
example: "172.0.2.1:80"
49+
example: '172.0.2.1:80'
4850
/users/authenticate:
4951
post:
5052
tags:
5153
- User Management
5254
summary: Authenticates a user and returns a valid JWT
53-
description: >-
54-
This endpoints validates the username and password that must
55-
be supplied in the Authorization header (using HTTP Basic Authentication).
56-
If valid, a JSON Web Token will be generated and returned, that may be used
57-
to authenticate the user for subsequent requests.
55+
description: >-
56+
This endpoints validates the username and password that must be
57+
supplied in the Authorization header (using HTTP Basic Authentication).
58+
If valid, a JSON Web Token will be generated and returned, that may be
59+
used to authenticate the user for subsequent requests.
5860
operationId: authenticate
5961
parameters:
6062
- in: header
6163
name: Delphi-Authorization
62-
description: >-
63-
Valid JWT that autenticates the calling entity.
64+
description: Valid JWT that autenticates the calling entity.
6465
type: string
6566
required: true
6667
- in: header
6768
name: Authorization
68-
description: >-
69-
HTTP Basic Authentication following the schema 'Basic <User:Password>
70-
where the concatination of username and password is Base64-Encoded.
69+
description: >-
70+
HTTP Basic Authentication following the schema 'Basic
71+
<User:Password> where the concatination of username and password is
72+
Base64-Encoded.
7173
type: string
7274
required: true
7375
responses:
7476
'200':
75-
description: Supplied data is valid, a JWT is returned
77+
description: 'Supplied data is valid, a JWT is returned'
7678
schema:
7779
type: string
78-
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
80+
example: >-
81+
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
7982
'401':
80-
description: Unauthorized, invalid username / password supplied.
83+
description: 'Unauthorized, invalid username / password supplied.'
8184
/users/add:
8285
post:
8386
tags:
8487
- User Management
8588
summary: Adds a new users for the registry
8689
description: >-
87-
Adds a new user that is passed in the requests entity. The id of the user
88-
will be returned.
90+
Adds a new user that is passed in the requests entity. The id of the
91+
user will be returned.
8992
operationId: addUser
9093
parameters:
9194
- in: body
@@ -113,13 +116,70 @@ paths:
113116
- Component
114117
responses:
115118
'200':
116-
description: OK, user has been added, id is returned
119+
description: 'OK, user has been added, id is returned'
117120
schema:
118121
type: integer
119122
format: int64
120123
example: 42
121124
'400':
122-
description: Bad request, name already exists
125+
description: 'Bad request, name already exists'
126+
/users:
127+
get:
128+
tags:
129+
- User Management
130+
summary: Gets a list of all registered users
131+
description: >-
132+
Returns a list of all users registered at the registry. Requires caller to have admin privileges.
133+
operationId: allUsers
134+
responses:
135+
'200':
136+
description: "OK, list of users is being returned"
137+
schema:
138+
type: array
139+
items:
140+
$ref: '#/definitions/User'
141+
/users/{Id}:
142+
get:
143+
tags:
144+
- User Management
145+
summary: Gets the user with the specified id
146+
description: >-
147+
Returns the user with the specified id, if that id is present at the registry.
148+
operationId: retrieveUser
149+
parameters:
150+
- in: path
151+
name: Id
152+
required: true
153+
description: Id of the user to retrieve
154+
type: integer
155+
format: int64
156+
responses:
157+
'200':
158+
description: "OK, user is being returned"
159+
schema:
160+
$ref: '#/definitions/User'
161+
'404':
162+
description: "Id not found"
163+
/users/{Id}/remove:
164+
post:
165+
tags:
166+
- User Management
167+
summary: Removes the user with the specified id
168+
description: >-
169+
Removes the user with the specified id, if that id is present at the registry.
170+
operationId: removeUser
171+
parameters:
172+
- in: path
173+
name: Id
174+
required: true
175+
description: Id of the user to remove
176+
type: integer
177+
format: int64
178+
responses:
179+
'200':
180+
description: "OK, user has been removed"
181+
'404':
182+
description: "Id not found"
123183
/instances/register:
124184
post:
125185
tags:
@@ -886,6 +946,27 @@ paths:
886946
'500':
887947
description: 'Internal server error, unknown operation result DESCRIPTION'
888948
definitions:
949+
User:
950+
type: object
951+
required:
952+
- userName
953+
- secret
954+
- userType
955+
properties:
956+
id:
957+
type: integer
958+
format: int64
959+
userName:
960+
type: string
961+
example: Ben
962+
secret:
963+
type: string
964+
example: 0DE19F6FAAFB7CF372172CEA658800999A75DB9E79AF5F378F274E47DF810CEE
965+
userType:
966+
type: string
967+
enum:
968+
- User
969+
- Admin
889970
InstanceLink:
890971
type: object
891972
required:

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/RequestHandler.scala

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -956,38 +956,72 @@ class RequestHandler(configuration: Configuration, authDao: AuthDAO, instanceDao
956956
}
957957
}
958958

959+
def isInstanceIdPresent(id: Long): Boolean = {
960+
instanceDao.hasInstance(id)
961+
}
962+
963+
def getInstance(id: Long): Option[Instance] = {
964+
instanceDao.getInstance(id)
965+
}
966+
967+
def instanceHasState(id: Long, state: InstanceState): Boolean = {
968+
instanceDao.getInstance(id) match {
969+
case Some(instance) => instance.instanceState == state
970+
case None => false
971+
}
972+
}
973+
959974
/**
960975
* Add user to user database
961976
*
962977
* @param user The user to add
963978
* @return Id assigned to that user
964979
*/
965-
def handleAddUser(user: DelphiUser): Try[Long] = {
980+
def handleAddUser(user: DelphiUser): Try[String] = {
966981

967982
val noIdUser = DelphiUser(id = None, userName = user.userName, secret = user.secret, userType = user.userType)
968983

969984
authDao.addUser(noIdUser) match {
970-
case Success(id) =>
985+
case Success(username) =>
971986
log.info(s"Successfully handled create user request")
972-
Success(id)
987+
Success(username)
973988
case Failure(x) => Failure(x)
974989
}
975990
}
976991

992+
/**
993+
* Remove a user with id
994+
*
995+
* @param id
996+
* @return
997+
*/
998+
def handleRemoveUser(id: Long): Try[Long] = {
977999

978-
def isInstanceIdPresent(id: Long): Boolean = {
979-
instanceDao.hasInstance(id)
1000+
authDao.removeUser(id) match {
1001+
case Success(_) =>
1002+
log.info(s"Successfully handled remove user request")
1003+
Success(id)
1004+
case Failure(x) => Failure(x)
1005+
}
9801006
}
9811007

982-
def getInstance(id: Long): Option[Instance] = {
983-
instanceDao.getInstance(id)
1008+
/**
1009+
* Get a user with id
1010+
*
1011+
* @param id
1012+
* @return
1013+
*/
1014+
def getUser(id: Long): Option[DelphiUser] = {
1015+
authDao.getUserWithId(id)
9841016
}
9851017

986-
def instanceHasState(id: Long, state: InstanceState): Boolean = {
987-
instanceDao.getInstance(id) match {
988-
case Some(instance) => instance.instanceState == state
989-
case None => false
990-
}
1018+
/**
1019+
* Get all user
1020+
*
1021+
* @return
1022+
*/
1023+
def getAllUsers(): List[DelphiUser] = {
1024+
authDao.getAllUser()
9911025
}
9921026

9931027
def isInstanceDockerContainer(id: Long): Boolean = {

0 commit comments

Comments
 (0)