-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
P4ADEV-788 applied requested changes
- Loading branch information
Showing
21 changed files
with
342 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 29 additions & 2 deletions
31
src/main/java/it/gov/pagopa/payhub/auth/service/a2a/legacy/A2AClientLegacyPropConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,41 @@ | ||
package it.gov.pagopa.payhub.auth.service.a2a.legacy; | ||
|
||
import it.gov.pagopa.payhub.auth.exception.custom.InvalidTokenException; | ||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.security.KeyFactory; | ||
import java.security.PublicKey; | ||
import java.security.spec.X509EncodedKeySpec; | ||
import java.util.Base64; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
@ConfigurationProperties(prefix = "m2m.legacy.public") | ||
@ConfigurationProperties(prefix = "m2m.legacy") | ||
@Data | ||
public class A2AClientLegacyPropConfig { | ||
private Map<String, String> secrets; | ||
private Map<String, String> publicKeys; | ||
|
||
public Map<String, PublicKey> getPublicKeysAsMap() { | ||
return Optional.ofNullable(publicKeys) | ||
.orElse(Map.of()) | ||
.entrySet().stream() | ||
.collect(Collectors.toUnmodifiableMap( | ||
Map.Entry::getKey, | ||
entry -> getPublicKeyFromString(entry.getKey(), entry.getValue()) | ||
)); | ||
} | ||
|
||
private PublicKey getPublicKeyFromString(String keyName, String encodedKey) { | ||
try { | ||
X509EncodedKeySpec publicKeyX509 = new X509EncodedKeySpec(Base64.getDecoder().decode(encodedKey)); | ||
KeyFactory kf = KeyFactory.getInstance("RSA"); | ||
return kf.generatePublic(publicKeyX509); | ||
} catch (Exception e){ | ||
throw new InvalidTokenException("invalid public key for: " + keyName); | ||
} | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
...n/java/it/gov/pagopa/payhub/auth/service/a2a/legacy/A2ALegacySecretsRetrieverService.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/main/java/it/gov/pagopa/payhub/auth/service/a2a/legacy/A2ALegacySecretsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package it.gov.pagopa.payhub.auth.service.a2a.legacy; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.security.PublicKey; | ||
import java.util.Map; | ||
|
||
@Service | ||
@Slf4j | ||
public class A2ALegacySecretsService { | ||
private final A2AClientLegacyPropConfig a2AClientLegacyPropConfig; | ||
|
||
public A2ALegacySecretsService(A2AClientLegacyPropConfig a2AClientLegacyPropConfig) { | ||
this.a2AClientLegacyPropConfig = a2AClientLegacyPropConfig; | ||
} | ||
|
||
public Map<String, PublicKey> getLegacySecrets() { | ||
return a2AClientLegacyPropConfig.getPublicKeysAsMap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.