mirror of
https://github.com/sismics/docs.git
synced 2024-12-23 11:43:49 +01:00
changed gson to jakarta.json
This commit is contained in:
parent
386a30045a
commit
f80b23369d
@ -69,11 +69,6 @@
|
|||||||
<artifactId>jul-to-slf4j</artifactId>
|
<artifactId>jul-to-slf4j</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.gson</groupId>
|
|
||||||
<artifactId>gson</artifactId>
|
|
||||||
<version>2.10.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.auth0</groupId>
|
<groupId>com.auth0</groupId>
|
||||||
<artifactId>java-jwt</artifactId>
|
<artifactId>java-jwt</artifactId>
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package com.sismics.model;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class KeycloakCertKey {
|
|
||||||
public String kid;
|
|
||||||
public List<String> x5c;
|
|
||||||
|
|
||||||
public KeycloakCertKey() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getX5c() {
|
|
||||||
return x5c;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setX5c(List<String> x5c) {
|
|
||||||
this.x5c = x5c;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKid() {
|
|
||||||
return kid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKid(String kid) {
|
|
||||||
this.kid = kid;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package com.sismics.model;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class KeycloakCertKeys {
|
|
||||||
public List<KeycloakCertKey> keys;
|
|
||||||
|
|
||||||
public KeycloakCertKeys() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<KeycloakCertKey> getKeys() {
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeys(List<KeycloakCertKey> keys) {
|
|
||||||
this.keys = keys;
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,11 +10,13 @@ import java.io.IOException;
|
|||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.sismics.docs.core.constant.Constants;
|
import com.sismics.docs.core.constant.Constants;
|
||||||
import com.sismics.docs.core.dao.UserDao;
|
import com.sismics.docs.core.dao.UserDao;
|
||||||
import com.sismics.docs.core.model.jpa.User;
|
import com.sismics.docs.core.model.jpa.User;
|
||||||
import com.sismics.model.KeycloakCertKeys;
|
import jakarta.json.Json;
|
||||||
|
import jakarta.json.JsonArray;
|
||||||
|
import jakarta.json.JsonObject;
|
||||||
|
import jakarta.json.JsonReader;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
@ -115,19 +117,23 @@ public class JwtBasedSecurityFilter extends SecurityFilter {
|
|||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
try (Reader reader = response.body().charStream()) {
|
try (Reader reader = response.body().charStream()) {
|
||||||
Gson gson = new Gson();
|
try (JsonReader jsonReader = Json.createReader(reader)) {
|
||||||
KeycloakCertKeys keys = gson.fromJson(reader, KeycloakCertKeys.class);
|
JsonObject jwks = jsonReader.readObject();
|
||||||
publicKey = keys.getKeys().stream().filter(k -> Objects.equals(k.getKid(), jwt.getKeyId()))
|
JsonArray keys = jwks.getJsonArray("keys");
|
||||||
|
publicKey = keys.stream().filter(key -> Objects.equals(key.asJsonObject().getString("kid"),
|
||||||
|
jwt.getKeyId()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(k -> k.getX5c().get(0))
|
.map(k -> k.asJsonObject().getJsonArray("x5c").getString(0))
|
||||||
.orElse("");
|
.orElse("");
|
||||||
log.info("Decoded public key - " + publicKey);
|
log.info("X5c is " + publicKey);
|
||||||
var decode = Base64.getDecoder().decode(publicKey);
|
var decode = Base64.getDecoder().decode(publicKey);
|
||||||
|
log.info("Decoded public key - " + publicKey);
|
||||||
var certificate = CertificateFactory.getInstance("X.509")
|
var certificate = CertificateFactory.getInstance("X.509")
|
||||||
.generateCertificate(new ByteArrayInputStream(decode));
|
.generateCertificate(new ByteArrayInputStream(decode));
|
||||||
rsaPublicKey = (RSAPublicKey) certificate.getPublicKey();
|
rsaPublicKey = (RSAPublicKey) certificate.getPublicKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error calling the jwt issuer at: " + jwtIssuerCerts, e);
|
log.error("Error calling the jwt issuer at: " + jwtIssuerCerts, e);
|
||||||
} catch (CertificateException e) {
|
} catch (CertificateException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user