From e03e0817beb005534b1ccac44d0b80885e46c591 Mon Sep 17 00:00:00 2001
From: Antonio Tarricone <110115827+antoniotarricone@users.noreply.github.com>
Date: Fri, 16 Jun 2023 15:43:51 +0200
Subject: [PATCH] feat: Optimizations. (#42)
---
dep-sha256.json | 7 +
lombok.config | 2 +
pom.xml | 7 +
.../swclient/mil/auth/bean/AccessToken.java | 42 +---
.../pagopa/swclient/mil/auth/bean/Client.java | 41 +---
.../mil/auth/bean/GetAccessToken.java | 101 +--------
.../swclient/mil/auth/bean/KeyPair.java | 143 +------------
.../pagopa/swclient/mil/auth/bean/KeyUse.java | 23 ++-
.../swclient/mil/auth/bean/PublicKey.java | 191 ++----------------
.../swclient/mil/auth/bean/PublicKeys.java | 51 +----
.../pagopa/swclient/mil/auth/bean/Role.java | 32 +--
.../swclient/mil/auth/bean/RoleEnum.java | 31 ++-
.../dao/ResourceOwnerCredentialsEntity.java | 64 +-----
.../mil/auth/resource/JwksResource.java | 38 +++-
.../mil/auth/resource/TokenResource.java | 12 +-
.../mil/auth/service/ClientVerifier.java | 3 +-
.../swclient/mil/auth/service/KeyFinder.java | 18 +-
.../mil/auth/service/KeyPairGenerator.java | 68 +------
.../auth/service/RefreshTokensService.java | 5 +-
.../mil/auth/service/RolesFinder.java | 24 ++-
.../service/TokenByClientSecretService.java | 1 +
.../auth/service/TokenByPasswordService.java | 13 +-
.../service/TokenByPoyntTokenService.java | 8 +-
.../mil/auth/service/TokenService.java | 8 +-
.../mil/auth/service/TokenVerifier.java | 4 +-
.../swclient/mil/auth/util/AuthError.java | 2 +-
.../swclient/mil/auth/util/AuthException.java | 2 +-
.../mil/auth/util/PasswordVerifier.java | 31 +--
.../mil/auth/util/TokenGenerator.java | 2 +-
.../validation/constraints/Validator.java | 16 +-
.../auth/validation/constraints/Verifier.java | 38 ++--
.../swclient/mil/auth/bean/PublicKeyTest.java | 133 ------------
.../mil/auth/bean/PublicKeysTest.java | 63 ------
.../mil/auth/resource/JwksResourceTest.java | 2 +-
.../mil/auth/resource/TokenResourceTest.java | 29 ++-
.../mil/auth/service/KeyFinderTest.java | 2 +-
.../service/KeyFinderWithExceptionTest.java | 2 +-
37 files changed, 260 insertions(+), 999 deletions(-)
create mode 100644 lombok.config
delete mode 100644 src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeyTest.java
delete mode 100644 src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeysTest.java
diff --git a/dep-sha256.json b/dep-sha256.json
index 2e7a1b97..eac235e6 100644
--- a/dep-sha256.json
+++ b/dep-sha256.json
@@ -1735,6 +1735,13 @@
"groupId": "io.quarkus",
"version": "3.1.0.Final",
"sha256": "CQrxChOQ6CJAt79ApWF_xW7EmsTzzxsHycigjRBD7eQ="
+ },
+ {
+ "id": "org.projectlombok:lombok:jar:1.18.28",
+ "artifactId": "lombok",
+ "groupId": "org.projectlombok",
+ "version": "1.18.28",
+ "sha256": "t3TcT8pUMiXYtejBY360E8Q2Oy5hPpUiJ3b3kqjOwOA="
}
]
}
\ No newline at end of file
diff --git a/lombok.config b/lombok.config
new file mode 100644
index 00000000..a23edb41
--- /dev/null
+++ b/lombok.config
@@ -0,0 +1,2 @@
+config.stopBubbling = true
+lombok.addLombokGeneratedAnnotation = true
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 296405c5..d97adc26 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,6 +32,7 @@
io.quarkus.platform
3.1.0.Final
true
+ 1.18.28
1.1.1
2.0.2
https://sonarcloud.io:443/
@@ -131,6 +132,12 @@
quarkus-jacoco
test
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/AccessToken.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/AccessToken.java
index a6385ee6..c4ef77ca 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/AccessToken.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/AccessToken.java
@@ -10,6 +10,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
+import lombok.Getter;
/**
*
@@ -17,12 +18,13 @@
*/
@RegisterForReflection
@JsonInclude(Include.NON_NULL)
+@Getter
public class AccessToken {
/*
* access_token
*/
@JsonProperty("access_token")
- private String accessToken;
+ private String accessTokenProper;
/*
* refresh_token
@@ -44,45 +46,13 @@ public class AccessToken {
/**
*
- * @param accessToken
+ * @param accessTokenProper
* @param refreshToken
* @param expiresIn
*/
- public AccessToken(String accessToken, String refreshToken, long expiresIn) {
- this.accessToken = accessToken;
+ public AccessToken(String accessTokenProper, String refreshToken, long expiresIn) {
+ this.accessTokenProper = accessTokenProper;
this.refreshToken = refreshToken;
this.expiresIn = expiresIn;
}
-
- /**
- *
- * @return the accessToken
- */
- public String getAccessToken() {
- return accessToken;
- }
-
- /**
- *
- * @return the refreshToken
- */
- public String getRefreshToken() {
- return refreshToken;
- }
-
- /**
- *
- * @return the tokenType
- */
- public String getTokenType() {
- return tokenType;
- }
-
- /**
- *
- * @return the expiresIn
- */
- public long getExpiresIn() {
- return expiresIn;
- }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/Client.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/Client.java
index 00ff2249..232e9697 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/Client.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/Client.java
@@ -5,11 +5,15 @@
*/
package it.pagopa.swclient.mil.auth.bean;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
/**
*
* @author Antonio Tarricone
*/
-@SuppressWarnings("unused")
+@AllArgsConstructor
+@Getter
public class Client {
/*
*
@@ -35,39 +39,4 @@ public class Client {
*
*/
private String description;
-
- /**
- * @param id
- * @param channel
- * @param secret
- * @param description
- */
- public Client(String id, String channel, String salt, String secretHash, String description) {
- this.id = id;
- this.channel = channel;
- this.salt = salt;
- this.secretHash = secretHash;
- this.description = description;
- }
-
- /**
- * @return the channel
- */
- public String getChannel() {
- return channel;
- }
-
- /**
- * @return the salt
- */
- public String getSalt() {
- return salt;
- }
-
- /**
- * @return the secretHash
- */
- public String getSecretHash() {
- return secretHash;
- }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/GetAccessToken.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/GetAccessToken.java
index 8e90b172..27eaa158 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/GetAccessToken.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/GetAccessToken.java
@@ -34,6 +34,8 @@
import jakarta.validation.constraints.Size;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.HeaderParam;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
/**
*
@@ -41,6 +43,8 @@
*/
@RegisterForReflection
@ValidationTarget(message = "[" + INCONSISTENT_REQUEST + "] Inconsistent request.")
+@NoArgsConstructor
+@Getter
public class GetAccessToken {
/*
* Request ID
@@ -150,101 +154,4 @@ public class GetAccessToken {
@FormParam("client_secret")
@Pattern(regexp = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$", message = "[" + CLIENT_SECRET_MUST_MATCH_REGEXP + "] client_secret must match \"{regexp}\"")
private String clientSecret;
-
- /**
- *
- */
- public GetAccessToken() {
- }
-
- /**
- * @return the acquirerId
- */
- public String getAcquirerId() {
- return acquirerId;
- }
-
- /**
- * @return the channel
- */
- public String getChannel() {
- return channel;
- }
-
- /**
- * @return the merchantId
- */
- public String getMerchantId() {
- return merchantId;
- }
-
- /**
- * @return the terminalId
- */
- public String getTerminalId() {
- return terminalId;
- }
-
- /**
- * @return the grantType
- */
- public String getGrantType() {
- return grantType;
- }
-
- /**
- * @return the username
- */
- public String getUsername() {
- return username;
- }
-
- /**
- * @return the password
- */
- public String getPassword() {
- return password;
- }
-
- /**
- * @return the refreshToken
- */
- public String getRefreshToken() {
- return refreshToken;
- }
-
- /**
- * @return the extToken
- */
- public String getExtToken() {
- return extToken;
- }
-
- /**
- * @return the addData
- */
- public String getAddData() {
- return addData;
- }
-
- /**
- * @return the clientId
- */
- public String getClientId() {
- return clientId;
- }
-
- /**
- * @return the scope
- */
- public String getScope() {
- return scope;
- }
-
- /**
- * @return the clientSecret
- */
- public String getClientSecret() {
- return clientSecret;
- }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyPair.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyPair.java
index aa91eaf6..cecb7905 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyPair.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyPair.java
@@ -6,13 +6,18 @@
package it.pagopa.swclient.mil.auth.bean;
import io.quarkus.runtime.annotations.RegisterForReflection;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
/**
*
* @author Antonio Tarricone
*/
@RegisterForReflection
-@SuppressWarnings("unused")
+@Getter
+@Setter
+@AllArgsConstructor
public class KeyPair {
/*
* Private exponent
@@ -34,41 +39,16 @@ public class KeyPair {
*/
private String kid;
- /*
- * Chinese remainder theorem exponent of the first factor
- */
- private String dp;
-
- /*
- * Chinese remainder theorem exponent of the second factor
- */
- private String dq;
-
/*
* Modulus
*/
private String n;
- /*
- * First prime factor
- */
- private String p;
-
/*
* Key type
*/
private KeyType kty;
- /*
- * Second prime factor
- */
- private String q;
-
- /*
- * First Chinese remainder theorem coefficient
- */
- private String qi;
-
/*
* Expiration time
*/
@@ -79,117 +59,6 @@ public class KeyPair {
*/
private long iat;
- /**
- *
- * @param d
- * @param e
- * @param use
- * @param kid
- * @param dp
- * @param dq
- * @param n
- * @param p
- * @param kty
- * @param q
- * @param qi
- * @param exp
- * @param iat
- */
- public KeyPair(String d, String e, KeyUse use, String kid, String dp, String dq, String n, String p, KeyType kty, String q, String qi, long exp, long iat) {
- this.d = d;
- this.e = e;
- this.use = use;
- this.kid = kid;
- this.dp = dp;
- this.dq = dq;
- this.n = n;
- this.p = p;
- this.kty = kty;
- this.q = q;
- this.qi = qi;
- this.exp = exp;
- this.iat = iat;
- }
-
- /**
- *
- * @return the d
- */
- public String getD() {
- return d;
- }
-
- /**
- *
- * @return the e
- */
- public String getE() {
- return e;
- }
-
- /**
- *
- * @return the use
- */
- public KeyUse getUse() {
- return use;
- }
-
- /**
- *
- * @return the kid
- */
- public String getKid() {
- return kid;
- }
-
- /**
- *
- * @param kid the kid to set
- */
- public void setKid(String kid) {
- this.kid = kid;
- }
-
- /**
- *
- * @return the n
- */
- public String getN() {
- return n;
- }
-
- /**
- *
- * @return the kty
- */
- public KeyType getKty() {
- return kty;
- }
-
- /**
- *
- * @return the exp
- */
- public long getExp() {
- return exp;
- }
-
- /**
- * @param exp the exp to set
- */
- public void setExp(long exp) {
- this.exp = exp;
- }
-
- /**
- *
- * @return the iat
- */
- public long getIat() {
- return iat;
- }
-
/**
*
* @return
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyUse.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyUse.java
index f11251fa..a42f46f8 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyUse.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/KeyUse.java
@@ -10,5 +10,26 @@
* @author Antonio Tarricone
*/
public enum KeyUse {
- sig
+ SIG("sig");
+
+ /*
+ * String value.
+ */
+ private String string;
+
+ /**
+ *
+ * @param string
+ */
+ private KeyUse(String string) {
+ this.string = string;
+ }
+
+ /**
+ *
+ */
+ @Override
+ public String toString() {
+ return string;
+ }
}
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKey.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKey.java
index c5a52688..0f0a44b7 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKey.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKey.java
@@ -5,16 +5,18 @@
*/
package it.pagopa.swclient.mil.auth.bean;
-import java.util.Objects;
-
import io.quarkus.runtime.annotations.RegisterForReflection;
+import lombok.AllArgsConstructor;
+import lombok.Data;
/**
*
* @author Antonio Tarricone
*/
@RegisterForReflection
-public class PublicKey implements Cloneable {
+@Data
+@AllArgsConstructor
+public class PublicKey {
/*
* Public exponent
*/
@@ -52,178 +54,15 @@ public class PublicKey implements Cloneable {
/**
*
- * @param e
- * @param use
- * @param kid
- * @param n
- * @param kty
- * @param exp
- * @param iat
- */
- public PublicKey(String e, KeyUse use, String kid, String n, KeyType kty, long exp, long iat) {
- this.e = e;
- this.use = use;
- this.kid = kid;
- this.n = n;
- this.kty = kty;
- this.exp = exp;
- this.iat = iat;
- }
-
- /**
- *
- * @return the e
- */
- public String getE() {
- return e;
- }
-
- /**
- *
- * @return the use
- */
- public KeyUse getUse() {
- return use;
- }
-
- /**
- *
- * @return the kid
- */
- public String getKid() {
- return kid;
- }
-
- /**
- *
- * @return the n
- */
- public String getN() {
- return n;
- }
-
- /**
- *
- * @return the kty
- */
- public KeyType getKty() {
- return kty;
- }
-
- /**
- *
- * @return the exp
- */
- public long getExp() {
- return exp;
- }
-
- /**
- *
- * @return the iat
- */
- public long getIat() {
- return iat;
- }
-
- /**
- * @param e the e to set
- */
- public void setE(String e) {
- this.e = e;
- }
-
- /**
- * @param use the use to set
- */
- public void setUse(KeyUse use) {
- this.use = use;
- }
-
- /**
- * @param kid the kid to set
- */
- public void setKid(String kid) {
- this.kid = kid;
- }
-
- /**
- * @param n the n to set
- */
- public void setN(String n) {
- this.n = n;
- }
-
- /**
- * @param kty the kty to set
- */
- public void setKty(KeyType kty) {
- this.kty = kty;
- }
-
- /**
- * @param exp the exp to set
- */
- public void setExp(long exp) {
- this.exp = exp;
- }
-
- /**
- * @param iat the iat to set
- */
- public void setIat(long iat) {
- this.iat = iat;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return new StringBuilder("PublicKey [e=")
- .append(e)
- .append(", use=")
- .append(use)
- .append(", kid=")
- .append(kid)
- .append(", n=")
- .append(n)
- .append(", kty=")
- .append(kty)
- .append(", exp=")
- .append(exp)
- .append(", iat=")
- .append(iat)
- .append("]")
- .toString();
- }
-
- /**
- * @see java.lang.Object#equals(Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- PublicKey other = (PublicKey) obj;
- return Objects.equals(e, other.e)
- && exp == other.exp
- && iat == other.iat
- && Objects.equals(kid, other.kid)
- && kty == other.kty
- && Objects.equals(n, other.n)
- && use == other.use;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Object clone() throws CloneNotSupportedException {
- return new PublicKey(e, use, kid, n, kty, exp, iat);
+ * @param publicKey
+ */
+ public PublicKey(PublicKey publicKey) {
+ this.e = publicKey.e;
+ this.use = publicKey.use;
+ this.kid = publicKey.kid;
+ this.n = publicKey.n;
+ this.kty = publicKey.kty;
+ this.exp = publicKey.exp;
+ this.iat = publicKey.iat;
}
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKeys.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKeys.java
index 63bb14da..2ce0dcbf 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKeys.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/PublicKeys.java
@@ -6,60 +6,25 @@
package it.pagopa.swclient.mil.auth.bean;
import java.util.List;
-import java.util.Objects;
import io.quarkus.runtime.annotations.RegisterForReflection;
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.ToString;
/**
*
* @author Antonio Tarricone
*/
@RegisterForReflection
+@AllArgsConstructor
+@Getter
+@ToString
+@EqualsAndHashCode
public class PublicKeys {
/*
*
*/
private List keys;
-
- /**
- *
- * @param keys
- */
- public PublicKeys(List keys) {
- this.keys = keys;
- }
-
- /**
- *
- * @return the keys
- */
- public List getKeys() {
- return keys;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return new StringBuilder("PublicKeys [keys=")
- .append(keys)
- .append("]")
- .toString();
- }
-
- /**
- * @see java.lang.Object#equals(Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- PublicKeys other = (PublicKeys) obj;
- return Objects.equals(keys, other.keys);
- }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/Role.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/Role.java
index 2d17d861..5d000dde 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/Role.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/Role.java
@@ -7,11 +7,15 @@
import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
/**
*
* @author Antonio Tarricone
*/
-@SuppressWarnings("unused")
+@AllArgsConstructor
+@Getter
public class Role {
/*
*
@@ -42,30 +46,4 @@ public class Role {
*
*/
private List roles;
-
- /**
- *
- * @param acquirerId
- * @param channel
- * @param clientId
- * @param merchantId
- * @param terminalId
- * @param roles
- */
- public Role(String acquirerId, String channel, String clientId, String merchantId, String terminalId, List roles) {
- this.acquirerId = acquirerId;
- this.channel = channel;
- this.clientId = clientId;
- this.merchantId = merchantId;
- this.terminalId = terminalId;
- this.roles = roles;
- }
-
- /**
- *
- * @return the roles
- */
- public List getRoles() {
- return roles;
- }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/bean/RoleEnum.java b/src/main/java/it/pagopa/swclient/mil/auth/bean/RoleEnum.java
index c6d4a301..18b55e68 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/bean/RoleEnum.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/bean/RoleEnum.java
@@ -10,9 +10,30 @@
* @author Antonio Tarricone
*/
public enum RoleEnum {
- Nodo,
- NoticePayer,
- InstitutionPortal,
- ServiceListRequester,
- SlavePos;
+ NODO("Nodo"),
+ NOTICE_PAYER("NoticePayer"),
+ INSTITUTION_PORTAL("InstitutionPortal"),
+ SERVICE_LIST_REQUESTER("ServiceListRequester"),
+ SLAVE_POS("SlavePos");
+
+ /*
+ * String value.
+ */
+ private String string;
+
+ /**
+ *
+ * @param string
+ */
+ private RoleEnum(String string) {
+ this.string = string;
+ }
+
+ /**
+ *
+ */
+ @Override
+ public String toString() {
+ return string;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/dao/ResourceOwnerCredentialsEntity.java b/src/main/java/it/pagopa/swclient/mil/auth/dao/ResourceOwnerCredentialsEntity.java
index 5c4af49f..fc40527f 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/dao/ResourceOwnerCredentialsEntity.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/dao/ResourceOwnerCredentialsEntity.java
@@ -5,13 +5,17 @@
*/
package it.pagopa.swclient.mil.auth.dao;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
/**
*
* FOR DEMO ONLY. THIS WILL BE REPLACED BY DB.
*
* @author Antonio Tarricone
*/
-@SuppressWarnings("unused")
+@AllArgsConstructor
+@Getter
public class ResourceOwnerCredentialsEntity {
/*
*
@@ -42,62 +46,4 @@ public class ResourceOwnerCredentialsEntity {
*
*/
private String merchantId;
-
- /**
- *
- * @param username
- * @param salt
- * @param passwordHash
- * @param acquirerId
- * @param channel
- * @param merchantId
- */
- public ResourceOwnerCredentialsEntity(String username, String salt, String passwordHash, String acquirerId, String channel, String merchantId) {
- this.username = username;
- this.salt = salt;
- this.passwordHash = passwordHash;
- this.acquirerId = acquirerId;
- this.channel = channel;
- this.merchantId = merchantId;
- }
-
- /**
- *
- * @return the salt
- */
- public String getSalt() {
- return salt;
- }
-
- /**
- *
- * @return the passwordHash
- */
- public String getPasswordHash() {
- return passwordHash;
- }
-
- /**
- *
- * @return the acquirerId
- */
- public String getAcquirerId() {
- return acquirerId;
- }
-
- /**
- *
- * @return the channel
- */
- public String getChannel() {
- return channel;
- }
-
- /**
- *
- * @return the merchantId
- */
- public String getMerchantId() {
- return merchantId;
- }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/resource/JwksResource.java b/src/main/java/it/pagopa/swclient/mil/auth/resource/JwksResource.java
index 3a932961..2bb73de9 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/resource/JwksResource.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/resource/JwksResource.java
@@ -7,11 +7,12 @@
import static it.pagopa.swclient.mil.auth.ErrorCode.ERROR_SEARCHING_FOR_KEYS;
+import java.time.Instant;
import java.util.List;
import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
-import it.pagopa.swclient.mil.auth.bean.PublicKeys;
+import it.pagopa.swclient.mil.auth.bean.PublicKey;
import it.pagopa.swclient.mil.auth.service.KeyFinder;
import it.pagopa.swclient.mil.bean.Errors;
import jakarta.inject.Inject;
@@ -19,6 +20,7 @@
import jakarta.ws.rs.InternalServerErrorException;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.CacheControl;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
@@ -29,6 +31,11 @@
*/
@Path("/.well-known/jwks.json")
public class JwksResource {
+ /*
+ *
+ */
+ private static final long SKEW = 5 * 60 * 1000L;
+
/*
*
*/
@@ -55,10 +62,35 @@ private InternalServerErrorException errorOnRetrievingKeys(Throwable t) {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
- public Uni get() {
+ public Uni get() {
Log.debug("get - Input parameters: n/a");
return keyRetriever.findPublicKeys() // Retrieve keys.
- .invoke(t -> Log.debugf("get - Output parameters: %s", t.toString()))
+ .invoke(l -> Log.debugf("get - Output parameters: %s", l.toString()))
+ .map(l -> {
+ // Search the key that exiperes first to set Cache-Control/max-age
+ long minExp = 0; // millis
+ for (PublicKey k : l.getKeys()) {
+ long exp = k.getExp() - SKEW; // To be sure that will not be cached keys that will expire in a while, subtract SKEW.
+ if (exp < minExp) {
+ minExp = exp;
+ }
+ }
+
+ int maxAge = (int)(minExp - Instant.now().toEpochMilli()) / 1000; // s
+
+ CacheControl cacheControl = new CacheControl();
+ if (maxAge > 0) {
+ cacheControl.setMaxAge(maxAge);
+ } else {
+ cacheControl.setNoCache(true);
+ }
+
+ return Response
+ .status(Status.OK)
+ .cacheControl(cacheControl)
+ .entity(l)
+ .build();
+ })
.onFailure().transform(this::errorOnRetrievingKeys); // Error while retrieving keys.
}
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/resource/TokenResource.java b/src/main/java/it/pagopa/swclient/mil/auth/resource/TokenResource.java
index 8f45bb55..119917b1 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/resource/TokenResource.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/resource/TokenResource.java
@@ -56,15 +56,15 @@ public class TokenResource {
/*
*
*/
- private static Map> QUALIFIERS = new HashMap<>();
+ private static Map> qualifiers = new HashMap<>();
static {
- QUALIFIERS.put(GrantType.CLIENT_CREDENTIALS, new AnnotationLiteral() {
+ qualifiers.put(GrantType.CLIENT_CREDENTIALS, new AnnotationLiteral() {
});
- QUALIFIERS.put(GrantType.PASSWORD, new AnnotationLiteral() {
+ qualifiers.put(GrantType.PASSWORD, new AnnotationLiteral() {
});
- QUALIFIERS.put(GrantType.POYNT_TOKEN, new AnnotationLiteral() {
+ qualifiers.put(GrantType.POYNT_TOKEN, new AnnotationLiteral() {
});
- QUALIFIERS.put(GrantType.REFRESH_TOKEN, new AnnotationLiteral() {
+ qualifiers.put(GrantType.REFRESH_TOKEN, new AnnotationLiteral() {
});
}
@@ -81,7 +81,7 @@ public Uni createOrRefreshToken(@Valid @BeanParam GetAccessToken ge
/*
* If the flow reaches this point, the input is validated!
*/
- return tokenService.select(QUALIFIERS.get(getAccessToken.getGrantType()))
+ return tokenService.select(qualifiers.get(getAccessToken.getGrantType()))
.get()
.process(getAccessToken)
.onFailure(t -> !(t instanceof AuthError || t instanceof AuthException))
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/ClientVerifier.java b/src/main/java/it/pagopa/swclient/mil/auth/service/ClientVerifier.java
index e061f007..e5abc559 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/ClientVerifier.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/ClientVerifier.java
@@ -59,8 +59,7 @@ public Uni findClient(String clientId) {
Log.debugf("Search for the client %s.", clientId);
return getClient(clientId)
.onFailure().transform(t -> {
- if (t instanceof WebApplicationException) {
- WebApplicationException e = (WebApplicationException) t;
+ if (t instanceof WebApplicationException e) {
Response r = e.getResponse();
// r cannot be null
if (r.getStatus() == 404) {
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/KeyFinder.java b/src/main/java/it/pagopa/swclient/mil/auth/service/KeyFinder.java
index cf56425d..0ff24a51 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/KeyFinder.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/KeyFinder.java
@@ -12,6 +12,8 @@
import java.time.Instant;
import java.util.Optional;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
import com.nimbusds.jose.JOSEException;
import io.quarkus.logging.Log;
@@ -29,6 +31,12 @@
*/
@ApplicationScoped
public class KeyFinder {
+ /*
+ * Access token duration.
+ */
+ @ConfigProperty(name = "access.duration")
+ long accessDuration;
+
/*
*
*/
@@ -52,7 +60,7 @@ public Uni findKeyPair() {
return redisClient.keys("*") // Loading kids.
.onItem().transformToMulti(kids -> Multi.createFrom().items(kids.stream())) // Transforming the list of kids in a stream of events (one event for a kid).
.onItem().transformToUniAndMerge(redisClient::get) // For each kid, getting the key pair.
- .filter(k -> k.getExp() > Instant.now().toEpochMilli()) // Filtering expired key pairs.
+ .filter(k -> k.getExp() > Instant.now().toEpochMilli() - accessDuration * 1000) // Filtering expired key pairs or that will expire before the expiration of the access token.
.collect() // Collecting all key pairs.
.asList() // Converting the key pair events in an event that is the list of key pair.
.chain(l -> {
@@ -71,9 +79,7 @@ public Uni findKeyPair() {
// Key pair storage in Redis.
Log.debug("Key pair storage.");
return redisClient.setex(keyPair.getKid(), keyPair.getExp(), keyPair)
- .chain(() -> {
- return item(keyPair);
- });
+ .chain(() -> item(keyPair));
} catch (JOSEException e) {
String message = String.format("[%s] Error generating the key pair.", ERROR_GENERATING_KEY_PAIR);
Log.fatalf(e, message);
@@ -108,11 +114,11 @@ public Uni findPublicKeys() {
.onItem().transformToMulti(kids -> Multi.createFrom().items(kids.stream())) // Transforming the list of kids in a stream of events (one event for a kid).
.onItem().transformToUniAndMerge(redisClient::get) // For each kid, getting the key pair.
.filter(k -> k.getExp() > Instant.now().toEpochMilli()) // Filtering expired key pairs.
- .map(k -> k.publicKey()) // Getting the public key from the key pair.
+ .map(KeyPair::publicKey) // Getting the public key from the key pair.
.collect() // Collecting all public keys.
.asList() // Converting the public key events in an event that is the list of public keys.
.invoke(l -> Log.debugf("Found %d valid key/s.", l.size()))
- .map(l -> new PublicKeys(l));
+ .map(PublicKeys::new);
}
/**
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/KeyPairGenerator.java b/src/main/java/it/pagopa/swclient/mil/auth/service/KeyPairGenerator.java
index aa967abe..e75687ab 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/KeyPairGenerator.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/KeyPairGenerator.java
@@ -5,20 +5,14 @@
*/
package it.pagopa.swclient.mil.auth.service;
-// import java.io.IOException;
-// import java.io.StringWriter;
import java.util.Date;
import java.util.UUID;
import org.eclipse.microprofile.config.inject.ConfigProperty;
-// import com.fasterxml.jackson.core.exc.StreamWriteException;
-// import com.fasterxml.jackson.databind.DatabindException;
-// import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.jwk.RSAKey;
import com.nimbusds.jose.jwk.gen.RSAKeyGenerator;
-// import com.nimbusds.jose.util.Base64URL;
import it.pagopa.swclient.mil.auth.bean.KeyPair;
import it.pagopa.swclient.mil.auth.bean.KeyType;
@@ -63,53 +57,28 @@ public KeyPair generate() throws JOSEException {
/*
* Private exponent
*/
- String d = rsaJwk.getPrivateExponent().toJSONString().replaceAll("\"", "");
+ String d = rsaJwk.getPrivateExponent().toJSONString().replace("\"", "");
/*
* Public exponent
*/
- String e = rsaJwk.getPublicExponent().toJSONString().replaceAll("\"", "");
+ String e = rsaJwk.getPublicExponent().toJSONString().replace("\"", "");
/*
* Public key use
*/
- KeyUse use = KeyUse.sig;
-
- /*
- * Chinese remainder theorem exponent of the first factor
- */
- String dp = rsaJwk.getFirstFactorCRTExponent().toJSONString().replaceAll("\"", "");
-
- /*
- * Chinese remainder theorem exponent of the second factor
- */
- String dq = rsaJwk.getSecondFactorCRTExponent().toJSONString().replaceAll("\"", "");
+ KeyUse use = KeyUse.SIG;
/*
* Modulus
*/
- String n = rsaJwk.getModulus().toJSONString().replaceAll("\"", "");
-
- /*
- * First prime factor
- */
- String p = rsaJwk.getFirstPrimeFactor().toJSONString().replaceAll("\"", "");
+ String n = rsaJwk.getModulus().toJSONString().replace("\"", "");
/*
* Key type
*/
KeyType kty = KeyType.RSA;
- /*
- * Second prime factor
- */
- String q = rsaJwk.getSecondPrimeFactor().toJSONString().replaceAll("\"", "");
-
- /*
- * First Chinese remainder theorem coefficient
- */
- String qi = rsaJwk.getFirstCRTCoefficient().toJSONString().replaceAll("\"", "");
-
/*
* Expiration time
*/
@@ -120,33 +89,6 @@ public KeyPair generate() throws JOSEException {
*/
long iat = issueTime.getTime();
- return new KeyPair(d, e, use, kid, dp, dq, n, p, kty, q, qi, exp, iat);
+ return new KeyPair(d, e, use, kid, n, kty, exp, iat);
}
-
- /**
- *
- * @param agrs
- * @throws JOSEException
- * @throws StreamWriteException
- * @throws DatabindException
- * @throws IOException
- */
- // public static void main(String[] agrs) throws JOSEException, StreamWriteException,
- // DatabindException, IOException {
- // KeyPairGenerator generator = new KeyPairGenerator();
- // generator.cryptoperiod = 10 * 365 * 24 * 60 * 60 * 1000;
- // generator.keysize = 4096;
- // KeyPair keyPair = generator.generateRsaKey();
- // System.out.println(keyPair);
- // StringWriter writer = new StringWriter();
- // new ObjectMapper().writeValue(writer, keyPair);
- // String json = writer.toString();
- // System.out.println(json);
- // String base64url = Base64URL.encode(json).toString();
- // System.out.println(base64url);
- //
- // String keyPairJson = Base64URL.from(base64url).decodeToString();
- // KeyPair recovered = new ObjectMapper().readValue(keyPairJson, KeyPair.class);
- // System.out.println(recovered);
- // }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/RefreshTokensService.java b/src/main/java/it/pagopa/swclient/mil/auth/service/RefreshTokensService.java
index e99f98a4..8ac2f1b2 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/RefreshTokensService.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/RefreshTokensService.java
@@ -31,11 +31,10 @@ public class RefreshTokensService extends TokenService {
* @param getAccessToken
* @return
*/
+ @Override
public Uni process(GetAccessToken getAccessToken) {
Log.debug("Tokens refreshing.");
return refreshTokenVerifier.verify(getAccessToken.getRefreshToken())
- .chain(() -> {
- return super.process(getAccessToken);
- });
+ .chain(() -> super.process(getAccessToken));
}
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/RolesFinder.java b/src/main/java/it/pagopa/swclient/mil/auth/service/RolesFinder.java
index 1e33f2fc..7dcf1612 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/RolesFinder.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/RolesFinder.java
@@ -42,7 +42,7 @@ public class RolesFinder {
private String replaceNullWithNa(String s) {
return s != null ? s : "NA";
}
-
+
/**
*
* @param acquirerId
@@ -75,8 +75,7 @@ private Uni find(String acquirerId, String channel, String clientId, Strin
replaceNullWithNa(merchantId),
replaceNullWithNa(terminalId))
.onFailure().transform(t -> {
- if (t instanceof WebApplicationException) {
- WebApplicationException e = (WebApplicationException) t;
+ if (t instanceof WebApplicationException e) {
Response r = e.getResponse();
// r cannot be null
if (r.getStatus() == 404) {
@@ -94,11 +93,9 @@ private Uni find(String acquirerId, String channel, String clientId, Strin
return new AuthError(ERROR_SEARCHING_FOR_ROLES, message);
}
})
- .chain(r -> {
- return UniGenerator.item(r);
- });
+ .chain(UniGenerator::item);
}
-
+
/**
* Finds roles.
*
@@ -118,7 +115,18 @@ public Uni findRoles(String acquirerId, String channel, String clientId, S
* If there are no roles for acquirer/channel/client/merchant/terminal, search for
* acquirer/channel/client/merchant (without terminal).
*/
- return find(acquirerId, channel, clientId, merchantId, "NA");
+ return find(acquirerId, channel, clientId, merchantId, "NA").onFailure(AuthException.class)
+ .recoverWithUni(tt -> {
+ if (merchantId != null) {
+ /*
+ * If there are no roles for acquirer/channel/client/merchant (without terminal), search for
+ * acquirer/channel/client (without terminal and merchant).
+ */
+ return find(acquirerId, channel, clientId, "NA", "NA");
+ } else {
+ return Uni.createFrom().failure(tt);
+ }
+ });
} else {
return Uni.createFrom().failure(t);
}
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByClientSecretService.java b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByClientSecretService.java
index 3dbc10bb..c864380c 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByClientSecretService.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByClientSecretService.java
@@ -24,6 +24,7 @@ public class TokenByClientSecretService extends TokenService {
* @param getAccessToken
* @return
*/
+ @Override
public Uni process(GetAccessToken getAccessToken) {
Log.debugf("Generation of the token by client secret.");
return super.process(getAccessToken);
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPasswordService.java b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPasswordService.java
index cb01c44f..35fe9977 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPasswordService.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPasswordService.java
@@ -134,12 +134,8 @@ private Uni verifyPassword(ResourceOwnerCredentialsEntity credentialsEntit
*/
private Uni verifyCredentials(GetAccessToken getAccessToken) {
return findCredentials(getAccessToken)
- .chain(c -> {
- return verifyConsistency(c, getAccessToken);
- })
- .chain(c -> {
- return verifyPassword(c, getAccessToken);
- });
+ .chain(c -> verifyConsistency(c, getAccessToken))
+ .chain(c -> verifyPassword(c, getAccessToken));
}
/**
@@ -147,11 +143,10 @@ private Uni verifyCredentials(GetAccessToken getAccessToken) {
* @param getAccessToken
* @return
*/
+ @Override
public Uni process(GetAccessToken getAccessToken) {
Log.debugf("Generation of the token/s by password.");
return verifyCredentials(getAccessToken)
- .chain(() -> {
- return super.process(getAccessToken);
- });
+ .chain(() -> super.process(getAccessToken));
}
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPoyntTokenService.java b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPoyntTokenService.java
index 86cfbac5..4ccc9138 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPoyntTokenService.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenByPoyntTokenService.java
@@ -47,8 +47,7 @@ public Uni verifyPoyntToken(GetAccessToken getAccessToken) {
Log.debug("Poynt token verification.");
return poyntClient.getBusinessObject("Bearer " + getAccessToken.getExtToken(), getAccessToken.getAddData())
.onFailure().transform(t -> {
- if (t instanceof WebApplicationException) {
- WebApplicationException e = (WebApplicationException) t;
+ if (t instanceof WebApplicationException e) {
Response r = e.getResponse();
// r cannot be null
String message = String.format("[%s] Poynt Token not valid. Status: %s", EXT_TOKEN_NOT_VALID, r.getStatus());
@@ -77,11 +76,10 @@ public Uni verifyPoyntToken(GetAccessToken getAccessToken) {
* @param getAccessToken
* @return
*/
+ @Override
public Uni process(GetAccessToken getAccessToken) {
Log.debugf("Generation of the token/s by Poynt token.");
return verifyPoyntToken(getAccessToken)
- .chain(() -> {
- return super.process(getAccessToken);
- });
+ .chain(() -> super.process(getAccessToken));
}
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenService.java b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenService.java
index 1b6ae310..2ece219a 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenService.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenService.java
@@ -98,11 +98,7 @@ private Uni generateToken(GetAccessToken getAccessToken, List process(GetAccessToken getAccessToken) {
return clientVerifier.verify(getAccessToken.getClientId(), getAccessToken.getChannel(), getAccessToken.getClientSecret())
- .chain(() -> {
- return roleFinder.findRoles(getAccessToken.getAcquirerId(), getAccessToken.getChannel(), getAccessToken.getClientId(), getAccessToken.getMerchantId(), getAccessToken.getTerminalId());
- })
- .chain(roleEntity -> {
- return generateToken(getAccessToken, roleEntity.getRoles());
- });
+ .chain(() -> roleFinder.findRoles(getAccessToken.getAcquirerId(), getAccessToken.getChannel(), getAccessToken.getClientId(), getAccessToken.getMerchantId(), getAccessToken.getTerminalId()))
+ .chain(roleEntity -> generateToken(getAccessToken, roleEntity.getRoles()));
}
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenVerifier.java b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenVerifier.java
index cdec6a8a..d37e78db 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/service/TokenVerifier.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/service/TokenVerifier.java
@@ -210,8 +210,6 @@ private Uni findPublicKey(String kid) {
protected Uni verifySignature(SignedJWT token) {
String kid = token.getHeader().getKeyID();
return findPublicKey(kid)
- .chain(k -> {
- return verifySignature(token, k);
- });
+ .chain(k -> verifySignature(token, k));
}
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/util/AuthError.java b/src/main/java/it/pagopa/swclient/mil/auth/util/AuthError.java
index 97dd1361..9b14f82c 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/util/AuthError.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/util/AuthError.java
@@ -20,7 +20,7 @@ public class AuthError extends Error {
/*
*
*/
- private String code;
+ private final String code;
/**
*
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/util/AuthException.java b/src/main/java/it/pagopa/swclient/mil/auth/util/AuthException.java
index 330f12e2..0f366772 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/util/AuthException.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/util/AuthException.java
@@ -19,7 +19,7 @@ public class AuthException extends RuntimeException {
/*
*
*/
- private String code;
+ private final String code;
/**
*
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/util/PasswordVerifier.java b/src/main/java/it/pagopa/swclient/mil/auth/util/PasswordVerifier.java
index 9d5fa9e3..fc5202e2 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/util/PasswordVerifier.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/util/PasswordVerifier.java
@@ -52,8 +52,7 @@ private static byte[] hashBytes(String password, String salt) throws NoSuchAlgor
System.arraycopy(saltBytes, 0, data, passwordBytes.length, saltBytes.length);
MessageDigest digest = MessageDigest.getInstance("SHA256");
- byte[] hashBytes = digest.digest(data);
- return hashBytes;
+ return digest.digest(data);
}
/**
@@ -65,32 +64,6 @@ private static byte[] hashBytes(String password, String salt) throws NoSuchAlgor
*/
public static String hash(String password, String salt) throws NoSuchAlgorithmException {
byte[] hashBytes = hashBytes(password, salt);
- String hash = Base64.getEncoder().encodeToString(hashBytes);
- return hash;
+ return Base64.getEncoder().encodeToString(hashBytes);
}
-
- // /**
- // *
- // * @throws NoSuchAlgorithmException
- // */
- // public static void generateSecrets() throws NoSuchAlgorithmException {
- // byte[] buf = new byte[64];
- // SecureRandom secure = SecureRandom.getInstanceStrong();
- // for (int i = 0; i < 4; i++) {
- // secure.nextBytes(buf);
- // String salt = Base64.getEncoder().encodeToString(buf);
- // String secret = UUID.randomUUID().toString();
- // String hash = hash(secret, salt);
- // System.out.printf("%d\t%s\t%s\t%s%n", i, salt, secret, hash);
- // }
- // }
- //
- // /**
- // *
- // * @param args
- // * @throws NoSuchAlgorithmException
- // */
- // public static void main(String[] args) throws NoSuchAlgorithmException {
- // generateSecrets();
- // }
}
\ No newline at end of file
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/util/TokenGenerator.java b/src/main/java/it/pagopa/swclient/mil/auth/util/TokenGenerator.java
index faa9899c..bd98dc14 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/util/TokenGenerator.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/util/TokenGenerator.java
@@ -37,7 +37,7 @@ private static String concat(List strings) {
if (strings == null) {
return null;
}
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
strings.forEach(x -> {
buffer.append(x);
buffer.append(" ");
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Validator.java b/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Validator.java
index 8b0f4efd..dce4c8e0 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Validator.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Validator.java
@@ -28,9 +28,9 @@ public class Validator implements ConstraintValidator VALIDATOR = new HashMap<>();
+ private static final Map VALIDATORS = new HashMap<>();
static {
- VALIDATOR.put(PASSWORD + "/" + POS, new Verifier() {
+ VALIDATORS.put(PASSWORD + "/" + POS, new Verifier() {
@Override
public boolean test(GetAccessToken getAccessToken) {
return acquirerIdMustNotBeNull(getAccessToken)
@@ -45,7 +45,7 @@ && usernameMustNotBeNull(getAccessToken)
}
});
- VALIDATOR.put(REFRESH_TOKEN + "/" + POS, new Verifier() {
+ VALIDATORS.put(REFRESH_TOKEN + "/" + POS, new Verifier() {
@Override
public boolean test(GetAccessToken getAccessToken) {
return acquirerIdMustNotBeNull(getAccessToken)
@@ -62,7 +62,7 @@ && passwordMustBeNull(getAccessToken)
});
- VALIDATOR.put(POYNT_TOKEN + "/" + POS, new Verifier() {
+ VALIDATORS.put(POYNT_TOKEN + "/" + POS, new Verifier() {
@Override
public boolean test(GetAccessToken getAccessToken) {
return acquirerIdMustNotBeNull(getAccessToken)
@@ -77,7 +77,7 @@ && usernameMustBeNull(getAccessToken)
}
});
- VALIDATOR.put(CLIENT_CREDENTIALS + "/" + ATM, new Verifier() {
+ VALIDATORS.put(CLIENT_CREDENTIALS + "/" + ATM, new Verifier() {
@Override
public boolean test(GetAccessToken getAccessToken) {
return acquirerIdMustNotBeNull(getAccessToken)
@@ -93,7 +93,7 @@ && passwordMustBeNull(getAccessToken)
}
});
- VALIDATOR.put(CLIENT_CREDENTIALS + "/" + POS, new Verifier() {
+ VALIDATORS.put(CLIENT_CREDENTIALS + "/" + POS, new Verifier() {
@Override
public boolean test(GetAccessToken getAccessToken) {
return acquirerIdMustNotBeNull(getAccessToken)
@@ -109,7 +109,7 @@ && passwordMustBeNull(getAccessToken)
}
});
- VALIDATOR.put(CLIENT_CREDENTIALS + "/null", new Verifier() {
+ VALIDATORS.put(CLIENT_CREDENTIALS + "/null", new Verifier() {
@Override
public boolean test(GetAccessToken getAccessToken) {
return acquirerIdMustBeNull(getAccessToken)
@@ -131,7 +131,7 @@ && passwordMustBeNull(getAccessToken)
*/
@Override
public boolean isValid(GetAccessToken getAccessToken, ConstraintValidatorContext context) {
- return VALIDATOR.getOrDefault(getAccessToken.getGrantType() + "/" + getAccessToken.getChannel(), new Verifier() {
+ return VALIDATORS.getOrDefault(getAccessToken.getGrantType() + "/" + getAccessToken.getChannel(), new Verifier() {
@Override
public boolean test(GetAccessToken t) {
Log.warn("Default validator in use.");
diff --git a/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Verifier.java b/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Verifier.java
index 2e79e8df..a883c287 100644
--- a/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Verifier.java
+++ b/src/main/java/it/pagopa/swclient/mil/auth/validation/constraints/Verifier.java
@@ -22,7 +22,7 @@ public abstract class Verifier implements Predicate {
*/
protected boolean acquirerIdMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getAcquirerId() == null;
- if (check == false) {
+ if (!check) {
Log.warn("AcquirerId must be null.");
}
return check;
@@ -35,7 +35,7 @@ protected boolean acquirerIdMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean acquirerIdMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getAcquirerId() != null;
- if (check == false) {
+ if (!check) {
Log.warn("AcquirerId must not be null.");
}
return check;
@@ -48,7 +48,7 @@ protected boolean acquirerIdMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean merchantIdMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getMerchantId() == null;
- if (check == false) {
+ if (!check) {
Log.warn("MerchantId must be null.");
}
return check;
@@ -61,7 +61,7 @@ protected boolean merchantIdMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean merchantIdMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getMerchantId() != null;
- if (check == false) {
+ if (!check) {
Log.warn("MerchantId must not be null.");
}
return check;
@@ -74,7 +74,7 @@ protected boolean merchantIdMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean terminalIdMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getTerminalId() == null;
- if (check == false) {
+ if (!check) {
Log.warn("TerminalId must be null.");
}
return check;
@@ -87,7 +87,7 @@ protected boolean terminalIdMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean terminalIdMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getTerminalId() != null;
- if (check == false) {
+ if (!check) {
Log.warn("TerminalId must not be null.");
}
return check;
@@ -100,7 +100,7 @@ protected boolean terminalIdMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean clientSecretMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getClientSecret() == null;
- if (check == false) {
+ if (!check) {
Log.warn("client_secret must be null.");
}
return check;
@@ -113,7 +113,7 @@ protected boolean clientSecretMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean clientSecretMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getClientSecret() != null;
- if (check == false) {
+ if (!check) {
Log.warn("client_secret must not be null.");
}
return check;
@@ -126,7 +126,7 @@ protected boolean clientSecretMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean extTokenMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getExtToken() == null;
- if (check == false) {
+ if (!check) {
Log.warn("ext_token must be null.");
}
return check;
@@ -139,7 +139,7 @@ protected boolean extTokenMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean extTokenMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getExtToken() != null;
- if (check == false) {
+ if (!check) {
Log.warn("ext_token must not be null.");
}
return check;
@@ -152,7 +152,7 @@ protected boolean extTokenMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean addDataMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getAddData() == null;
- if (check == false) {
+ if (!check) {
Log.warn("add_data must be null.");
}
return check;
@@ -165,7 +165,7 @@ protected boolean addDataMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean addDataMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getAddData() != null;
- if (check == false) {
+ if (!check) {
Log.warn("add_data must not be null.");
}
return check;
@@ -178,7 +178,7 @@ protected boolean addDataMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean refreshTokenMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getRefreshToken() == null;
- if (check == false) {
+ if (!check) {
Log.warn("refresh_token must be null.");
}
return check;
@@ -191,7 +191,7 @@ protected boolean refreshTokenMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean refreshTokenMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getRefreshToken() != null;
- if (check == false) {
+ if (!check) {
Log.warn("refresh_token must not be null.");
}
return check;
@@ -204,7 +204,7 @@ protected boolean refreshTokenMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean usernameMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getUsername() == null;
- if (check == false) {
+ if (!check) {
Log.warn("username must be null.");
}
return check;
@@ -217,7 +217,7 @@ protected boolean usernameMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean usernameMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getUsername() != null;
- if (check == false) {
+ if (!check) {
Log.warn("username must not be null.");
}
return check;
@@ -230,7 +230,7 @@ protected boolean usernameMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean passwordMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getPassword() == null;
- if (check == false) {
+ if (!check) {
Log.warn("password must be null.");
}
return check;
@@ -243,7 +243,7 @@ protected boolean passwordMustBeNull(GetAccessToken getAccessToken) {
*/
protected boolean passwordMustNotBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getPassword() != null;
- if (check == false) {
+ if (!check) {
Log.warn("password must not be null.");
}
return check;
@@ -256,7 +256,7 @@ protected boolean passwordMustNotBeNull(GetAccessToken getAccessToken) {
*/
protected boolean scopedMustBeNull(GetAccessToken getAccessToken) {
boolean check = getAccessToken.getScope() == null;
- if (check == false) {
+ if (!check) {
Log.warn("scope must be null.");
}
return check;
diff --git a/src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeyTest.java b/src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeyTest.java
deleted file mode 100644
index 81591c6c..00000000
--- a/src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeyTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * PublicKeyTest.java
- *
- * 1 giu 2023
- */
-package it.pagopa.swclient.mil.auth.bean;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-import org.junit.jupiter.api.Test;
-
-import io.quarkus.test.junit.QuarkusTest;
-
-/**
- *
- * @author Antonio Tarricone
- */
-@QuarkusTest
-class PublicKeyTest {
- /**
- *
- */
- @Test
- void equals1() {
- PublicKey publicKey = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- assertTrue(publicKey.equals(publicKey));
- }
-
- /**
- *
- */
- @Test
- void equals2() {
- PublicKey publicKey = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- assertFalse(publicKey.equals(null));
- }
-
- /**
- *
- */
- @Test
- void equals3() {
- PublicKey publicKey = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- assertFalse(publicKey.equals(new Object()));
- }
-
- /**
- *
- */
- @Test
- void equals4() {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- assertTrue(publicKey1.equals(publicKey2));
- }
-
- /**
- * @throws CloneNotSupportedException
- */
- @Test
- void equals5() throws CloneNotSupportedException {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = (PublicKey) publicKey1.clone();
- publicKey2.setE("");
- assertFalse(publicKey1.equals(publicKey2));
- }
-
- /**
- * @throws CloneNotSupportedException
- */
- @Test
- void equals6() throws CloneNotSupportedException {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = (PublicKey) publicKey1.clone();
- publicKey2.setExp(1);
- assertFalse(publicKey1.equals(publicKey2));
- }
-
- /**
- * @throws CloneNotSupportedException
- */
- @Test
- void equals7() throws CloneNotSupportedException {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = (PublicKey) publicKey1.clone();
- publicKey2.setIat(1);
- assertFalse(publicKey1.equals(publicKey2));
- }
-
- /**
- * @throws CloneNotSupportedException
- */
- @Test
- void equals8() throws CloneNotSupportedException {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = (PublicKey) publicKey1.clone();
- publicKey2.setKid("");
- assertFalse(publicKey1.equals(publicKey2));
- }
-
- /**
- * @throws CloneNotSupportedException
- */
- @Test
- void equals9() throws CloneNotSupportedException {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = (PublicKey) publicKey1.clone();
- publicKey2.setKty(null);
- assertFalse(publicKey1.equals(publicKey2));
- }
-
- /**
- * @throws CloneNotSupportedException
- */
- @Test
- void equals10() throws CloneNotSupportedException {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = (PublicKey) publicKey1.clone();
- publicKey2.setN("");
- assertFalse(publicKey1.equals(publicKey2));
- }
-
- /**
- * @throws CloneNotSupportedException
- */
- @Test
- void equals11() throws CloneNotSupportedException {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKey publicKey2 = (PublicKey) publicKey1.clone();
- publicKey2.setUse(null);
- assertFalse(publicKey1.equals(publicKey2));
- }
-}
\ No newline at end of file
diff --git a/src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeysTest.java b/src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeysTest.java
deleted file mode 100644
index f5bad738..00000000
--- a/src/test/java/it/pagopa/swclient/mil/auth/bean/PublicKeysTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * PublicKeysTest.java
- *
- * 1 giu 2023
- */
-package it.pagopa.swclient.mil.auth.bean;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.util.List;
-
-import org.junit.jupiter.api.Test;
-
-import io.quarkus.test.junit.QuarkusTest;
-
-/**
- *
- * @author Antonio Tarricone
- */
-@QuarkusTest
-class PublicKeysTest {
- /**
- *
- */
- @Test
- void equals1() {
- PublicKey publicKey = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKeys publicKeys = new PublicKeys(List.of(publicKey));
- assertTrue(publicKeys.equals(publicKeys));
- }
-
- /**
- *
- */
- @Test
- void equals2() {
- PublicKey publicKey = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKeys publicKeys = new PublicKeys(List.of(publicKey));
- assertFalse(publicKeys.equals(null));
- }
-
- /**
- *
- */
- @Test
- void equals3() {
- PublicKey publicKey = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKeys publicKeys = new PublicKeys(List.of(publicKey));
- assertFalse(publicKeys.equals(new Object()));
- }
-
- /**
- *
- */
- @Test
- void equals4() {
- PublicKey publicKey1 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKeys publicKeys1 = new PublicKeys(List.of(publicKey1));
- PublicKey publicKey2 = new PublicKey("1", KeyUse.sig, "2", "3", KeyType.RSA, 0, 0);
- PublicKeys publicKeys2 = new PublicKeys(List.of(publicKey2));
- assertTrue(publicKeys1.equals(publicKeys2));
- }
-}
\ No newline at end of file
diff --git a/src/test/java/it/pagopa/swclient/mil/auth/resource/JwksResourceTest.java b/src/test/java/it/pagopa/swclient/mil/auth/resource/JwksResourceTest.java
index 3032d872..7233d913 100644
--- a/src/test/java/it/pagopa/swclient/mil/auth/resource/JwksResourceTest.java
+++ b/src/test/java/it/pagopa/swclient/mil/auth/resource/JwksResourceTest.java
@@ -37,7 +37,7 @@
@QuarkusTest
@TestHTTPEndpoint(JwksResource.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-public class JwksResourceTest {
+class JwksResourceTest {
/*
*
*/
diff --git a/src/test/java/it/pagopa/swclient/mil/auth/resource/TokenResourceTest.java b/src/test/java/it/pagopa/swclient/mil/auth/resource/TokenResourceTest.java
index 8b43e498..fbea364b 100644
--- a/src/test/java/it/pagopa/swclient/mil/auth/resource/TokenResourceTest.java
+++ b/src/test/java/it/pagopa/swclient/mil/auth/resource/TokenResourceTest.java
@@ -185,7 +185,7 @@ void createTokenByClientSecretForNodo() throws NoSuchAlgorithmException {
clientId,
"NA",
"NA"))
- .thenReturn(item(new Role("NA", "NA", clientId, "NA", "NA", List.of(RoleEnum.Nodo.name()))));
+ .thenReturn(item(new Role("NA", "NA", clientId, "NA", "NA", List.of(RoleEnum.NODO.toString()))));
/*
* Test
@@ -508,7 +508,7 @@ void createTokenByPasswordWithErrorSearchingCredentials() throws NoSuchAlgorithm
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
/*
* Test
@@ -726,7 +726,7 @@ void createTokenByPoyntTokenWithErrorVerifingToken1() {
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
/*
* Test
@@ -774,7 +774,7 @@ void createTokenByPoyntTokenWithErrorVerifingToken2() {
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
/*
* Test
@@ -822,7 +822,7 @@ void createTokenByPoyntTokenWithErrorVerifingToken3() {
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
/*
* Test
@@ -870,7 +870,7 @@ void createTokenByPoyntTokenWithErrorVerifingToken4() {
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
/*
* Test
@@ -1008,7 +1008,7 @@ void refreshToken() throws JOSEException, NoSuchAlgorithmException, InvalidKeySp
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
String token = TokenGenerator.generate(acquirerId, Channel.POS, merchantId, clientId, terminalId, 24 * 60 * 60 * 1000, null, List.of("offline_access"), keyPair);
@@ -1605,7 +1605,7 @@ private void setupForCreateTokenByClientSecret() throws NoSuchAlgorithmException
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
Mockito
.when(authDataRepository.getRoles(
@@ -1645,7 +1645,7 @@ private void setupForCreateTokenByPassword() throws NoSuchAlgorithmException {
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
}
/**
@@ -1676,6 +1676,15 @@ private void setupForCreateTokenByPoyntToken() {
clientId,
merchantId,
"NA"))
- .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, merchantId, "NA", List.of(RoleEnum.NoticePayer.name(), RoleEnum.SlavePos.name()))));
+ .thenReturn(Uni.createFrom().failure(new WebApplicationException(404)));
+
+ Mockito
+ .when(authDataRepository.getRoles(
+ acquirerId,
+ Channel.POS,
+ clientId,
+ "NA",
+ "NA"))
+ .thenReturn(item(new Role(acquirerId, Channel.POS, clientId, "NA", "NA", List.of(RoleEnum.NOTICE_PAYER.toString(), RoleEnum.SLAVE_POS.toString()))));
}
}
\ No newline at end of file
diff --git a/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderTest.java b/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderTest.java
index 6a3eda06..114c5d2d 100644
--- a/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderTest.java
+++ b/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderTest.java
@@ -33,7 +33,7 @@
* @author Antonio Tarricone
*/
@QuarkusTest
-public class KeyFinderTest {
+class KeyFinderTest {
/*
*
*/
diff --git a/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderWithExceptionTest.java b/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderWithExceptionTest.java
index 417dd11d..53602ea2 100644
--- a/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderWithExceptionTest.java
+++ b/src/test/java/it/pagopa/swclient/mil/auth/service/KeyFinderWithExceptionTest.java
@@ -28,7 +28,7 @@
* @author Antonio Tarricone
*/
@QuarkusTest
-public class KeyFinderWithExceptionTest {
+class KeyFinderWithExceptionTest {
/*
*
*/