Skip to content

Commit ec377f8

Browse files
committed
refactored code to make it past impsort-maven-plugin build error
1 parent 504749a commit ec377f8

File tree

1 file changed

+29
-26
lines changed
  • dsf-common/dsf-common-oidc/src/main/java/dev/dsf/common/oidc

1 file changed

+29
-26
lines changed

dsf-common/dsf-common-oidc/src/main/java/dev/dsf/common/oidc/Jwks.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,39 +66,42 @@ public Algorithm toAlgorithm() throws JwksException
6666
{
6767
return switch (kty)
6868
{
69-
case "RSA" -> {
69+
case "RSA" -> toRsaAlgorithm();
70+
case "EC" -> toEcdsaAlgorithm();
7071

71-
RSAPublicKey key = toRsaPublicKey(n, e);
72-
RSAKeyProvider keyProvider = toRsaKeyProvider(key, kid);
73-
74-
yield switch (alg)
75-
{
76-
case "RS256" -> Algorithm.RSA256(keyProvider);
77-
case "RS384" -> Algorithm.RSA384(keyProvider);
78-
case "RS512" -> Algorithm.RSA512(keyProvider);
72+
default -> throw new JwksException("JWKS kty property value '" + kty + "' not one of 'RSA' or 'EC'");
73+
};
74+
}
7975

80-
default -> throw new JwksException(
81-
"JWKS alg property value '" + alg + "' not one of 'RSA256', 'RSA384' or 'RSA512'");
82-
};
83-
}
76+
private Algorithm toRsaAlgorithm()
77+
{
78+
RSAPublicKey key = toRsaPublicKey(n, e);
79+
RSAKeyProvider keyProvider = toRsaKeyProvider(key, kid);
8480

85-
case "EC" -> {
81+
return switch (alg)
82+
{
83+
case "RS256" -> Algorithm.RSA256(keyProvider);
84+
case "RS384" -> Algorithm.RSA384(keyProvider);
85+
case "RS512" -> Algorithm.RSA512(keyProvider);
8686

87-
ECPublicKey key = toEcPublicKey(x, y, crv);
88-
ECDSAKeyProvider keyProvider = toEcKeyProvider(key, kid);
87+
default -> throw new JwksException(
88+
"JWKS alg property value '" + alg + "' not one of 'RSA256', 'RSA384' or 'RSA512'");
89+
};
90+
}
8991

90-
yield switch (alg)
91-
{
92-
case "ES256" -> Algorithm.ECDSA256(keyProvider);
93-
case "ES384" -> Algorithm.ECDSA384(keyProvider);
94-
case "ES512" -> Algorithm.ECDSA512(keyProvider);
92+
private Algorithm toEcdsaAlgorithm()
93+
{
94+
ECPublicKey key = toEcPublicKey(x, y, crv);
95+
ECDSAKeyProvider keyProvider = toEcKeyProvider(key, kid);
9596

96-
default -> throw new JwksException(
97-
"JWKS crv property value '" + alg + "' not one of 'ES256', 'ES384' or 'ES512'");
98-
};
99-
}
97+
return switch (alg)
98+
{
99+
case "ES256" -> Algorithm.ECDSA256(keyProvider);
100+
case "ES384" -> Algorithm.ECDSA384(keyProvider);
101+
case "ES512" -> Algorithm.ECDSA512(keyProvider);
100102

101-
default -> throw new JwksException("JWKS kty property value '" + kty + "' not one of 'RSA' or 'EC'");
103+
default -> throw new JwksException(
104+
"JWKS crv property value '" + alg + "' not one of 'ES256', 'ES384' or 'ES512'");
102105
};
103106
}
104107

0 commit comments

Comments
 (0)