test with key generation
This commit is contained in:
parent
03ad7c5cf4
commit
c297f338f7
@ -17,6 +17,7 @@ import cz.trask.migration.model.v32.ApplicationDetail.KeyManagerApp;
|
||||
import cz.trask.migration.model.v45.ApplicationCreateRequest;
|
||||
import cz.trask.migration.model.v45.ApplicationCreateResponse;
|
||||
import cz.trask.migration.model.v45.ApplicationKeyMappingRequest45;
|
||||
import cz.trask.migration.model.v45.ApplicationKeyMappingResponse45;
|
||||
import cz.trask.migration.model.v45.ApplicationListResponse45;
|
||||
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
|
||||
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
|
||||
@ -160,6 +161,15 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
byte[] kmData = mapper.writeValueAsBytes(keyMappingRequest);
|
||||
publishApplicationKeyMappingToWso2(createdApp.getApplicationId(), kmData,
|
||||
tokenResponse);
|
||||
|
||||
ApplicationKeyMappingResponse45 appKeys = generateKeysForApplication(createdApp.getApplicationId(), keyType, keyManager);
|
||||
|
||||
if (appKeys != null && appKeys.getKeyMappingId() != null) {
|
||||
byte[] kmData2 = mapper.writeValueAsBytes(keyMappingRequest);
|
||||
publishApplicationKeyMappingToWso2(createdApp.getApplicationId(), kmData2,
|
||||
tokenResponse);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,6 +187,37 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicationKeyMappingResponse45 generateKeysForApplication(String applicationId, String keyType, String keyManager) {
|
||||
try {
|
||||
String endpoint = config.getTarget().getDevPortalApiUrl() + "/v3/applications/" + applicationId
|
||||
+ "/generate-keys";
|
||||
|
||||
Map<String, String> httpHeaders = createBearerAuthHeaders(
|
||||
authenticateToWso2AndGetToken(config.getTarget()));
|
||||
httpHeaders.put("Content-Type", "application/json");
|
||||
|
||||
Map<String, Object> keyGenRequest = new HashMap<>();
|
||||
keyGenRequest.put("keyType", keyType);
|
||||
keyGenRequest.put("keyManager", keyManager);
|
||||
keyGenRequest.put("grantTypesToBeSupported", List.of("client_credentials","password"));
|
||||
|
||||
byte[] requestData = mapper.writeValueAsBytes(keyGenRequest);
|
||||
|
||||
HttpResponse response = makeDataRequest(endpoint, httpHeaders, requestData);
|
||||
|
||||
if (response.getResponseCode() == 200 || response.getResponseCode() == 201) {
|
||||
log.info(" - Keys generated successfully for Application {}", applicationId);
|
||||
return mapper.readValue(response.getResponse(), ApplicationKeyMappingResponse45.class);
|
||||
} else {
|
||||
log.warn(" - Key generation for Application {} failed with response code {}", applicationId,
|
||||
response.getResponseCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("IO error while generating keys for Application {}: {}", applicationId, e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void publishApplicationKeyMappingToWso2(String applicationId, byte[] kmData, TokenResponse tokenResponse) {
|
||||
try {
|
||||
// Publish the application key mapping data to WSO2
|
||||
|
||||
@ -0,0 +1,149 @@
|
||||
package cz.trask.migration.model.v45;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ApplicationDetail45 {
|
||||
|
||||
private String type;
|
||||
private String version;
|
||||
|
||||
@JsonProperty("data")
|
||||
private Data data;
|
||||
|
||||
@lombok.Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Data {
|
||||
@JsonProperty("applicationInfo")
|
||||
private ApplicationInfo applicationInfo;
|
||||
|
||||
@JsonProperty("subscribedAPIs")
|
||||
private List<SubscribedAPI> subscribedAPIs;
|
||||
}
|
||||
|
||||
@lombok.Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class ApplicationInfo {
|
||||
@JsonProperty("applicationId")
|
||||
private String applicationId;
|
||||
|
||||
private String name;
|
||||
|
||||
@JsonProperty("throttlingPolicy")
|
||||
private String throttlingPolicy;
|
||||
|
||||
private String description;
|
||||
|
||||
@JsonProperty("tokenType")
|
||||
private String tokenType;
|
||||
|
||||
private String status;
|
||||
|
||||
private List<?> groups;
|
||||
|
||||
private List<Key> keys;
|
||||
|
||||
private Map<String, Object> attributes;
|
||||
|
||||
private Integer subscriptionCount;
|
||||
|
||||
@JsonProperty("subscriptionScopes")
|
||||
private List<?> subscriptionScopes;
|
||||
|
||||
private String owner;
|
||||
|
||||
@JsonProperty("createdTime")
|
||||
private String createdTime;
|
||||
|
||||
@JsonProperty("updatedTime")
|
||||
private String updatedTime;
|
||||
|
||||
private String visibility;
|
||||
}
|
||||
|
||||
@lombok.Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Key {
|
||||
@JsonProperty("keyMappingId")
|
||||
private String keyMappingId;
|
||||
|
||||
@JsonProperty("keyManager")
|
||||
private String keyManager;
|
||||
|
||||
@JsonProperty("consumerKey")
|
||||
private String consumerKey;
|
||||
|
||||
@JsonProperty("consumerSecret")
|
||||
private String consumerSecret;
|
||||
|
||||
@JsonProperty("supportedGrantTypes")
|
||||
private List<String> supportedGrantTypes;
|
||||
|
||||
@JsonProperty("callbackUrl")
|
||||
private String callbackUrl;
|
||||
|
||||
@JsonProperty("keyState")
|
||||
private String keyState;
|
||||
|
||||
@JsonProperty("keyType")
|
||||
private String keyType;
|
||||
|
||||
private String mode;
|
||||
|
||||
private Token token;
|
||||
|
||||
@JsonProperty("additionalProperties")
|
||||
private Map<String, Object> additionalProperties;
|
||||
}
|
||||
|
||||
@lombok.Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Token {
|
||||
private List<?> tokenScopes;
|
||||
|
||||
@JsonProperty("validityTime")
|
||||
private Integer validityTime;
|
||||
}
|
||||
|
||||
@lombok.Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class SubscribedAPI {
|
||||
@JsonProperty("apiId")
|
||||
private ApiId apiId;
|
||||
|
||||
@JsonProperty("subscriber")
|
||||
private Subscriber subscriber;
|
||||
|
||||
@JsonProperty("throttlingPolicy")
|
||||
private String throttlingPolicy;
|
||||
}
|
||||
|
||||
@lombok.Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class ApiId {
|
||||
@JsonProperty("providerName")
|
||||
private String providerName;
|
||||
|
||||
@JsonProperty("apiName")
|
||||
private String apiName;
|
||||
|
||||
private String version;
|
||||
private String uuid;
|
||||
private Integer id;
|
||||
}
|
||||
|
||||
@lombok.Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Subscriber {
|
||||
private String name;
|
||||
private Integer id;
|
||||
private Integer tenantId;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user