Skip to content

Commit

Permalink
update export certs flows
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJaI committed Jul 2, 2024
1 parent bb88304 commit 2af756b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ public class GatewayAPIDTO implements Serializable {
private String[] sequencesToBeRemove;
private GatewayContentDTO[] localEntriesToBeAdd;
private String[] localEntriesToBeRemove;
private GatewayContentDTO[] productionClientCertificatesToBeAdd;
private GatewayContentDTO[] sandboxClientCertificatesToBeAdd;
private String[] productionClientCertificatesToBeRemove;
private String[] sandboxClientCertificatesToBeRemove;
private GatewayContentDTO[] clientCertificatesToBeAdd;
private String[] clientCertificatesToBeRemove;
private GatewayContentDTO[] endpointEntriesToBeAdd;
private String[] endpointEntriesToBeRemove;
private CredentialDto[] credentialsToBeAdd ;
Expand Down Expand Up @@ -153,36 +151,20 @@ public void setLocalEntriesToBeRemove(String[] localEntriesToBeRemove) {
this.localEntriesToBeRemove = localEntriesToBeRemove;
}

public GatewayContentDTO[] getProductionClientCertificatesToBeAdd() {
return productionClientCertificatesToBeAdd;
public GatewayContentDTO[] getClientCertificatesToBeAdd() {
return clientCertificatesToBeAdd;
}

public void setProductionClientCertificatesToBeAdd(GatewayContentDTO[] productionClientCertificatesToBeAdd) {
this.productionClientCertificatesToBeAdd = productionClientCertificatesToBeAdd;
public void setClientCertificatesToBeAdd(GatewayContentDTO[] clientCertificatesToBeAdd) {
this.clientCertificatesToBeAdd = clientCertificatesToBeAdd;
}

public GatewayContentDTO[] getSandboxClientCertificatesToBeAdd() {
return sandboxClientCertificatesToBeAdd;
public String[] getClientCertificatesToBeRemove() {
return clientCertificatesToBeRemove;
}

public void setSandboxClientCertificatesToBeAdd(GatewayContentDTO[] sandboxClientCertificatesToBeAdd) {
this.sandboxClientCertificatesToBeAdd = sandboxClientCertificatesToBeAdd;
}

public String[] getProductionClientCertificatesToBeRemove() {
return productionClientCertificatesToBeRemove;
}

public void setProductionClientCertificatesToBeRemove(String[] productionClientCertificatesToBeRemove) {
this.productionClientCertificatesToBeRemove = productionClientCertificatesToBeRemove;
}

public String[] getSandboxClientCertificatesToBeRemove() {
return sandboxClientCertificatesToBeRemove;
}

public void setSandboxClientCertificatesToBeRemove(String[] sandboxClientCertificatesToBeRemove) {
this.sandboxClientCertificatesToBeRemove = sandboxClientCertificatesToBeRemove;
public void setClientCertificatesToBeRemove(String[] clientCertificatesToBeRemove) {
this.clientCertificatesToBeRemove = clientCertificatesToBeRemove;
}

public GatewayContentDTO[] getEndpointEntriesToBeAdd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ private void unDeployAPI(APIGatewayAdmin apiGatewayAdmin, DeployAPIInGatewayEven
GatewayUtils
.addStringToList(gatewayEvent.getUuid(), gatewayAPIDTO.getLocalEntriesToBeRemove()));
apiGatewayAdmin.unDeployAPI(gatewayAPIDTO);
DataHolder.getInstance().getApiToProductionCertificatesMap().remove(gatewayEvent.getUuid());
DataHolder.getInstance().getApiToSandboxCertificatesMap().remove(gatewayEvent.getUuid());
DataHolder.getInstance().getApiToCertificatesMap().remove(gatewayEvent.getUuid());

DataHolder.getInstance().removeKeyManagerToAPIMapping(gatewayAPIDTO.getApiId());
}
Expand Down Expand Up @@ -421,21 +420,13 @@ private void addDeployedCertificatesToAPIAssociation(GatewayAPIDTO gatewayAPIDTO

if (gatewayAPIDTO != null) {
String apiId = gatewayAPIDTO.getApiId();
List<String> productionAliasList = new ArrayList<>();
if (gatewayAPIDTO.getProductionClientCertificatesToBeAdd() != null) {
for (GatewayContentDTO gatewayContentDTO : gatewayAPIDTO.getProductionClientCertificatesToBeAdd()) {
productionAliasList.add(gatewayContentDTO.getName());
List<String> aliasList = new ArrayList<>();
if (gatewayAPIDTO.getClientCertificatesToBeAdd() != null) {
for (GatewayContentDTO gatewayContentDTO : gatewayAPIDTO.getClientCertificatesToBeAdd()) {
aliasList.add(gatewayContentDTO.getName());
}
}
DataHolder.getInstance().addApiToProductionAliasList(apiId, productionAliasList);

List<String> sandboxAliasList = new ArrayList<>();
if (gatewayAPIDTO.getSandboxClientCertificatesToBeAdd() != null) {
for (GatewayContentDTO gatewayContentDTO : gatewayAPIDTO.getSandboxClientCertificatesToBeAdd()) {
sandboxAliasList.add(gatewayContentDTO.getName());
}
}
DataHolder.getInstance().addApiToSandboxAliasList(apiId, sandboxAliasList);
DataHolder.getInstance().addApiToAliasList(apiId, aliasList);
}
}

Expand All @@ -460,14 +451,11 @@ private void setClientCertificatesToRemoveIntoGatewayDTO(GatewayAPIDTO gatewayDT

if (gatewayDTO != null) {
if (StringUtils.isNotEmpty(gatewayDTO.getApiId())) {
List<String> productionCertificateAliasListForAPI =
DataHolder.getInstance().getProductionCertificateAliasListForAPI(gatewayDTO.getApiId());
gatewayDTO.setProductionClientCertificatesToBeRemove(productionCertificateAliasListForAPI.toArray(new String[0]));
}
if (StringUtils.isNotEmpty(gatewayDTO.getApiId())) {
List<String> sandboxCertificateAliasListForAPI =
DataHolder.getInstance().getSandboxCertificateAliasListForAPI(gatewayDTO.getApiId());
gatewayDTO.setSandboxClientCertificatesToBeRemove(sandboxCertificateAliasListForAPI.toArray(new String[0]));
List<String> certificateAliasListForAPI =
DataHolder.getInstance().getCertificateAliasListForAPI(gatewayDTO.getApiId());
certificateAliasListForAPI.addAll(certificateAliasListForAPI);
gatewayDTO.setClientCertificatesToBeRemove(certificateAliasListForAPI.toArray(new String[0]));

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
public class DataHolder {
private static final Log log = LogFactory.getLog(DataHolder.class);
private static final DataHolder Instance = new DataHolder();
private Map<String, List<String>> apiToProductionCertificatesMap = new HashMap();
private Map<String, List<String>> apiToSandboxCertificatesMap = new HashMap();
private Map<String, List<String>> apiToCertificatesMap = new HashMap();
private Map<String, String> googleAnalyticsConfigMap = new HashMap<>();
private Map<String, GraphQLSchemaDTO> apiToGraphQLSchemaDTOMap = new HashMap<>();
private Map<String, List<String>> apiToKeyManagersMap = new HashMap<>();
Expand All @@ -52,42 +51,24 @@ private DataHolder() {
initializeTenantDeploymentStatusMap();
}

public Map<String, List<String>> getApiToProductionCertificatesMap() {
return apiToProductionCertificatesMap;
}

public void setApiToProductionCertificatesMap(Map<String, List<String>> apiToProductionCertificatesMap) {
this.apiToProductionCertificatesMap = apiToProductionCertificatesMap;
}

public Map<String, List<String>> getApiToSandboxCertificatesMap() {
return apiToSandboxCertificatesMap;
}

public void setApiToSandboxCertificatesMap(Map<String, List<String>> apiToSandboxCertificatesMap) {
this.apiToSandboxCertificatesMap = apiToSandboxCertificatesMap;
}

public static DataHolder getInstance() {

return Instance;
}
public void addApiToProductionAliasList(String apiId, List<String> aliasList) {

apiToProductionCertificatesMap.put(apiId, aliasList);
public void addApiToAliasList(String apiId, List<String> aliasList) {
apiToCertificatesMap.put(apiId, aliasList);
}
public void addApiToSandboxAliasList(String apiId, List<String> aliasList) {

apiToSandboxCertificatesMap.put(apiId, aliasList);
public List<String> getCertificateAliasListForAPI(String apiId) {
return apiToCertificatesMap.getOrDefault(apiId, Collections.emptyList());
}

public List<String> getProductionCertificateAliasListForAPI(String apiId) {

return apiToProductionCertificatesMap.getOrDefault(apiId, Collections.emptyList());
public Map<String, List<String>> getApiToCertificatesMap() {
return apiToCertificatesMap;
}
public List<String> getSandboxCertificateAliasListForAPI(String apiId) {

return apiToSandboxCertificatesMap.getOrDefault(apiId, Collections.emptyList());
public void setApiToCertificatesMap(Map<String, List<String>> apiToCertificatesMap) {
this.apiToCertificatesMap = apiToCertificatesMap;
}

public void addGoogleAnalyticsConfig(String tenantDomain, String config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,20 +708,14 @@ public boolean deployAPI(GatewayAPIDTO gatewayAPIDTO) throws AxisFault {
}

// Add Client Certificates
if (gatewayAPIDTO.getProductionClientCertificatesToBeAdd() != null) {
if (gatewayAPIDTO.getClientCertificatesToBeAdd() != null) {
synchronized (certificateManager) {
for (GatewayContentDTO certificate : gatewayAPIDTO.getProductionClientCertificatesToBeAdd()) {
certificateManager.addClientCertificateToGateway(certificate.getContent(), certificate.getName());
}
}
}
if (gatewayAPIDTO.getSandboxClientCertificatesToBeAdd() != null) {
synchronized (certificateManager) {
for (GatewayContentDTO certificate : gatewayAPIDTO.getSandboxClientCertificatesToBeAdd()) {
for (GatewayContentDTO certificate : gatewayAPIDTO.getClientCertificatesToBeAdd()) {
certificateManager.addClientCertificateToGateway(certificate.getContent(), certificate.getName());
}
}
}

if (log.isDebugEnabled()) {
log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " client certificates deployed");
log.debug("Start to add vault entries " + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
Expand Down Expand Up @@ -859,20 +853,14 @@ private void unDeployAPI(SequenceAdminServiceProxy sequenceAdminServiceProxy,
}

// Remove clientCertificates
if (gatewayAPIDTO.getProductionClientCertificatesToBeRemove() != null) {
if (gatewayAPIDTO.getClientCertificatesToBeRemove() != null) {
synchronized (certificateManager) {
for (String alias : gatewayAPIDTO.getProductionClientCertificatesToBeRemove()) {
certificateManager.deleteClientCertificateFromGateway(alias);
}
}
}
if (gatewayAPIDTO.getSandboxClientCertificatesToBeRemove() != null) {
synchronized (certificateManager) {
for (String alias : gatewayAPIDTO.getSandboxClientCertificatesToBeRemove()) {
for (String alias : gatewayAPIDTO.getClientCertificatesToBeRemove()) {
certificateManager.deleteClientCertificateFromGateway(alias);
}
}
}

if (log.isDebugEnabled()) {
log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " client certificates undeployed " +
"successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,8 @@
"type" : "string",
"example" : "EXCHANGED",
"description" : "The type of the tokens to be used (exchanged or without exchanged). Accepted values are EXCHANGED, DIRECT or BOTH.",
"enum" : [ "EXCHANGED", "DIRECT", "BOTH" ],
"default" : "DIRECT"
"default" : "DIRECT",
"enum" : [ "EXCHANGED", "DIRECT", "BOTH" ]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ CREATE TABLE IF NOT EXISTS `AM_API_CLIENT_CERTIFICATE` (
`TIER_NAME` VARCHAR (512),
`KEY_TYPE` VARCHAR(20) NOT NULL DEFAULT 'PRODUCTION',
FOREIGN KEY (API_ID) REFERENCES AM_API (API_ID) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`ALIAS`,`TENANT_ID`, `REMOVED`)
PRIMARY KEY (`ALIAS`,`TENANT_ID`, `KEY_TYPE`, `REMOVED`)
);

CREATE TABLE IF NOT EXISTS AM_APPLICATION_GROUP_MAPPING (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,8 @@ private static void setClientCertificatesToBeAdded(String tenantDomain, GatewayA
clientCertificate.setName(APIConstants.API_KEY_TYPE_PRODUCTION + "_" + clientCertificateDTO.getAlias()
+ "_" + tenantId);
clientCertificate.setContent(clientCertificateDTO.getCertificate());
gatewayAPIDTO.setProductionClientCertificatesToBeAdd(addGatewayContentToList(clientCertificate,
gatewayAPIDTO.getProductionClientCertificatesToBeAdd()));
gatewayAPIDTO.setClientCertificatesToBeAdd(addGatewayContentToList(clientCertificate,
gatewayAPIDTO.getClientCertificatesToBeAdd()));
}
}
if (sandboxClientCertificatesDTOList != null) {
Expand All @@ -954,8 +954,8 @@ private static void setClientCertificatesToBeAdded(String tenantDomain, GatewayA
clientCertificate.setName(APIConstants.API_KEY_TYPE_SANDBOX + "_" + clientCertificateDTO.getAlias()
+ "_" + tenantId);
clientCertificate.setContent(clientCertificateDTO.getCertificate());
gatewayAPIDTO.setSandboxClientCertificatesToBeAdd(addGatewayContentToList(clientCertificate,
gatewayAPIDTO.getSandboxClientCertificatesToBeAdd()));
gatewayAPIDTO.setClientCertificatesToBeAdd(addGatewayContentToList(clientCertificate,
gatewayAPIDTO.getClientCertificatesToBeAdd()));
}
}
}
Expand Down

0 comments on commit 2af756b

Please sign in to comment.