decode APIM3.2 credentials - clientSecret

This commit is contained in:
Radek Davidek 2025-10-21 16:48:27 +02:00
parent a3ebd99fb6
commit 5b5ce421d5
2 changed files with 35 additions and 23 deletions

View File

@ -14,6 +14,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import cz.trask.migration.model.ApiDefinition32;
import cz.trask.migration.model.ApiDefinition45;
import cz.trask.migration.model.ApiDefinition45.ApiPolicies;
import cz.trask.migration.util.CredentialsDecoder;
public class ApiDefinitionMapper {
@ -216,7 +217,7 @@ public class ApiDefinitionMapper {
newSec.setType(oldSec.getType());
newSec.setTokenUrl(oldSec.getTokenUrl());
newSec.setClientId(oldSec.getClientId());
newSec.setClientSecret(oldSec.getClientSecret());
newSec.setClientSecret(CredentialsDecoder.decodeCredentials(oldSec.getClientSecret(), "wso2apim32-pk.pem"));
newSec.setUsername(oldSec.getUsername());
newSec.setPassword(oldSec.getPassword());
newSec.setGrantType(oldSec.getGrantType());

View File

@ -17,7 +17,12 @@ import lombok.extern.log4j.Log4j2;
@Log4j2
public class CredentialsDecoder {
public static void decodeCredentials(String credentials, String pkFile) throws Exception {
public static String decodeCredentials(String credentials, String pkFile) {
if (credentials == null || credentials.isEmpty()) {
log.warn("No credentials provided to decode.");
return null;
}
try {
String decodedJson = new String(Base64.getDecoder().decode(credentials));
log.debug("Decoded JSON: {}", decodedJson);
@ -45,5 +50,11 @@ public class CredentialsDecoder {
String decryptedText = new String(decryptedBytes, "UTF-8");
log.debug("Decoded credential: {}", decryptedText);
return decryptedText;
} catch (Exception e) {
log.error("Error decoding credentials: ", e);
return null;
}
}
}