Skip to content

Commit 59f6c70

Browse files
authored
Merge pull request #253 from Engineering-Research-and-Development/develop
Develop
2 parents f6adf8e + 3dcbf4d commit 59f6c70

20 files changed

+234
-175
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [1.14.7] - 2024-01-19
5+
6+
### Added
7+
8+
- Simple user management
9+
410
## [1.14.6] - 2023-11-16
511

612
### Changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# List of users
2+
users.list=idsUser,bob
3+
4+
# Credentials for each user
5+
# encoded - password
6+
idsUser.password=$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUubrqdGTFCH3m
7+
# encoded - passwordBob
8+
bob.password=$2a$12$8ngZQYUF9pATTwNRmLiYeu6XGlLd79eb4FIgr5ezzuAA6tGLxuAyy

ci/docker/ecc_resources_consumer/application-docker.properties

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ application.usageControlVersion=platoon
155155
application.technicalHeaders=header,Is-Enabled-DataApp-WebSocket,payload,Forward-To,Payload-Content-Type,Host
156156

157157
#SelfDescription
158-
#API management credentials
159-
application.user.api.username=apiUser
160-
# 'password' encoded value
161-
application.user.api.password=$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUubrqdGTFCH3m
162158
#number of consecutive failed attempts
163159
application.user.lock.maxattempts=5
164160
# duration for how long user will be locked
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# List of users
2+
users.list=apiUser,alice
3+
4+
# Credentials for each user
5+
# encoded - password
6+
apiUser.password=$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUubrqdGTFCH3m
7+
# encoded - passwordAlice
8+
alice.password=$2a$12$xeiemEk5ycerfxq7440ieeTUmZ3EK65hwXwM.NQu.1Y29xbpOMVyq

ci/docker/ecc_resources_provider/application-docker.properties

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ application.usageControlVersion=platoon
158158
application.technicalHeaders=header,Is-Enabled-DataApp-WebSocket,payload,Forward-To,Payload-Content-Type,Host
159159

160160
#SelfDescription
161-
#API management credentials
162-
application.user.api.username=apiUser
163-
# 'password' encoded value
164-
application.user.api.password=$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUubrqdGTFCH3m
165161
#number of consecutive failed attempts
166162
application.user.lock.maxattempts=5
167163
# duration for how long user will be locked
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# List of users
2+
users.list=apiUser,alice
3+
4+
# Credentials for each user
5+
# encoded - password
6+
apiUser.password=$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUubrqdGTFCH3m
7+
# encoded - passwordAlice
8+
alice.password=$2a$12$xeiemEk5ycerfxq7440ieeTUmZ3EK65hwXwM.NQu.1Y29xbpOMVyq

doc/AUDIT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ TRUE Connector has list of audit events which can be found in following table:
1010
|HTTP_REQUEST_RECEIVED | Http request received |
1111
|USER_AUTHORIZATION_FAILURE | Authorization failure |
1212
|USER_AUTHORIZATION_SUCCESS | Authorization success |
13+
|USER_AUTHENTICATION_FAILURE | Authentication failure |
14+
|USER_AUTHENTICATION_SUCCESS | Authentication success |
1315
|USER_BLOCKED | User blocked |
1416
|SELF_DESCRIPTION | Self description requested |
1517
|CONTRACT_OFFER | Contract offer requested |

doc/SELF_DESCRIPTION.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,33 @@ All endpoints after /api/** are protected and you will have to provide credentia
4646

4747
![Basic Auth](basic_auth.jpg?raw=true "Basic Authorization for api endpoints")
4848

49-
Credentials are located in property file, and for now, there is only one user:
5049

50+
For storing user credentials, simple in memory user storage solution is implemented, and all user credentials can be found in `users.properties` file.
51+
52+
53+
```
54+
# List of users
55+
users.list=apiUser,alice
56+
57+
# Credentials for each user
58+
# encoded - password
59+
apiUser.password=$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUubrqdGTFCH3m
60+
# encoded - passwordAlice
61+
alice.password=$2a$12$xeiemEk5ycerfxq7440ieeTUmZ3EK65hwXwM.NQu.1Y29xbpOMVyq
5162
```
52-
application.user.api.username=apiUser
53-
application.user.api.password=encoded_password
63+
64+
65+
In the example, the property `user.list` is a list with each item separated by a comma (,) without space. You need to enter all the users you want and then give each one a specific password, which must be BCrypt encoded. Getting password can be done via following endpoint:
5466

5567
```
68+
/notification/password/{new_password}
69+
```
70+
71+
Using this endpoint, it is guaranteed that the password strength rules configured in the `application.properties` file will be enforced.
72+
73+
Bare in mind that this endpoint is password protected, and you will have to provide existing credentials in order for TRUE Connector to generate new hash that matches with the value passed in URL, so the general advice is to keep `apiUser` as a kind of administrator account. Once new hash is returned, you can modify properties file and set new password for specific user.
74+
75+
5676

5777
There is also mechanism to lock user after configured number of consecutive failed attempts from same IP address. Following functionality can be configured by changing:
5878

src/main/java/it/eng/idsa/businesslogic/audit/TrueConnectorEvent.java

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,92 +14,111 @@
1414
import it.eng.idsa.multipart.domain.MultipartMessage;
1515

1616
public class TrueConnectorEvent extends AuditApplicationEvent {
17-
17+
1818
private static final long serialVersionUID = -87655024649097585L;
19-
19+
2020
private static final String IDS_USER = "idsUser";
2121

2222
public TrueConnectorEvent(String principal, TrueConnectorEventType type, MultipartMessage multipartMessage) {
2323
super(principal, type.name(), detailsMultipartMessage(multipartMessage, null));
2424
}
25-
25+
2626
/**
2727
* Uses default principal - connector
28-
* @param type TrueConnectorEventType
28+
*
29+
* @param type TrueConnectorEventType
2930
* @param multipartMessage - logs information from multipartMessage to event
3031
*/
3132
public TrueConnectorEvent(TrueConnectorEventType type, MultipartMessage multipartMessage) {
3233
super(IDS_USER, type.name(), detailsMultipartMessage(multipartMessage, null));
3334
}
34-
35+
3536
/**
3637
* TrueConnector event with correlationId
37-
* @param type TrueConnectorEventType
38+
*
39+
* @param type TrueConnectorEventType
3840
* @param multipartMessage - logs information from multipartMessage to event
39-
* @param correlationId correlation Id
41+
* @param correlationId correlation Id
4042
*/
4143
public TrueConnectorEvent(TrueConnectorEventType type, MultipartMessage multipartMessage, String correlationId) {
4244
super(IDS_USER, type.name(), detailsMultipartMessage(multipartMessage, correlationId));
4345
}
44-
46+
4547
/**
4648
* Default TrueConnector event
49+
*
4750
* @param principal Principal of the user
48-
* @param type TrueConnectorEventType
49-
* @param data Data for logging
51+
* @param type TrueConnectorEventType
52+
* @param data Data for logging
5053
*/
5154
public TrueConnectorEvent(String principal, TrueConnectorEventType type, Map<String, Object> data) {
5255
super(principal, type.name(), data);
5356
}
54-
57+
58+
/**
59+
* TrueConnectorEvent with request and type\n
60+
*
61+
* @param request Http Request
62+
* @param principal Principal of the user
63+
* @param type TrueConnectorEventType
64+
*/
65+
public TrueConnectorEvent(HttpServletRequest request, String principal, TrueConnectorEventType type) {
66+
super(principal, type.name(), details(request, null, null));
67+
}
68+
5569
/**
5670
* TrueConnectorEvent with request and type\n
71+
*
5772
* @param request Http Request
58-
* @param type TrueConnectorEventType
73+
* @param type TrueConnectorEventType
5974
*/
6075
public TrueConnectorEvent(HttpServletRequest request, TrueConnectorEventType type) {
6176
super(principal(request), type.name(), details(request, null, null));
6277
}
63-
78+
6479
/**
6580
* TrueConnectorEvent with request, type and correlationId
66-
* @param request Http Request
67-
* @param type TrueConnectorEventType
81+
*
82+
* @param request Http Request
83+
* @param type TrueConnectorEventType
6884
* @param correlationId correlation id
6985
*/
7086
public TrueConnectorEvent(HttpServletRequest request, TrueConnectorEventType type, String correlationId) {
7187
super(principal(request), type.name(), details(request, correlationId, null));
7288
}
73-
89+
7490
/**
7591
* TrueConnectorEvent with request, type, correlationId and payload
76-
* @param request HTTP request
77-
* @param type TrueConnectorEventType
92+
*
93+
* @param request HTTP request
94+
* @param type TrueConnectorEventType
7895
* @param correlationId correlationId for tracking request
79-
* @param payload payload of the request
96+
* @param payload payload of the request
8097
*/
81-
public TrueConnectorEvent(HttpServletRequest request, TrueConnectorEventType type, String correlationId, String payload) {
98+
public TrueConnectorEvent(HttpServletRequest request, TrueConnectorEventType type, String correlationId,
99+
String payload) {
82100
super(principal(request), type.name(), details(request, correlationId, payload));
83101
}
84102

85103
private static String principal(HttpServletRequest request) {
86104
return Optional.ofNullable(request.getUserPrincipal()).map(Principal::getName).orElse("anonymousUser");
87105
}
88-
89-
private static Map<String, Object> detailsMultipartMessage(MultipartMessage multipartMessage, String correlationId) {
106+
107+
private static Map<String, Object> detailsMultipartMessage(MultipartMessage multipartMessage,
108+
String correlationId) {
90109
Map<String, Object> details = new HashMap<>();
91110
details.put("http.method", HttpMethod.POST);
92111
if (correlationId != null) {
93112
details.put("correlationId", correlationId);
94113
}
95-
if(multipartMessage != null) {
114+
if (multipartMessage != null) {
96115
details.put("http.message", multipartMessage.getHeaderContent().getClass().getCanonicalName());
97116
} else {
98117
details.put("http.message", "NO MESSAGE");
99118
}
100119
return details;
101120
}
102-
121+
103122
private static Map<String, Object> details(HttpServletRequest request, String correlationId, String payload) {
104123
Map<String, Object> details = new HashMap<>();
105124
details.put("http.method", request.getMethod());
@@ -108,7 +127,7 @@ private static Map<String, Object> details(HttpServletRequest request, String co
108127
if (correlationId != null) {
109128
details.put("correlationId", correlationId);
110129
}
111-
130+
112131
if (payload != null) {
113132
details.put("payload", payload);
114133
}
@@ -121,7 +140,7 @@ private static Map<String, String> getHeadersInfo(HttpServletRequest request) {
121140
while (headerNames.hasMoreElements()) {
122141
String key = (String) headerNames.nextElement();
123142
String value = request.getHeader(key);
124-
if(key.equalsIgnoreCase("Authorization")) {
143+
if (key.equalsIgnoreCase("Authorization")) {
125144
value = "******";
126145
}
127146
map.put(key, value);

src/main/java/it/eng/idsa/businesslogic/audit/TrueConnectorEventType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public enum TrueConnectorEventType {
66
HTTP_REQUEST_RECEIVED("Http request received"),
77
USER_AUTHORIZATION_FAILURE("Authorization failure"),
88
USER_AUTHORIZATION_SUCCESS("Authorization success"),
9+
USER_AUTHENTICATION_FAILURE("Authentication failure"),
10+
USER_AUTHENTICATION_SUCCESS("Authentication success"),
911
USER_BLOCKED("User blocked"),
1012
SELF_DESCRIPTION("Self description requested"),
1113
CONTRACT_OFFER("Contract offer requested"),

0 commit comments

Comments
 (0)