Skip to content

Commit d95e7d2

Browse files
authored
Merge pull request #32 from rglauco/main
Distinction between core and fed keys, updated compatibility with spid-cie-oidc-django v1.4.0
2 parents 70779ed + 3cda9b6 commit d95e7d2

34 files changed

+303
-134
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Sample projects using the library can be executed as docker or docker-compose. S
105105

106106
### SpringBoot Relying Party example
107107

108-
A simple [SpringBoot](examples/relying-party-spring-boot) web application using the starter-kit to implement a Relying Party.
108+
A simple [SpringBoot](examples/relying-party-spring-boot) web application using the starter-kit to implement a Relying Party, as well to perform the complete onboarding and login/logout test within the CIE Federation.
109109

110110
This application is for demo purpose only, please don't use it in production or critical environment.
111111

coverage/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>it.spid.cie.oidc</groupId>
77
<artifactId>starter-kit-parent</artifactId>
8-
<version>0.4.1-SNAPSHOT</version>
8+
<version>1.0.0-SNAPSHOT</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>it.spid.cie.oidc</groupId>
77
<artifactId>starter-kit-parent</artifactId>
8-
<version>0.4.1-SNAPSHOT</version>
8+
<version>1.0.0-SNAPSHOT</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

examples/relying-party-spring-boot/README.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Run the provider [federation](https://github.com/italia/spid-cie-oidc-django)
1515
- the project should run on [http://127.0.0.1:8000](http://127.0.0.1:8000), keep it running
1616

1717

18-
Clone this repository and install all the lement inside the MavenLocal registry
18+
Clone this repository and install all the elements inside the MavenLocal registry
1919
```
2020
git clone https://github.com/italia/spid-cie-oidc-java
2121
@@ -39,9 +39,10 @@ this will start the relying party server on [http://127.0.0.1:8080](http://127.0
3939
Do the on-boarding process
4040
- generate the relying party jwks
4141
- go [here](http://127.0.0.1:8080/) to auto-generate it
42-
- jwks are exposed on the page and inside application log
43-
- create the file `${user.home}/oidc-rp-jwk.json` with the jwks
44-
- use "reload" link to proceed with next step
42+
- federation jwks and core jwks are exposed on the page and inside application log
43+
- create the file `${user.home}/oidc-rp-jwk.json` with the federation jwks
44+
- create the file `${user.home}/oidc-rp-core-jwk.json` with the core jwks
45+
- - use "reload" link to proceed with next step
4546
- show on-boarding datas
4647
- go [here](http://127.0.0.1:8080/) to see it
4748
- register the relying party [here](http://127.0.0.1:8000/admin/spid_cie_oidc_authority/federationdescendant/add)
@@ -76,10 +77,32 @@ A docker image containing this example can be built a run:
7677
- visit `http://relying-party.org:8080/`
7778

7879
Some hints:
79-
- we are using [federation](https://github.com/italia/spid-cie-oidc-django) v1.2.0
80+
- we are using [federation](https://github.com/italia/spid-cie-oidc-django) v1.4.0
8081
- docker images currently sets a proxy of the exposed ports on the localhost interface, so you could use
8182
previous chapter instructions replacing `127.0.0.1` with the right hostname
82-
- docker image mounts the folder `./docker/data-java` as `/data` inside spring-boot container to externalize `jwk` and `trust-marks` configuration
83+
- docker image mounts the folder `./docker/data-java` as `/data` inside spring-boot container to externalize federation and core `jwks` and `trust-marks` configuration
8384

8485

8586
[Docker Compose in action on YouTube](https://www.youtube.com/watch?v=U2Ec0No2EKg)
87+
88+
**To be onboarded into CIE Federation**:
89+
- use always appropriate and valid TLS Certificates
90+
- use IP from Italian networks for server [CIE Federation servers uses geoblocking]
91+
- as contact use the same institutional email address as stated into the administrative part [do not use PEC]
92+
- when copy the federation public key please follow this pattern:
93+
- ```
94+
{
95+
"keys": [
96+
{
97+
"alg": "RS256",
98+
"kid": "....",
99+
"kty": "RSA",
100+
"n": ".....",
101+
"e": "AQAB",
102+
"use": "sig"
103+
}
104+
]
105+
}
106+
```
107+
- when onboarded, please retrieve the Trust Mark form TA fetch endpoint like this example for preproduction: `https://preprod.oidc.registry.servizicie.interno.gov.it/fetch?sub={your_client_id}`
108+
- remember to (put `[` `]` around the Trust Mark when writing the appropriate file

examples/relying-party-spring-boot/docker/Dockerfile-cie.django

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM python:3.11-slim
22

33
RUN apt update && apt -y install git
44

5-
RUN git clone --depth=1 --branch v1.2.0 https://github.com/italia/spid-cie-oidc-django && \
5+
RUN git clone --depth=1 --branch v1.4.0 https://github.com/italia/spid-cie-oidc-django && \
66
cd spid-cie-oidc-django && \
77
pip install --upgrade pip && \
88
pip install -e . && \

examples/relying-party-spring-boot/docker/Dockerfile.django

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM python:3.11-slim
22

33
RUN apt update && apt -y install git
44

5-
RUN git clone --depth=1 --branch v1.2.0 https://github.com/italia/spid-cie-oidc-django && \
5+
RUN git clone --depth=1 --branch v1.4.0 https://github.com/italia/spid-cie-oidc-django && \
66
cd spid-cie-oidc-django && \
77
pip install --upgrade pip && \
88
pip install -e . && \

examples/relying-party-spring-boot/docker/Dockerfile.java-rp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ VOLUME ["/data"]
1313
ENV OIDC_HOSTS_TRUST_ANCHOR="trust-anchor.org"
1414
ENV OIDC_HOSTS_CIE_PROVIDER="cie-provider.org"
1515
ENV OIDC_HOSTS_RELYING_PARTY="relying-party.org"
16-
ENV OIDC_RELYING_PARTY_JWK_FILE_PATH="/data/oidc-rp-jwk.json"
16+
ENV OIDC_RELYING_PARTY_JWK_FED_FILE_PATH="/data/oidc-rp-jwk.json"
17+
ENV OIDC_RELYING_PARTY_CORE_JWK_CORE_FILE_PATH="/data/oidc-rp-core-jwk.json"
1718
ENV OIDC_RELYING_PARTY_TRUST_MARKS_FILE_PATH="/data/oidc-rp-trust-marks.json"
1819
ENV SPRING_H2_CONSOLE_SETTINGS_WEB_ALLOW_OTHERS="true"
1920

examples/relying-party-spring-boot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>it.spid.cie.oidc</groupId>
77
<artifactId>it.spid.cie.oidc.examples</artifactId>
8-
<version>0.4.1-SNAPSHOT</version>
8+
<version>1.0.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>it.spid.cie.oidc.relying.party.spring-boot-sample</artifactId>

examples/relying-party-spring-boot/src/main/java/it/spid/cie/oidc/spring/boot/relying/party/RelyingPartyWrapper.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public JSONObject getUserInfo(String state, String code)
4848
}
4949

5050
public String getUserKey(JSONObject userInfo) {
51-
String userKey = userInfo.optString("email");
51+
String userKey = userInfo.optString("sub");
5252

5353
if (Validator.isNullOrEmpty(userKey)) {
54-
userKey = userInfo.optString("email", "");
54+
userKey = userInfo.optString("sub", "");
5555
}
5656

5757
return userKey;
@@ -83,11 +83,12 @@ public void reloadHandler() throws OIDCException {
8383

8484
@PostConstruct
8585
private void postConstruct() throws OIDCException {
86-
String jwk = readFile(oidcConfig.getRelyingParty().getJwkFilePath());
86+
String jwkFed = readFile(oidcConfig.getRelyingParty().getJwkFedFilePath());
87+
String jwkCore = readFile(oidcConfig.getRelyingParty().getJwkCoreFilePath());
8788
String trustMarks = readFile(
8889
oidcConfig.getRelyingParty().getTrustMarksFilePath());
8990

90-
logger.info("final jwk: " + jwk);
91+
logger.info("final jwkFed: " + jwkFed);
9192
logger.info("final trust_marks: " + trustMarks);
9293

9394
RelyingPartyOptions options = new RelyingPartyOptions()
@@ -110,7 +111,8 @@ private void postConstruct() throws OIDCException {
110111
.setLogoUri(oidcConfig.getRelyingParty().getLogoUri())
111112
.setPolicyUri(oidcConfig.getRelyingParty().getPolicyUri())
112113
.setFederationContacts(oidcConfig.getRelyingParty().getFederationContacts())
113-
.setJWK(jwk)
114+
.setJWKFed(jwkFed)
115+
.setJWKCore(jwkCore)
114116
.setTrustMarks(trustMarks);
115117

116118
relyingPartyHandler = new RelyingPartyHandler(options, persistenceImpl);

examples/relying-party-spring-boot/src/main/java/it/spid/cie/oidc/spring/boot/relying/party/config/OidcConfig.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@ public Set<String> getRedirectUris() {
208208
// return jwk;
209209
// }
210210

211-
public String getJwkFilePath() {
212-
return jwkFilePath;
211+
public String getJwkFedFilePath() {
212+
return jwkFedFilePath;
213+
}
214+
public String getJwkCoreFilePath() {
215+
return jwkCoreFilePath;
213216
}
214-
215217
// public String getTrustMarks() {
216218
// return trustMarks;
217219
// }
@@ -271,10 +273,13 @@ public void setFederationContacts(Set<String> federationContacts) {
271273
// this.jwk = jwk;
272274
// }
273275

274-
public void setJwkFilePath(String jwkFilePath) {
275-
this.jwkFilePath = jwkFilePath;
276+
public void setJwkFedFilePath(String jwkFedFilePath) {
277+
this.jwkFedFilePath = jwkFedFilePath;
276278
}
277279

280+
public void setJwkCoreFilePath(String jwkCoreFilePath) {
281+
this.jwkCoreFilePath = jwkCoreFilePath;
282+
}
278283
// public void setTrustMarks(String trustMarks) {
279284
// this.trustMarks = trustMarks;
280285
// }
@@ -305,7 +310,8 @@ public JSONObject toJSON() {
305310
json.put("clientId", clientId);
306311
json.put("redirectUris", redirectUris);
307312
//json.put("jwk", jwk);
308-
json.put("jwkFilePath", jwkFilePath);
313+
json.put("jwkFilePath", jwkFedFilePath);
314+
json.put("jwkCoreFilePath", jwkCoreFilePath);
309315
//json.put("trustMarks", trustMarks);
310316
json.put("trustMarksFilePath", trustMarksFilePath);
311317

@@ -319,7 +325,8 @@ public JSONObject toJSON() {
319325
private String clientId;
320326
private Set<String> redirectUris = new HashSet<>();
321327
//private String jwk;
322-
private String jwkFilePath;
328+
private String jwkFedFilePath;
329+
private String jwkCoreFilePath;
323330
//private String trustMarks;
324331
private String trustMarksFilePath;
325332

0 commit comments

Comments
 (0)