Skip to content

Commit 05e2fbe

Browse files
author
Rob Tjalma
authored
Merge pull request #91 from com-pas/develop
Merge branch 'develop' into main
2 parents 41dcf85 + f1d2f03 commit 05e2fbe

File tree

28 files changed

+494
-83
lines changed

28 files changed

+494
-83
lines changed

.github/dependabot.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
version: 2
6+
7+
registries:
8+
maven-github:
9+
type: maven-repository
10+
url: https://maven.pkg.github.com/com-pas/*
11+
username: OWNER
12+
password: ${{ secrets.DB_GITHUB_PACKAGES }}
13+
14+
updates:
15+
# Maintain dependencies for GitHub Actions
16+
- package-ecosystem: "github-actions"
17+
directory: "/"
18+
schedule:
19+
interval: "daily"
20+
open-pull-requests-limit: 5
21+
22+
# Maintain dependencies for Maven
23+
- package-ecosystem: "maven"
24+
directory: "/"
25+
registries:
26+
- maven-github
27+
schedule:
28+
interval: "daily"
29+
open-pull-requests-limit: 5
30+
ignore:
31+
# Next two dependencies shouldn't be upgrade, because RestEasy isn't using newer version. (2.3.X)
32+
- dependency-name: jakarta.xml.bind:jakarta.xml.bind-api
33+
versions: [ "[3.0,)" ]
34+
- dependency-name: com.sun.xml.bind:jaxb-impl
35+
versions: [ "[3.0,)" ]

.github/workflows/build-project.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Set up JDK 1.11
18-
uses: actions/setup-java@v1
18+
uses: actions/setup-java@v2.3.0
1919
with:
20-
java-version: 1.11
20+
distribution: 'zulu'
21+
java-version: '11'
2122
- name: Create custom Maven Settings.xml
2223
uses: whelk-io/maven-settings-xml-action@v18
2324
with:

.github/workflows/release-project.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ jobs:
2424
shell: bash
2525
# Extra the tagname form the git reference, value of GITHUB_REF will be something like refs/tags/<tag_name>.
2626
run: echo "##[set-output name=tagname;]$(echo ${GITHUB_REF##*/})"
27-
- uses: actions/setup-java@v2
27+
- name: Set up JDK 11
28+
uses: actions/[email protected]
2829
with:
30+
distribution: 'zulu'
2931
java-version: '11'
30-
distribution: 'adopt'
3132
- name: Create custom Maven Settings.xml
3233
uses: whelk-io/maven-settings-xml-action@v18
3334
with:

.github/workflows/sonarcloud-analysis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ jobs:
1717
with:
1818
fetch-depth: 0
1919
- name: Set up JDK 11
20-
uses: actions/setup-java@v1
20+
uses: actions/setup-java@v2.3.0
2121
with:
22-
java-version: 1.11
22+
distribution: 'zulu'
23+
java-version: '11'
2324
- name: Cache SonarCloud packages
24-
uses: actions/cache@v1
25+
uses: actions/cache@v2.1.6
2526
with:
2627
path: ~/.sonar/cache
2728
key: ${{ runner.os }}-sonar
2829
restore-keys: ${{ runner.os }}-sonar
2930
- name: Cache Maven packages
30-
uses: actions/cache@v1
31+
uses: actions/cache@v2.1.6
3132
with:
3233
path: ~/.m2
3334
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,66 @@ You can then execute your native executable with: `./app/target/code-with-quarku
7171

7272
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html
7373
.
74+
75+
## Environment variables
76+
77+
Below environment variable(s) can be used to configure the connection to BaseX, if BaseX Server is used.
78+
79+
| Environment variable | Java Property | Description | Example |
80+
| -------------------------------- | ------------------------- | --------------------------------------------- | ---------------- |
81+
| BASEX_HOST | basex.host | Name of the Host where BaseX runs. | localhost |
82+
| BASEX_PORT | basex.port | Port on the Host on which BaseX runs. | 1984 |
83+
| BASEX_USERNAME | basex.username | Username under which the application logs in. | admin |
84+
| BASEX_PASSWORD | basex.password | Password of the username used above. | admin |
85+
86+
Below environment variable(s) can be used to configure which claims are used to fill the UserInfo response.
87+
88+
| Environment variable | Java Property | Description | Example |
89+
| -------------------------------- | ------------------------------ | --------------------------------------------- | ---------------- |
90+
| USERINFO_NAME_CLAIMNAME | compas.userinfo.name.claimname | The Name of the user logged in. | name |
91+
| USERINFO_WHO_CLAIMNAME | compas.userinfo.who.claimname | The Name of the user used in the Who History. | name |
92+
93+
## Security
94+
95+
To use most of the endpoints the users needs to be authenticated using JWT in the authorization header. There are 4
96+
environment variables that can be set in the container to configure the validation/processing of the JWT.
97+
98+
| Environment variable | Java Property | Description | Example |
99+
| -------------------------------- | -------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------- |
100+
| JWT_VERIFY_KEY | smallrye.jwt.verify.key.location | Location of certificates to verify the JWT. | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs |
101+
| JWT_VERIFY_ISSUER | mp.jwt.verify.issuer | The issuer of the JWT. | http://localhost:8089/auth/realms/compas |
102+
| JWT_VERIFY_CLIENT_ID | mp.jwt.verify.audiences | The Client ID that should be in the "aud" claim. | scl-data-service |
103+
| JWT_GROUPS_PATH | smallrye.jwt.path.groups | The JSON Path where to find the roles of the user. | resource_access/scl-data-service/roles |
104+
105+
The application uses the following list of roles. The fine-grained roles are built up of the types of SCL Files this
106+
service supports and the rights READ/CREATE/UPDATE/DElETE. This way the mapping of the roles to groups/users can be
107+
configured as needed.
108+
109+
- ICD_CREATE
110+
- ICD_DELETE
111+
- ICD_READ
112+
- ICD_UPDATE
113+
- SCD_CREATE
114+
- SCD_DELETE
115+
- SCD_READ
116+
- SCD_UPDATE
117+
- SSD_CREATE
118+
- SSD_DELETE
119+
- SSD_READ
120+
- SSD_UPDATE
121+
- ISD_CREATE
122+
- ISD_DELETE
123+
- ISD_READ
124+
- ISD_UPDATE
125+
- CID_CREATE
126+
- CID_DELETE
127+
- CID_READ
128+
- CID_UPDATE
129+
- IID_CREATE
130+
- IID_DELETE
131+
- IID_READ
132+
- IID_UPDATE
133+
- SED_CREATE
134+
- SED_DELETE
135+
- SED_READ
136+
- SED_UPDATE

app/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SPDX-License-Identifier: Apache-2.0
1818
<packaging>jar</packaging>
1919

2020
<properties>
21-
<quarkus.platform.version>2.0.0.Final</quarkus.platform.version>
21+
<quarkus.platform.version>2.2.1.Final</quarkus.platform.version>
2222
</properties>
2323

2424
<dependencyManagement>
@@ -104,7 +104,7 @@ SPDX-License-Identifier: Apache-2.0
104104
</dependency>
105105
<dependency>
106106
<groupId>io.quarkus</groupId>
107-
<artifactId>quarkus-test-security</artifactId>
107+
<artifactId>quarkus-test-security-jwt</artifactId>
108108
<scope>test</scope>
109109
</dependency>
110110
<dependency>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
package org.lfenergy.compas.scl.data.rest;
5+
6+
import io.smallrye.config.ConfigMapping;
7+
import io.smallrye.config.WithName;
8+
9+
@ConfigMapping(prefix = "compas.userinfo")
10+
public interface UserInfoProperties {
11+
@WithName("name.claimname")
12+
String name();
13+
14+
@WithName("who.claimname")
15+
String who();
16+
}

app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResource.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
package org.lfenergy.compas.scl.data.rest.v1;
55

66
import io.quarkus.security.Authenticated;
7-
import io.quarkus.security.identity.SecurityIdentity;
7+
import org.eclipse.microprofile.jwt.JsonWebToken;
88
import org.lfenergy.compas.scl.data.model.SclType;
9+
import org.lfenergy.compas.scl.data.rest.UserInfoProperties;
910
import org.lfenergy.compas.scl.data.rest.v1.model.Type;
1011
import org.lfenergy.compas.scl.data.rest.v1.model.TypeListResponse;
12+
import org.lfenergy.compas.scl.data.rest.v1.model.UserInfoResponse;
1113
import org.slf4j.Logger;
1214
import org.slf4j.LoggerFactory;
1315

@@ -31,16 +33,19 @@ public class CompasCommonResource {
3133
private static final Logger LOGGER = LoggerFactory.getLogger(CompasCommonResource.class);
3234

3335
@Inject
34-
SecurityIdentity securityIdentity;
36+
JsonWebToken jsonWebToken;
37+
38+
@Inject
39+
UserInfoProperties userInfoProperties;
3540

3641
@GET
3742
@Path("/type/list")
3843
@Produces(MediaType.APPLICATION_XML)
3944
public TypeListResponse list(@HeaderParam("Authorization") String authHeader) {
40-
LOGGER.debug("Authorization Header '{}'", authHeader);
45+
LOGGER.trace("Authorization Header '{}'", authHeader);
4146

4247
// Retrieve the roles the logged in user has.
43-
var roles = securityIdentity.getRoles();
48+
var roles = jsonWebToken.getGroups();
4449

4550
var response = new TypeListResponse();
4651
response.setTypes(
@@ -52,4 +57,15 @@ public TypeListResponse list(@HeaderParam("Authorization") String authHeader) {
5257
.collect(Collectors.toList()));
5358
return response;
5459
}
60+
61+
@GET
62+
@Path("/userinfo")
63+
@Produces(MediaType.APPLICATION_XML)
64+
public UserInfoResponse getUserInfo(@HeaderParam("Authorization") String authHeader) {
65+
LOGGER.trace("Authorization Header '{}'", authHeader);
66+
67+
var response = new UserInfoResponse();
68+
response.setName(jsonWebToken.getClaim(userInfoProperties.name()));
69+
return response;
70+
}
5571
}

app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
package org.lfenergy.compas.scl.data.rest.v1;
55

66
import io.quarkus.security.Authenticated;
7+
import org.eclipse.microprofile.jwt.JsonWebToken;
78
import org.lfenergy.compas.core.commons.ElementConverter;
89
import org.lfenergy.compas.scl.data.model.SclType;
910
import org.lfenergy.compas.scl.data.model.Version;
11+
import org.lfenergy.compas.scl.data.rest.UserInfoProperties;
1012
import org.lfenergy.compas.scl.data.rest.v1.model.*;
1113
import org.lfenergy.compas.scl.data.service.CompasSclDataService;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
1216

1317
import javax.enterprise.context.RequestScoped;
1418
import javax.inject.Inject;
@@ -23,9 +27,17 @@
2327
@RequestScoped
2428
@Path("/scl/v1/{" + TYPE_PATH_PARAM + "}")
2529
public class CompasSclDataResource {
30+
private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclDataResource.class);
31+
2632
private final CompasSclDataService compasSclDataService;
2733
private final ElementConverter converter;
2834

35+
@Inject
36+
JsonWebToken jsonWebToken;
37+
38+
@Inject
39+
UserInfoProperties userInfoProperties;
40+
2941
@Inject
3042
public CompasSclDataResource(CompasSclDataService compasSclDataService,
3143
ElementConverter converter) {
@@ -38,8 +50,11 @@ public CompasSclDataResource(CompasSclDataService compasSclDataService,
3850
@Produces(MediaType.APPLICATION_XML)
3951
public CreateResponse create(@PathParam(TYPE_PATH_PARAM) SclType type,
4052
@Valid CreateRequest request) {
53+
String who = jsonWebToken.getClaim(userInfoProperties.who());
54+
LOGGER.trace("Username used for Who {}", who);
55+
4156
var response = new CreateResponse();
42-
response.setId(compasSclDataService.create(type, request.getName(), request.getElements().get(0)));
57+
response.setId(compasSclDataService.create(type, request.getName(), who, request.getComment(), request.getElements().get(0)));
4358
return response;
4459
}
4560

@@ -109,7 +124,10 @@ public String findRawSCLByUUIDAndVersion(@PathParam(TYPE_PATH_PARAM) SclType typ
109124
public void update(@PathParam(TYPE_PATH_PARAM) SclType type,
110125
@PathParam(ID_PATH_PARAM) UUID id,
111126
@Valid UpdateRequest request) {
112-
compasSclDataService.update(type, id, request.getChangeSetType(), request.getElements().get(0));
127+
String who = jsonWebToken.getClaim(userInfoProperties.who());
128+
LOGGER.trace("Username used for Who {}", who);
129+
130+
compasSclDataService.update(type, id, request.getChangeSetType(), who, request.getComment(), request.getElements().get(0));
113131
}
114132

115133
@DELETE

app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class CreateRequest {
2626
@XmlElement(name = "Name", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true)
2727
private String name;
2828

29+
@Schema(description = "Comment that will be added to the new history record.")
30+
@XmlElement(name = "Comment", namespace = SCL_DATA_SERVICE_V1_NS_URI)
31+
private String comment;
32+
2933
@Size(min = 1, max = 1, message = "{org.lfenergy.compas.XmlAnyElementValid.moreElements.message}")
3034
@XmlAnyElementValid(elementName = "SCL", elementNamespace = SCL_NS_URI)
3135
@Schema(description = "Can contain one element, named 'SCL', containing a SCL XML Definition")
@@ -40,6 +44,14 @@ public void setName(String name) {
4044
this.name = name;
4145
}
4246

47+
public String getComment() {
48+
return comment;
49+
}
50+
51+
public void setComment(String comment) {
52+
this.comment = comment;
53+
}
54+
4355
public List<Element> getElements() {
4456
return elements;
4557
}

0 commit comments

Comments
 (0)