diff --git a/distro/data/src/main/resources/ddls/apiman-gateway_h2.ddl b/distro/data/src/main/resources/ddls/apiman-gateway_h2.ddl
index da31b48231..a39dce30ff 100644
--- a/distro/data/src/main/resources/ddls/apiman-gateway_h2.ddl
+++ b/distro/data/src/main/resources/ddls/apiman-gateway_h2.ddl
@@ -2,12 +2,9 @@
CREATE TABLE apis (org_id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, bean CLOB NOT NULL);
ALTER TABLE apis ADD PRIMARY KEY (org_id, id, version);
-CREATE TABLE clients (org_id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, bean CLOB NOT NULL);
-ALTER TABLE clients ADD PRIMARY KEY (org_id, id, version);
-
-CREATE TABLE contracts (api_key VARCHAR(255) NOT NULL, client_org_id VARCHAR(255) NOT NULL, client_id VARCHAR(255) NOT NULL, client_version VARCHAR(255) NOT NULL, bean CLOB NOT NULL);
-ALTER TABLE contracts ADD PRIMARY KEY (api_key);
-ALTER TABLE contracts ADD CONSTRAINT FK_contracts_1 FOREIGN KEY (client_org_id, client_id, client_version) REFERENCES clients (org_id, id, version);
-CREATE INDEX IDX_contracts_1 ON contracts(client_org_id, client_id, client_version);
+CREATE TABLE clients (api_key VARCHAR(255) NOT NULL, org_id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, bean CLOB NOT NULL);
+ALTER TABLE clients ADD PRIMARY KEY (api_key);
+ALTER TABLE clients ADD CONSTRAINT UK_clients_1 UNIQUE (org_id, id, version);
+CREATE INDEX IDX_clients_1 ON clients(org_id, id, version);
CREATE TABLE dataversion (version BIGINT NOT NULL);
diff --git a/distro/data/src/main/resources/ddls/apiman-gateway_mysql5.ddl b/distro/data/src/main/resources/ddls/apiman-gateway_mysql5.ddl
index 7240297605..e3b5f69e5e 100644
--- a/distro/data/src/main/resources/ddls/apiman-gateway_mysql5.ddl
+++ b/distro/data/src/main/resources/ddls/apiman-gateway_mysql5.ddl
@@ -3,11 +3,8 @@ CREATE TABLE apis (org_id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL, versi
ALTER TABLE apis ADD PRIMARY KEY (org_id, id, version);
CREATE TABLE clients (org_id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, bean LONGTEXT NOT NULL);
-ALTER TABLE clients ADD PRIMARY KEY (org_id, id, version);
-
-CREATE TABLE contracts (api_key VARCHAR(255) NOT NULL, client_org_id VARCHAR(255) NOT NULL, client_id VARCHAR(255) NOT NULL, client_version VARCHAR(255) NOT NULL, bean LONGTEXT NOT NULL);
-ALTER TABLE contracts ADD PRIMARY KEY (api_key);
-ALTER TABLE contracts ADD CONSTRAINT FK_contracts_1 FOREIGN KEY (client_org_id, client_id, client_version) REFERENCES clients (org_id, id, version);
-CREATE INDEX IDX_contracts_1 ON contracts(client_org_id, client_id, client_version);
+ALTER TABLE clients ADD PRIMARY KEY (api_key);
+ALTER TABLE clients ADD CONSTRAINT UK_clients_1 UNIQUE (org_id, id, version);
+CREATE INDEX IDX_clients_1 ON clients(org_id, id, version);
CREATE TABLE dataversion (version BIGINT NOT NULL);
diff --git a/distro/data/src/main/resources/ddls/apiman-gateway_oracle12.ddl b/distro/data/src/main/resources/ddls/apiman-gateway_oracle12.ddl
index 7b07475600..a7c0b18075 100644
--- a/distro/data/src/main/resources/ddls/apiman-gateway_oracle12.ddl
+++ b/distro/data/src/main/resources/ddls/apiman-gateway_oracle12.ddl
@@ -3,11 +3,8 @@ CREATE TABLE apis (org_id VARCHAR2(255) NOT NULL, id VARCHAR2(255) NOT NULL, ver
ALTER TABLE apis ADD PRIMARY KEY (org_id, id, version);
CREATE TABLE clients (org_id VARCHAR2(255) NOT NULL, id VARCHAR2(255) NOT NULL, version VARCHAR2(255) NOT NULL, bean CLOB NOT NULL);
-ALTER TABLE clients ADD PRIMARY KEY (org_id, id, version);
-
-CREATE TABLE contracts (api_key VARCHAR2(255) NOT NULL, client_org_id VARCHAR2(255) NOT NULL, client_id VARCHAR2(255) NOT NULL, client_version VARCHAR2(255) NOT NULL, bean CLOB NOT NULL);
-ALTER TABLE contracts ADD PRIMARY KEY (api_key);
-ALTER TABLE contracts ADD CONSTRAINT FK_contracts_1 FOREIGN KEY (client_org_id, client_id, client_version) REFERENCES clients (org_id, id, version);
-CREATE INDEX IDX_contracts_1 ON contracts(client_org_id, client_id, client_version);
+ALTER TABLE clients ADD PRIMARY KEY (api_key);
+ALTER TABLE clients ADD CONSTRAINT UK_clients_1 UNIQUE (org_id, id, version);
+CREATE INDEX IDX_clients_1 ON clients(org_id, id, version);
CREATE TABLE dataversion (version NUMBER(38, 0) NOT NULL);
diff --git a/distro/data/src/main/resources/ddls/apiman-gateway_postgresql9.ddl b/distro/data/src/main/resources/ddls/apiman-gateway_postgresql9.ddl
index 20590cb079..2685a2eccd 100644
--- a/distro/data/src/main/resources/ddls/apiman-gateway_postgresql9.ddl
+++ b/distro/data/src/main/resources/ddls/apiman-gateway_postgresql9.ddl
@@ -3,11 +3,8 @@ CREATE TABLE apis (org_id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL, versi
ALTER TABLE apis ADD PRIMARY KEY (org_id, id, version);
CREATE TABLE clients (org_id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, bean TEXT NOT NULL);
-ALTER TABLE clients ADD PRIMARY KEY (org_id, id, version);
-
-CREATE TABLE contracts (api_key VARCHAR(255) NOT NULL, client_org_id VARCHAR(255) NOT NULL, client_id VARCHAR(255) NOT NULL, client_version VARCHAR(255) NOT NULL, bean TEXT NOT NULL);
-ALTER TABLE contracts ADD PRIMARY KEY (api_key);
-ALTER TABLE contracts ADD CONSTRAINT FK_contracts_1 FOREIGN KEY (client_org_id, client_id, client_version) REFERENCES clients (org_id, id, version);
-CREATE INDEX IDX_contracts_1 ON contracts(client_org_id, client_id, client_version);
+ALTER TABLE clients ADD PRIMARY KEY (api_key);
+ALTER TABLE clients ADD CONSTRAINT UK_clients_1 UNIQUE (org_id, id, version);
+CREATE INDEX IDX_clients_1 ON clients(org_id, id, version);
CREATE TABLE dataversion (version BIGINT NOT NULL);
diff --git a/distro/data/src/main/resources/ddls/apiman_h2.ddl b/distro/data/src/main/resources/ddls/apiman_h2.ddl
index ecd99cffe6..a48a25b978 100644
--- a/distro/data/src/main/resources/ddls/apiman_h2.ddl
+++ b/distro/data/src/main/resources/ddls/apiman_h2.ddl
@@ -11,7 +11,7 @@
CREATE SEQUENCE hibernate_sequence START WITH 999;
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-1::apiman (generated)
-CREATE TABLE client_versions (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP NOT NULL, modified_by VARCHAR(255) NOT NULL, modified_on TIMESTAMP NOT NULL, published_on TIMESTAMP, retired_on TIMESTAMP, status VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, client_id VARCHAR(255), client_org_id VARCHAR(255));
+CREATE TABLE client_versions (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP NOT NULL, modified_by VARCHAR(255) NOT NULL, modified_on TIMESTAMP NOT NULL, published_on TIMESTAMP, retired_on TIMESTAMP, status VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, client_id VARCHAR(255), client_org_id VARCHAR(255), apikey VARCHAR(255) NOT NULL);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-2::apiman (generated)
CREATE TABLE clients (id VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP NOT NULL, description VARCHAR(512), name VARCHAR(255) NOT NULL, organization_id VARCHAR(255) NOT NULL);
@@ -20,7 +20,7 @@ CREATE TABLE clients (id VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL
CREATE TABLE auditlog (id BIGINT NOT NULL, created_on TIMESTAMP NOT NULL, data VARCHAR(2147483647), entity_id VARCHAR(255), entity_type VARCHAR(255) NOT NULL, entity_version VARCHAR(255), organization_id VARCHAR(255) NOT NULL, what VARCHAR(255) NOT NULL, who VARCHAR(255) NOT NULL);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-4::apiman (generated)
-CREATE TABLE contracts (id BIGINT NOT NULL, apikey VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP NOT NULL, clientv_id BIGINT, planv_id BIGINT, apiv_id BIGINT);
+CREATE TABLE contracts (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP NOT NULL, clientv_id BIGINT, planv_id BIGINT, apiv_id BIGINT);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-5::apiman (generated)
CREATE TABLE endpoint_properties (api_version_id BIGINT NOT NULL, value VARCHAR(255), name VARCHAR(255) NOT NULL);
@@ -301,6 +301,7 @@ ALTER TABLE plan_versions ADD CONSTRAINT UK_plan_versions_1 UNIQUE (plan_id, pla
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-4::apiman
ALTER TABLE client_versions ADD CONSTRAINT UK_client_versions_1 UNIQUE (client_id, client_org_id, version);
+ALTER TABLE client_versions ADD CONSTRAINT UK_client_versions_2 UNIQUE (apikey);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-5::apiman
ALTER TABLE api_versions ADD CONSTRAINT UK_api_versions_1 UNIQUE (api_id, api_org_id, version);
@@ -309,7 +310,7 @@ ALTER TABLE api_versions ADD CONSTRAINT UK_api_versions_1 UNIQUE (api_id, api_or
ALTER TABLE api_defs ADD CONSTRAINT UK_api_defs_1 UNIQUE (api_version_id);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-7::apiman
-ALTER TABLE contracts ADD CONSTRAINT UK_contracts_1 UNIQUE (clientv_id, apiv_id, planv_id);
+ALTER TABLE contracts ADD CONSTRAINT UK_contracts_1 UNIQUE (clientv_id, apiv_id);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/200-apiman-manager-api.db.indexes.changelog.xml::createIndex-1::apiman
CREATE INDEX IDX_auditlog_1 ON auditlog(who);
diff --git a/distro/data/src/main/resources/ddls/apiman_mysql5.ddl b/distro/data/src/main/resources/ddls/apiman_mysql5.ddl
index 9c195eecd0..0e91dad7fe 100644
--- a/distro/data/src/main/resources/ddls/apiman_mysql5.ddl
+++ b/distro/data/src/main/resources/ddls/apiman_mysql5.ddl
@@ -13,7 +13,7 @@ CREATE TABLE hibernate_sequence (next_val bigint(20) DEFAULT NULL) ENGINE=InnoDB
INSERT INTO hibernate_sequence VALUES (999);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-1::apiman (generated)
-CREATE TABLE client_versions (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on datetime NOT NULL, modified_by VARCHAR(255) NOT NULL, modified_on datetime NOT NULL, published_on datetime NULL, retired_on datetime NULL, status VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, client_id VARCHAR(255) NULL, client_org_id VARCHAR(255) NULL) ENGINE=InnoDB;
+CREATE TABLE client_versions (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on datetime NOT NULL, modified_by VARCHAR(255) NOT NULL, modified_on datetime NOT NULL, published_on datetime NULL, retired_on datetime NULL, status VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, client_id VARCHAR(255) NULL, client_org_id VARCHAR(255) NULL, apikey VARCHAR(255) NOT NULL) ENGINE=InnoDB;
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-2::apiman (generated)
CREATE TABLE clients (id VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL, created_on datetime NOT NULL, description VARCHAR(512) NULL, name VARCHAR(255) NOT NULL, organization_id VARCHAR(255) NOT NULL) ENGINE=InnoDB;
@@ -22,7 +22,7 @@ CREATE TABLE clients (id VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL
CREATE TABLE auditlog (id BIGINT NOT NULL, created_on datetime NOT NULL, data LONGTEXT NULL, entity_id VARCHAR(255) NULL, entity_type VARCHAR(255) NOT NULL, entity_version VARCHAR(255) NULL, organization_id VARCHAR(255) NOT NULL, what VARCHAR(255) NOT NULL, who VARCHAR(255) NOT NULL) ENGINE=InnoDB;
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-4::apiman (generated)
-CREATE TABLE contracts (id BIGINT NOT NULL, apikey VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL, created_on datetime NOT NULL, clientv_id BIGINT NULL, planv_id BIGINT NULL, apiv_id BIGINT NULL) ENGINE=InnoDB;
+CREATE TABLE contracts (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on datetime NOT NULL, clientv_id BIGINT NULL, planv_id BIGINT NULL, apiv_id BIGINT NULL) ENGINE=InnoDB;
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-5::apiman (generated)
CREATE TABLE endpoint_properties (api_version_id BIGINT NOT NULL, value VARCHAR(255) NULL, name VARCHAR(255) NOT NULL) ENGINE=InnoDB;
@@ -303,6 +303,7 @@ ALTER TABLE plan_versions ADD CONSTRAINT UK_plan_versions_1 UNIQUE (plan_id, pla
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-4::apiman
ALTER TABLE client_versions ADD CONSTRAINT UK_client_versions_1 UNIQUE (client_id, client_org_id, version);
+ALTER TABLE client_versions ADD CONSTRAINT UK_client_versions_2 UNIQUE (apikey);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-5::apiman
ALTER TABLE api_versions ADD CONSTRAINT UK_api_versions_1 UNIQUE (api_id, api_org_id, version);
@@ -311,7 +312,7 @@ ALTER TABLE api_versions ADD CONSTRAINT UK_api_versions_1 UNIQUE (api_id, api_or
ALTER TABLE api_defs ADD CONSTRAINT UK_api_defs_1 UNIQUE (api_version_id);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-7::apiman
-ALTER TABLE contracts ADD CONSTRAINT UK_contracts_1 UNIQUE (clientv_id, apiv_id, planv_id);
+ALTER TABLE contracts ADD CONSTRAINT UK_contracts_1 UNIQUE (clientv_id, apiv_id);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/200-apiman-manager-api.db.indexes.changelog.xml::createIndex-1::apiman
CREATE INDEX IDX_auditlog_1 ON auditlog(who);
diff --git a/distro/data/src/main/resources/ddls/apiman_oracle12.ddl b/distro/data/src/main/resources/ddls/apiman_oracle12.ddl
index ec119fb103..9b400df5de 100644
--- a/distro/data/src/main/resources/ddls/apiman_oracle12.ddl
+++ b/distro/data/src/main/resources/ddls/apiman_oracle12.ddl
@@ -10,7 +10,7 @@
CREATE SEQUENCE hibernate_sequence;
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-1::apiman (generated)
-CREATE TABLE client_versions (id NUMBER(38, 0) NOT NULL, created_by VARCHAR2(255) NOT NULL, created_on TIMESTAMP NOT NULL, modified_by VARCHAR2(255) NOT NULL, modified_on TIMESTAMP NOT NULL, published_on TIMESTAMP, retired_on TIMESTAMP, status VARCHAR2(255) NOT NULL, version VARCHAR2(255) NOT NULL, client_id VARCHAR2(255), client_org_id VARCHAR2(255));
+CREATE TABLE client_versions (id NUMBER(38, 0) NOT NULL, created_by VARCHAR2(255) NOT NULL, created_on TIMESTAMP NOT NULL, modified_by VARCHAR2(255) NOT NULL, modified_on TIMESTAMP NOT NULL, published_on TIMESTAMP, retired_on TIMESTAMP, status VARCHAR2(255) NOT NULL, version VARCHAR2(255) NOT NULL, client_id VARCHAR2(255), client_org_id VARCHAR2(255), apikey VARCHAR2(255) NOT NULL);
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-2::apiman (generated)
CREATE TABLE clients (id VARCHAR2(255) NOT NULL, created_by VARCHAR2(255) NOT NULL, created_on TIMESTAMP NOT NULL, description VARCHAR2(512), name VARCHAR2(255) NOT NULL, organization_id VARCHAR2(255) NOT NULL);
@@ -19,7 +19,7 @@ CREATE TABLE clients (id VARCHAR2(255) NOT NULL, created_by VARCHAR2(255) NOT NU
CREATE TABLE auditlog (id NUMBER(38, 0) NOT NULL, created_on TIMESTAMP NOT NULL, data CLOB, entity_id VARCHAR2(255), entity_type VARCHAR2(255) NOT NULL, entity_version VARCHAR2(255), organization_id VARCHAR2(255) NOT NULL, what VARCHAR2(255) NOT NULL, who VARCHAR2(255) NOT NULL);
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-4::apiman (generated)
-CREATE TABLE contracts (id NUMBER(38, 0) NOT NULL, apikey VARCHAR2(255) NOT NULL, created_by VARCHAR2(255) NOT NULL, created_on TIMESTAMP NOT NULL, clientv_id NUMBER(38, 0), planv_id NUMBER(38, 0), apiv_id NUMBER(38, 0));
+CREATE TABLE contracts (id NUMBER(38, 0) NOT NULL, created_by VARCHAR2(255) NOT NULL, created_on TIMESTAMP NOT NULL, clientv_id NUMBER(38, 0), planv_id NUMBER(38, 0), apiv_id NUMBER(38, 0));
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-5::apiman (generated)
CREATE TABLE endpoint_properties (api_version_id NUMBER(38, 0) NOT NULL, value VARCHAR2(255), name VARCHAR2(255) NOT NULL);
@@ -299,6 +299,7 @@ ALTER TABLE plan_versions ADD CONSTRAINT UK_plan_versions_1 UNIQUE (plan_id, pla
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-4::apiman
ALTER TABLE client_versions ADD CONSTRAINT UK_client_versions_1 UNIQUE (client_id, client_org_id, version);
+ALTER TABLE client_versions ADD CONSTRAINT UK_client_versions_2 UNIQUE (apikey);
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-5::apiman
ALTER TABLE api_versions ADD CONSTRAINT UK_api_versions_1 UNIQUE (api_id, api_org_id, version);
@@ -307,7 +308,7 @@ ALTER TABLE api_versions ADD CONSTRAINT UK_api_versions_1 UNIQUE (api_id, api_or
ALTER TABLE api_defs ADD CONSTRAINT UK_api_defs_1 UNIQUE (api_version_id);
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-7::apiman
-ALTER TABLE contracts ADD CONSTRAINT UK_contracts_1 UNIQUE (clientv_id, apiv_id, planv_id);
+ALTER TABLE contracts ADD CONSTRAINT UK_contracts_1 UNIQUE (clientv_id, apiv_id);
-- Changeset C:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/200-apiman-manager-api.db.indexes.changelog.xml::createIndex-1::apiman
CREATE INDEX IDX_auditlog_1 ON auditlog(who);
diff --git a/distro/data/src/main/resources/ddls/apiman_postgresql9.ddl b/distro/data/src/main/resources/ddls/apiman_postgresql9.ddl
index a5d19906a5..1ffc928a01 100644
--- a/distro/data/src/main/resources/ddls/apiman_postgresql9.ddl
+++ b/distro/data/src/main/resources/ddls/apiman_postgresql9.ddl
@@ -11,7 +11,7 @@
CREATE SEQUENCE hibernate_sequence START WITH 999;
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-1::apiman (generated)
-CREATE TABLE client_versions (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, modified_by VARCHAR(255) NOT NULL, modified_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, published_on TIMESTAMP WITHOUT TIME ZONE, retired_on TIMESTAMP WITHOUT TIME ZONE, status VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, client_id VARCHAR(255), client_org_id VARCHAR(255));
+CREATE TABLE client_versions (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, modified_by VARCHAR(255) NOT NULL, modified_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, published_on TIMESTAMP WITHOUT TIME ZONE, retired_on TIMESTAMP WITHOUT TIME ZONE, status VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, client_id VARCHAR(255), client_org_id VARCHAR(255), apikey VARCHAR(255) NOT NULL);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-2::apiman (generated)
CREATE TABLE clients (id VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, description VARCHAR(512), name VARCHAR(255) NOT NULL, organization_id VARCHAR(255) NOT NULL);
@@ -20,7 +20,7 @@ CREATE TABLE clients (id VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL
CREATE TABLE auditlog (id BIGINT NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, data TEXT, entity_id VARCHAR(255), entity_type VARCHAR(255) NOT NULL, entity_version VARCHAR(255), organization_id VARCHAR(255) NOT NULL, what VARCHAR(255) NOT NULL, who VARCHAR(255) NOT NULL);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-4::apiman (generated)
-CREATE TABLE contracts (id BIGINT NOT NULL, apikey VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, clientv_id BIGINT, planv_id BIGINT, apiv_id BIGINT);
+CREATE TABLE contracts (id BIGINT NOT NULL, created_by VARCHAR(255) NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, clientv_id BIGINT, planv_id BIGINT, apiv_id BIGINT);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml::1436469846462-5::apiman (generated)
CREATE TABLE endpoint_properties (api_version_id BIGINT NOT NULL, value VARCHAR(255), name VARCHAR(255) NOT NULL);
@@ -301,6 +301,7 @@ ALTER TABLE plan_versions ADD CONSTRAINT "UK_plan_versions_1" UNIQUE (plan_id, p
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-4::apiman
ALTER TABLE client_versions ADD CONSTRAINT "UK_client_versions_1" UNIQUE (client_id, client_org_id, version);
+ALTER TABLE client_versions ADD CONSTRAINT "UK_client_versions_2" UNIQUE (apikey);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-5::apiman
ALTER TABLE api_versions ADD CONSTRAINT "UK_api_versions_1" UNIQUE (api_id, api_org_id, version);
@@ -309,7 +310,7 @@ ALTER TABLE api_versions ADD CONSTRAINT "UK_api_versions_1" UNIQUE (api_id, api_
ALTER TABLE api_defs ADD CONSTRAINT "UK_api_defs_1" UNIQUE (api_version_id);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml::addUniqueConstraint-7::apiman
-ALTER TABLE contracts ADD CONSTRAINT "UK_contracts_1" UNIQUE (clientv_id, apiv_id, planv_id);
+ALTER TABLE contracts ADD CONSTRAINT "UK_contracts_1" UNIQUE (clientv_id, apiv_id);
-- Changeset c:/Users/ewittman/git/apiman/apiman/distro/ddl/src/main/liquibase/current/200-apiman-manager-api.db.indexes.changelog.xml::createIndex-1::apiman
CREATE INDEX "IDX_auditlog_1" ON auditlog(who);
diff --git a/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml b/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml
index ad6fbfd8e2..0625c0b42a 100644
--- a/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml
+++ b/distro/ddl/src/main/liquibase/current/010-apiman-manager-api.db.tables.changelog.xml
@@ -27,6 +27,9 @@
+
+
+
@@ -79,9 +82,6 @@
-
-
-
diff --git a/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml b/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml
index fc4679620c..3f169e2f49 100644
--- a/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml
+++ b/distro/ddl/src/main/liquibase/current/110-apiman-manager-api.db.unique.constraints.changelog.xml
@@ -25,7 +25,11 @@
constraintName="UK_api_defs_1" initiallyDeferred="false" tableName="api_defs"/>
-
+
+
+
\ No newline at end of file
diff --git a/gateway/api/rest-impl/src/main/java/io/apiman/gateway/api/rest/impl/ClientResourceImpl.java b/gateway/api/rest-impl/src/main/java/io/apiman/gateway/api/rest/impl/ClientResourceImpl.java
index 94c0b42bb2..55606c04e6 100644
--- a/gateway/api/rest-impl/src/main/java/io/apiman/gateway/api/rest/impl/ClientResourceImpl.java
+++ b/gateway/api/rest-impl/src/main/java/io/apiman/gateway/api/rest/impl/ClientResourceImpl.java
@@ -44,6 +44,10 @@ public ClientResourceImpl() {
*/
@Override
public void register(Client client) throws RegistrationException, NotAuthorizedException {
+ if (client.getApiKey() == null) {
+ throw new RegistrationException("Cannot Register Client: Missing API Key"); //$NON-NLS-1$
+ }
+
final Set errorHolder = new HashSet<>();
final CountDownLatch latch = new CountDownLatch(1);
// Register client; latch until result returned and evaluated
diff --git a/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/ApiContract.java b/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/ApiContract.java
index 4e4d31adbf..804af4ede2 100644
--- a/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/ApiContract.java
+++ b/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/ApiContract.java
@@ -29,7 +29,6 @@ public class ApiContract implements Serializable {
private static final long serialVersionUID = -4264090614804457252L;
- private String apikey;
private Api api;
private Client client;
private String plan;
@@ -43,33 +42,17 @@ public ApiContract() {
/**
* Constructor.
- * @param apikey the api key
* @param api the api
* @param client the client
* @param policies the list of policies
*/
- public ApiContract(String apikey, Api api, Client client, String plan, List policies) {
- setApikey(apikey);
+ public ApiContract(Api api, Client client, String plan, List policies) {
setApi(api);
setClient(client);
setPlan(plan);
setPolicies(policies);
}
- /**
- * @return the apikey
- */
- public String getApikey() {
- return apikey;
- }
-
- /**
- * @param apikey the apikey to set
- */
- public void setApikey(String apikey) {
- this.apikey = apikey;
- }
-
/**
* @return the api
*/
@@ -112,37 +95,6 @@ public void setPolicies(List policies) {
this.policies = policies;
}
- /**
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((apikey == null) ? 0 : apikey.hashCode());
- return result;
- }
-
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ApiContract other = (ApiContract) obj;
- if (apikey == null) {
- if (other.apikey != null)
- return false;
- } else if (!apikey.equals(other.apikey))
- return false;
- return true;
- }
-
/**
* @return the plan
*/
diff --git a/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Client.java b/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Client.java
index 60941fa104..9b951cda76 100644
--- a/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Client.java
+++ b/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Client.java
@@ -33,6 +33,7 @@ public class Client implements Serializable {
private String organizationId;
private String clientId;
private String version;
+ private String apiKey;
private Set contracts = new HashSet<>();
/**
@@ -173,4 +174,18 @@ private String toString(Collection> collection, int maxLen) {
return builder.toString();
}
+ /**
+ * @return the apiKey
+ */
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ /**
+ * @param apiKey the apiKey to set
+ */
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
}
diff --git a/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Contract.java b/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Contract.java
index 8d2ea199c0..3a955d5fc2 100644
--- a/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Contract.java
+++ b/gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/Contract.java
@@ -28,7 +28,6 @@ public class Contract implements Serializable {
private static final long serialVersionUID = 8344360785926823601L;
- private String apiKey;
private String apiOrgId;
private String apiId;
private String apiVersion;
@@ -41,20 +40,6 @@ public class Contract implements Serializable {
public Contract() {
}
- /**
- * @return the apiKey
- */
- public String getApiKey() {
- return apiKey;
- }
-
- /**
- * @param apiKey the apiKey to set
- */
- public void setApiKey(String apiKey) {
- this.apiKey = apiKey;
- }
-
/**
* @return the apiOrgId
*/
@@ -126,34 +111,28 @@ public void setPlan(String plan) {
}
/**
- * @see java.lang.Object#hashCode()
+ * Checks the API unique identifier against what this contract expects (org id, id, version).
+ * Returns true if they match.
+ * @param request
+ * @return true if the given request matches this contract
*/
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((apiKey == null) ? 0 : apiKey.hashCode());
- return result;
+ public boolean matches(ApiRequest request) {
+ String apiOrgId = request.getApiOrgId();
+ String apiId = request.getApiId();
+ String apiVersion = request.getApiVersion();
+ return matches(apiOrgId, apiId, apiVersion);
}
-
+
/**
- * @see java.lang.Object#equals(java.lang.Object)
+ * Checks the API unique identifier against what this contract expects (org id, id, version).
+ * Returns true if they match.
+ * @param apiOrgId
+ * @param apiId
+ * @param apiVersion
+ * @return true if the given request matches this contract
*/
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Contract other = (Contract) obj;
- if (apiKey == null) {
- if (other.apiKey != null)
- return false;
- } else if (!apiKey.equals(other.apiKey))
- return false;
- return true;
+ public boolean matches(String apiOrgId, String apiId, String apiVersion) {
+ return this.apiOrgId.equals(apiOrgId) && this.apiId.equals(apiId) && this.apiVersion.equals(apiVersion);
}
}
diff --git a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/IRegistry.java b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/IRegistry.java
index b7c44b0457..a33024d880 100644
--- a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/IRegistry.java
+++ b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/IRegistry.java
@@ -18,9 +18,7 @@
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.Client;
-import io.apiman.gateway.engine.beans.Contract;
import io.apiman.gateway.engine.beans.exceptions.InvalidContractException;
import io.apiman.gateway.engine.beans.exceptions.PublishingException;
import io.apiman.gateway.engine.beans.exceptions.RegistrationException;
@@ -35,16 +33,6 @@
*/
public interface IRegistry {
- /**
- * Gets the {@link Contract} to use based on information included in the inbound
- * API request.
- *
- * @param request an inbound API request
- * @param handler the result handler
- * @throws InvalidContractException when contract is invalid
- */
- public void getContract(ApiRequest request, IAsyncResultHandler handler);
-
/**
* Publishes a new {@link Api} into the registry.
* @param api the api being published
@@ -86,4 +74,23 @@ public interface IRegistry {
*/
public void getApi(String organizationId, String apiId, String apiVersion, IAsyncResultHandler handler);
+ /**
+ * Gets the {@link Client} referenced by the given API Key.
+ *
+ * @param request an inbound API request
+ * @param handler the result handler
+ * @throws InvalidContractException when contract is invalid
+ */
+ public void getClient(String apiKey, IAsyncResultHandler handler);
+
+ /**
+ * Gets the full contract associated with the given API identifier and API Key.
+ * @param apiOrganizationId
+ * @param apiId
+ * @param apiVersion
+ * @param apiKey
+ * @param handler
+ */
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey, IAsyncResultHandler handler);
+
}
diff --git a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/ApiRequestExecutorImpl.java b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/ApiRequestExecutorImpl.java
index f1f928e943..933d77f3e7 100644
--- a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/ApiRequestExecutorImpl.java
+++ b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/ApiRequestExecutorImpl.java
@@ -273,7 +273,11 @@ public void execute() {
}
});
} else {
- registry.getContract(request, (IAsyncResult contractResult) -> {
+ String apiOrgId = request.getApiOrgId();
+ String apiId = request.getApiId();
+ String apiVersion = request.getApiVersion();
+ String apiKey = request.getApiKey();
+ registry.getContract(apiOrgId, apiId, apiVersion, apiKey,(IAsyncResult contractResult) -> {
if (contractResult.isSuccess()) {
ApiContract apiContract = contractResult.getResult();
diff --git a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/InMemoryRegistry.java b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/InMemoryRegistry.java
index 95efc92acd..25ab031fbc 100644
--- a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/InMemoryRegistry.java
+++ b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/InMemoryRegistry.java
@@ -17,11 +17,9 @@
import io.apiman.gateway.engine.IRegistry;
import io.apiman.gateway.engine.async.AsyncResultImpl;
-import io.apiman.gateway.engine.async.IAsyncResult;
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.Client;
import io.apiman.gateway.engine.beans.Contract;
import io.apiman.gateway.engine.beans.exceptions.InvalidContractException;
@@ -54,8 +52,8 @@ public InMemoryRegistry() {
@Override
public void publishApi(Api api, IAsyncResultHandler handler) {
synchronized (mutex) {
- String apiKey = getApiKey(api);
- getMap().put(apiKey, api);
+ String apiIdx = getApiIndex(api);
+ getMap().put(apiIdx, api);
}
handler.handle(AsyncResultImpl.create((Void) null));
}
@@ -65,12 +63,11 @@ public void publishApi(Api api, IAsyncResultHandler handler) {
*/
@Override
public void retireApi(Api api, IAsyncResultHandler handler) {
+ String apiIdx = getApiIndex(api);
Exception error = null;
synchronized (mutex) {
- String apiKey = getApiKey(api);
- if (getMap().containsKey(apiKey)) {
- getMap().remove(apiKey);
- } else {
+ Api removedApi = (Api) getMap().remove(apiIdx);
+ if (removedApi == null) {
error = new PublishingException(Messages.i18n.format("InMemoryRegistry.ApiNotFound")); //$NON-NLS-1$
}
}
@@ -90,32 +87,21 @@ public void registerClient(Client client, IAsyncResultHandler handler) {
synchronized (mutex) {
// Validate the client first - we need to be able to resolve all the contracts.
for (Contract contract : client.getContracts()) {
- String apiKey = getApiKey(contract.getApiOrgId(), contract.getApiId(), contract.getApiVersion());
- if (!getMap().containsKey(apiKey)) {
+ String apiIdx = getApiIndex(contract.getApiOrgId(), contract.getApiId(), contract.getApiVersion());
+ if (!getMap().containsKey(apiIdx)) {
error = new RegistrationException(Messages.i18n.format("InMemoryRegistry.ApiNotFoundInOrg", //$NON-NLS-1$
contract.getApiId(), contract.getApiOrgId()));
break;
}
}
- // Unregister the app (if it exists)
- IAsyncResultHandler unregisterHandler = new IAsyncResultHandler() {
- @Override
- public void handle(IAsyncResult result) {
- }
- };
- unregisterClient(client, unregisterHandler);
+ // Unregister the client (if it exists)
+ unregisterClientInternal(client, true);
- // Now, register the app.
- String clientKey = getClientKey(client);
- getMap().put(clientKey, client);
- for (Contract contract : client.getContracts()) {
- String apiKey = getApiKey(contract.getApiOrgId(), contract.getApiId(), contract.getApiVersion());
- Api api = (Api) getMap().get(apiKey);
- ApiContract sc = new ApiContract(contract.getApiKey(), api, client, contract.getPlan(), contract.getPolicies());
- String contractKey = getContractKey(contract);
- getMap().put(contractKey, sc);
- }
+ // Now, register the client.
+ String clientIdx = getClientIndex(client);
+ getMap().put(clientIdx, client);
+ getMap().put(client.getApiKey(), client);
}
if (error == null) {
handler.handle(AsyncResultImpl.create((Void) null));
@@ -129,51 +115,95 @@ public void handle(IAsyncResult result) {
*/
@Override
public void unregisterClient(Client client, IAsyncResultHandler handler) {
- Exception error = null;
+ try {
+ unregisterClientInternal(client, false);
+ handler.handle(AsyncResultImpl.create((Void) null));
+ } catch (RegistrationException e) {
+ handler.handle(AsyncResultImpl.create(e, Void.class));
+ }
+ }
+
+ /**
+ * @param client
+ * @param silent
+ */
+ protected void unregisterClientInternal(Client client, boolean silent) throws RegistrationException {
synchronized (mutex) {
- String clientKey = getClientKey(client);
- if (getMap().containsKey(clientKey)) {
- Client removed = (Client) getMap().remove(clientKey);
- for (Contract contract : removed.getContracts()) {
- String contractKey = getContractKey(contract);
- if (getMap().containsKey(contractKey)) {
- getMap().remove(contractKey);
- }
+ String clientIdx = getClientIndex(client);
+ Client oldClient = (Client) getMap().remove(clientIdx);
+ if (oldClient == null) {
+ if (!silent) {
+ throw new RegistrationException(Messages.i18n.format("InMemoryRegistry.ClientNotFound")); //$NON-NLS-1$
}
} else {
- error = new RegistrationException(Messages.i18n.format("InMemoryRegistry.ClientNotFound")); //$NON-NLS-1$
+ getMap().remove(oldClient.getApiKey());
}
}
- if (error == null) {
- handler.handle(AsyncResultImpl.create((Void) null));
- } else {
- handler.handle(AsyncResultImpl.create(error, Void.class));
- }
}
-
+
/**
- * @see io.apiman.gateway.engine.IRegistry#getContract(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- public void getContract(ApiRequest request, IAsyncResultHandler handler) {
- String contractKey = getContractKey(request);
- ApiContract contract = (ApiContract) getMap().get(contractKey);
+ public void getClient(String apiKey, IAsyncResultHandler handler) {
+ Client client = getClientInternal(apiKey);
+ handler.handle(AsyncResultImpl.create(client));
+ }
- if (contract == null) {
- Exception error = new InvalidContractException(Messages.i18n.format("InMemoryRegistry.NoContractForAPIKey", request.getApiKey())); //$NON-NLS-1$
+ /**
+ * Gets the client and returns it.
+ * @param apiKey
+ */
+ protected Client getClientInternal(String apiKey) {
+ Client client;
+ synchronized (mutex) {
+ client = (Client) getMap().get(apiKey);
+ }
+ return client;
+ }
+
+ /**
+ * @see io.apiman.gateway.engine.IRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ */
+ @Override
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
+ IAsyncResultHandler handler) {
+ Client client = null;
+ Api api = null;
+
+ String apiIdx = getApiIndex(apiOrganizationId, apiId, apiVersion);
+ synchronized (mutex) {
+ client = (Client) getMap().get(apiKey);
+ api = (Api) getMap().get(apiIdx);
+ }
+ if (client == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("InMemoryRegistry.NoClientForAPIKey", apiKey)); //$NON-NLS-1$
handler.handle(AsyncResultImpl.create(error, ApiContract.class));
return;
}
- // Has the api been retired?
- Api api = contract.getApi();
- String apiKey = getApiKey(api);
- if (getMap().get(apiKey) == null) {
+ if (api == null) {
Exception error = new InvalidContractException(Messages.i18n.format("InMemoryRegistry.ApiWasRetired", //$NON-NLS-1$
- api.getApiId(), api.getOrganizationId()));
+ apiId, apiOrganizationId));
handler.handle(AsyncResultImpl.create(error, ApiContract.class));
return;
}
-
+
+ Contract matchedContract = null;
+ for (Contract contract : client.getContracts()) {
+ if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
+ matchedContract = contract;
+ break;
+ }
+ }
+
+ if (matchedContract == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("InMemoryRegistry.NoContractFound", //$NON-NLS-1$
+ client.getClientId(), api.getApiId()));
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+
+ ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
handler.handle(AsyncResultImpl.create(contract));
}
@@ -183,58 +213,56 @@ public void getContract(ApiRequest request, IAsyncResultHandler han
@Override
public void getApi(String organizationId, String apiId, String apiVersion,
IAsyncResultHandler handler) {
- String key = getApiKey(organizationId, apiId, apiVersion);
- Api api = (Api) getMap().get(key);
+ Api api = getApiInternal(organizationId, apiId, apiVersion);
handler.handle(AsyncResultImpl.create(api));
}
/**
- * Generates an in-memory key for an api, used to index the app for later quick
+ * Gets an API by its unique identifying info (orgid, id, version).
+ * @param apiOrgId
+ * @param apiId
+ * @param apiVersion
+ * @return an Api or null if not found
+ */
+ private Api getApiInternal(String apiOrgId, String apiId, String apiVersion) {
+ String key = getApiIndex(apiOrgId, apiId, apiVersion);
+ Api api;
+ synchronized (mutex) {
+ api = (Api) getMap().get(key);
+ }
+ return api;
+ }
+
+ /**
+ * Generates an in-memory key for an api, used to index the client for later quick
* retrieval.
* @param api an api
* @return a api key
*/
- private String getApiKey(Api api) {
- return getApiKey(api.getOrganizationId(), api.getApiId(), api.getVersion());
+ private String getApiIndex(Api api) {
+ return getApiIndex(api.getOrganizationId(), api.getApiId(), api.getVersion());
}
/**
- * Generates an in-memory key for an api, used to index the app for later quick
+ * Generates an in-memory key for an api, used to index the client for later quick
* retrieval.
* @param orgId
* @param apiId
* @param version
* @return a api key
*/
- private String getApiKey(String orgId, String apiId, String version) {
+ private String getApiIndex(String orgId, String apiId, String version) {
return "API::" + orgId + "|" + apiId + "|" + version; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
/**
- * Generates an in-memory key for an client, used to index the app for later quick
- * retrieval.
- * @param app an client
- * @return an client key
- */
- private String getClientKey(Client app) {
- return "CLIENT::" + app.getOrganizationId() + "|" + app.getClientId() + "|" + app.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- /**
- * Generates an in-memory key for a contract.
- * @param request
- */
- private String getContractKey(ApiRequest request) {
- return "CONTRACT::" + request.getApiKey(); //$NON-NLS-1$
- }
-
- /**
- * Generates an in-memory key for a api contract, used to index the app for later quick
+ * Generates an in-memory key for an client, used to index the client for later quick
* retrieval.
- * @param contract
+ * @param client an client
+ * @return a client key
*/
- private String getContractKey(Contract contract) {
- return "CONTRACT::" + contract.getApiKey(); //$NON-NLS-1$
+ private String getClientIndex(Client client) {
+ return "CLIENT::" + client.getOrganizationId() + "|" + client.getClientId() + "|" + client.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
/**
diff --git a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/SecureRegistryWrapper.java b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/SecureRegistryWrapper.java
index a69ff5484a..29b6f2f902 100644
--- a/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/SecureRegistryWrapper.java
+++ b/gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/SecureRegistryWrapper.java
@@ -21,7 +21,6 @@
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.Client;
import io.apiman.gateway.engine.beans.Contract;
import io.apiman.gateway.engine.beans.Policy;
@@ -123,13 +122,33 @@ public void handle(IAsyncResult result) {
}
});
}
-
+
+ /**
+ * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ */
+ @Override
+ public void getClient(String apiKey, IAsyncResultHandler handler) {
+ delegate.getClient(apiKey, new IAsyncResultHandler() {
+ @Override
+ public void handle(IAsyncResult result) {
+ if (result.isSuccess()) {
+ Client client = result.getResult();
+ for (Contract contract : client.getContracts()) {
+ decryptPolicies(contract.getPolicies());
+ }
+ }
+ handler.handle(result);
+ }
+ });
+ }
+
/**
- * @see io.apiman.gateway.engine.IRegistry#getContract(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ * @see io.apiman.gateway.engine.IRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- public void getContract(ApiRequest request, final IAsyncResultHandler handler) {
- delegate.getContract(request, new IAsyncResultHandler() {
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
+ IAsyncResultHandler handler) {
+ delegate.getContract(apiOrganizationId, apiId, apiVersion, apiKey, new IAsyncResultHandler() {
@Override
public void handle(IAsyncResult result) {
if (result.isSuccess()) {
diff --git a/gateway/engine/core/src/main/resources/io/apiman/gateway/engine/i18n/messages.properties b/gateway/engine/core/src/main/resources/io/apiman/gateway/engine/i18n/messages.properties
index f85062a934..ac52c072c3 100644
--- a/gateway/engine/core/src/main/resources/io/apiman/gateway/engine/i18n/messages.properties
+++ b/gateway/engine/core/src/main/resources/io/apiman/gateway/engine/i18n/messages.properties
@@ -1,5 +1,4 @@
InMemoryRegistry.ClientNotFound=Client not found.
-InMemoryRegistry.NoContractForAPIKey=No contract found for API Key {0}
InMemoryRegistry.ApiNotFound=API not found.
InMemoryRegistry.ApiNotFoundInOrg=API {0} not found in Organization {1}.
InMemoryRegistry.ApiWasRetired=API {0} in Organization {1} has been retired.
@@ -10,4 +9,6 @@ DefaultPluginRegistry.PluginNotFound=Could not find plugin. (Not found locally
DefaultPluginRegistry.InvalidPlugin=Invalid plugin file at: {0}
DefaultPluginRegistry.MissingPluginSpecFile=Missing plugin spec file at: {0}
InfluxDb09Metrics.databaseDoesNotExist=Database {0} does not exist.
-InfluxDb09Metrics.mandatoryConfigMustBeSet={0} requires {1} to be set in configuration.
\ No newline at end of file
+InfluxDb09Metrics.mandatoryConfigMustBeSet={0} requires {1} to be set in configuration.
+InMemoryRegistry.NoClientForAPIKey=No client found for API Key {0}
+InMemoryRegistry.NoContractFound=No contract found between Client {0} and API {1}.
diff --git a/gateway/engine/core/src/test/java/io/apiman/gateway/engine/impl/DefaultEngineFactoryTest.java b/gateway/engine/core/src/test/java/io/apiman/gateway/engine/impl/DefaultEngineFactoryTest.java
index 5c5184b149..f0d66cc84a 100644
--- a/gateway/engine/core/src/test/java/io/apiman/gateway/engine/impl/DefaultEngineFactoryTest.java
+++ b/gateway/engine/core/src/test/java/io/apiman/gateway/engine/impl/DefaultEngineFactoryTest.java
@@ -191,13 +191,13 @@ public void abort() {
api.setOrganizationId("TestOrg");
api.setApiId("TestApi");
api.setVersion("1.0");
- // create an app
+ // create a client
Client app = new Client();
app.setClientId("TestApp");
app.setOrganizationId("TestOrg");
app.setVersion("1.0");
+ app.setApiKey("client-12345");
Contract contract = new Contract();
- contract.setApiKey("12345");
contract.setPlan("Gold");
contract.setApiId("TestApi");
contract.setApiOrgId("TestOrg");
@@ -219,7 +219,10 @@ public void handle(IAsyncResult result) {
});
ApiRequest request = new ApiRequest();
- request.setApiKey("12345");
+ request.setApiKey("client-12345");
+ request.setApiId("TestApi");
+ request.setApiOrgId("TestOrg");
+ request.setApiVersion("1.0");
request.setDestination("/");
request.setUrl("http://localhost:9999/");
request.setType("TEST");
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/AbstractESComponent.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/AbstractESComponent.java
index 9897352dcc..991bb347ae 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/AbstractESComponent.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/AbstractESComponent.java
@@ -28,6 +28,7 @@ public abstract class AbstractESComponent {
private final Map config;
private JestClient esClient;
+ private String indexName;
/**
* Constructor.
@@ -35,6 +36,11 @@ public abstract class AbstractESComponent {
*/
public AbstractESComponent(Map config) {
this.config = config;
+ String indexName = config.get("client.index"); //$NON-NLS-1$
+ if (indexName == null) {
+ indexName = getDefaultIndexName();
+ }
+ this.indexName = indexName;
}
/**
@@ -42,14 +48,21 @@ public AbstractESComponent(Map config) {
*/
public synchronized JestClient getClient() {
if (esClient == null) {
- esClient = ESClientFactory.createClient(config, getIndexName());
+ esClient = ESClientFactory.createClient(config, getDefaultIndexName());
}
return esClient;
}
/**
- * Gets the configured index name.
+ * Gets the default index name for this component.
+ */
+ protected abstract String getDefaultIndexName();
+
+ /**
+ * Gets the index name to use when reading/writing to ES.
*/
- protected abstract String getIndexName();
+ protected String getIndexName() {
+ return indexName;
+ }
}
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/CachingESRegistry.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/CachingESRegistry.java
index 59dbe4faea..14e2491895 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/CachingESRegistry.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/CachingESRegistry.java
@@ -16,16 +16,15 @@
package io.apiman.gateway.engine.es;
import io.apiman.gateway.engine.async.AsyncResultImpl;
-import io.apiman.gateway.engine.async.IAsyncResult;
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
+import io.apiman.gateway.engine.beans.Client;
+import io.apiman.gateway.engine.beans.Contract;
import io.apiman.gateway.engine.beans.exceptions.InvalidContractException;
import io.apiman.gateway.engine.es.i18n.Messages;
import java.io.IOException;
-import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -39,8 +38,8 @@
*/
public abstract class CachingESRegistry extends ESRegistry {
- private Map contractCache = new ConcurrentHashMap<>();
- private Map apiCache = new HashMap<>();
+ private Map apiCache = new ConcurrentHashMap<>();
+ private Map clientCache = new ConcurrentHashMap<>();
private Object mutex = new Object();
/**
@@ -56,44 +55,51 @@ public CachingESRegistry(Map config) {
*/
protected void invalidateCache() {
synchronized (mutex) {
- contractCache.clear();
+ clientCache.clear();
apiCache.clear();
}
}
/**
- * @see io.apiman.gateway.engine.es.ESRegistry#getContract(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ * @see io.apiman.gateway.engine.jdbc.ESRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- public void getContract(final ApiRequest request, final IAsyncResultHandler handler) {
- ApiContract contract;
-
- final String contractKey = getContractKey(request);
- synchronized (mutex) {
- contract = contractCache.get(contractKey);
- }
-
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
+ IAsyncResultHandler handler) {
+ Client client = null;
+ Api api = null;
+
try {
- if (contract == null) {
- super.getContract(request, new IAsyncResultHandler() {
- @Override
- public void handle(IAsyncResult result) {
- if (result.isSuccess()) {
- contractCache.put(contractKey, result.getResult());
- }
- handler.handle(result);
- }
- });
- } else {
- Api api = getApi(request.getApiOrgId(), request.getApiId(), request.getApiVersion());
- if (api == null) {
- throw new InvalidContractException(Messages.i18n.format("ESRegistry.ApiWasRetired", //$NON-NLS-1$
- request.getApiId(), request.getApiOrgId()));
+ synchronized (mutex) {
+ client = getClient(apiKey);
+ api = getApi(apiOrganizationId, apiId, apiVersion);
+ }
+ if (client == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("ESRegistry.NoClientForAPIKey", apiKey)); //$NON-NLS-1$
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+ if (api == null) {
+ throw new InvalidContractException(Messages.i18n.format("ESRegistry.ApiWasRetired", //$NON-NLS-1$
+ apiId, apiOrganizationId));
+ }
+
+ Contract matchedContract = null;
+ for (Contract contract : client.getContracts()) {
+ if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
+ matchedContract = contract;
+ break;
}
- contract.setApi(api);
- handler.handle(AsyncResultImpl.create(contract));
}
- } catch (Throwable e) {
+
+ if (matchedContract == null) {
+ throw new InvalidContractException(Messages.i18n.format("ESRegistry.NoContractFound", //$NON-NLS-1$
+ client.getClientId(), api.getApiId()));
+ }
+
+ ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
+ handler.handle(AsyncResultImpl.create(contract));
+ } catch (Exception e) {
handler.handle(AsyncResultImpl.create(e, ApiContract.class));
}
}
@@ -119,17 +125,17 @@ public void getApi(final String organizationId, final String apiId, final String
* @param version
*/
protected Api getApi(String orgId, String apiId, String version) throws IOException {
- String apiKey = getApiKey(orgId, apiId, version);
+ String apiIdx = getApiIdx(orgId, apiId, version);
Api api;
synchronized (mutex) {
- api = apiCache.get(apiKey);
+ api = apiCache.get(apiIdx);
}
if (api == null) {
api = super.getApi(getApiId(orgId, apiId, version));
synchronized (mutex) {
if (api != null) {
- apiCache.put(apiKey, api);
+ apiCache.put(apiIdx, api);
}
}
}
@@ -138,18 +144,43 @@ protected Api getApi(String orgId, String apiId, String version) throws IOExcept
}
/**
- * @see io.apiman.gateway.engine.es.ESRegistry#checkApi(io.apiman.gateway.engine.beans.ApiContract)
+ * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- protected void checkApi(ApiContract contract) throws InvalidContractException, IOException {
- Api api = getApi(contract.getApi().getOrganizationId(),
- contract.getApi().getApiId(),
- contract.getApi().getVersion());
- if (api == null) {
- throw new InvalidContractException(Messages.i18n.format("ESRegistry.ApiWasRetired", //$NON-NLS-1$
- contract.getApi().getApiId(), contract.getApi().getOrganizationId()));
+ public void getClient(String apiKey, IAsyncResultHandler handler) {
+ try {
+ Client client = getClient(apiKey);
+ handler.handle(AsyncResultImpl.create(client));
+ } catch (IOException e) {
+ handler.handle(AsyncResultImpl.create(e, Client.class));
+ }
+ }
+
+ /**
+ * Gets the client either from the cache or from ES.
+ * @param orgId
+ * @param clientId
+ * @param version
+ * @throws IOException
+ */
+ protected Client getClient(String apiKey) throws IOException {
+ Client client;
+ synchronized (mutex) {
+ client = clientCache.get(apiKey);
}
+
+ if (client == null) {
+ client = super.getClient(apiKey);
+ synchronized (mutex) {
+ if (client != null) {
+ clientCache.put(apiKey, client);
+ }
+ }
+ }
+
+ return client;
}
+
/**
* Generates an in-memory key for an API, used to index the app for later quick
@@ -159,16 +190,8 @@ protected void checkApi(ApiContract contract) throws InvalidContractException, I
* @param version
* @return a API key
*/
- private String getApiKey(String orgId, String apiId, String version) {
+ private String getApiIdx(String orgId, String apiId, String version) {
return "API::" + orgId + "|" + apiId + "|" + version; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- /**
- * Generates an in-memory key for a contract.
- * @param request
- */
- private String getContractKey(ApiRequest request) {
- return "CONTRACT::" + request.getApiKey(); //$NON-NLS-1$
- }
-
}
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESCacheStoreComponent.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESCacheStoreComponent.java
index c1d1e45142..b484f44ec6 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESCacheStoreComponent.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESCacheStoreComponent.java
@@ -224,10 +224,10 @@ public void transmit() {
}
/**
- * @see io.apiman.gateway.engine.es.AbstractESComponent#getIndexName()
+ * @see io.apiman.gateway.engine.es.AbstractESComponent#getDefaultIndexName()
*/
@Override
- protected String getIndexName() {
+ protected String getDefaultIndexName() {
return ESConstants.CACHE_INDEX_NAME;
}
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESMetrics.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESMetrics.java
index c2a0ab61e4..d3cffe24dc 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESMetrics.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESMetrics.java
@@ -79,10 +79,10 @@ public void failed(Exception e) {
}
/**
- * @see io.apiman.gateway.engine.es.AbstractESComponent#getIndexName()
+ * @see io.apiman.gateway.engine.es.AbstractESComponent#getDefaultIndexName()
*/
@Override
- protected String getIndexName() {
+ protected String getDefaultIndexName() {
return ESConstants.METRICS_INDEX_NAME;
}
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRateLimiterComponent.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRateLimiterComponent.java
index 490eba450d..16a0818480 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRateLimiterComponent.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRateLimiterComponent.java
@@ -136,10 +136,10 @@ private String id(String bucketId) {
}
/**
- * @see io.apiman.gateway.engine.es.AbstractESComponent#getIndexName()
+ * @see io.apiman.gateway.engine.es.AbstractESComponent#getDefaultIndexName()
*/
@Override
- protected String getIndexName() {
+ protected String getDefaultIndexName() {
return ESConstants.GATEWAY_INDEX_NAME;
}
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRegistry.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRegistry.java
index 5eb399415b..38ccaf2ee7 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRegistry.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESRegistry.java
@@ -20,23 +20,19 @@
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.Client;
import io.apiman.gateway.engine.beans.Contract;
import io.apiman.gateway.engine.beans.exceptions.InvalidContractException;
import io.apiman.gateway.engine.beans.exceptions.PublishingException;
import io.apiman.gateway.engine.beans.exceptions.RegistrationException;
import io.apiman.gateway.engine.es.i18n.Messages;
-import io.apiman.gateway.engine.es.util.ElasticQueryUtil;
import io.searchbox.client.JestResult;
import io.searchbox.core.Delete;
-import io.searchbox.core.DeleteByQuery;
import io.searchbox.core.Get;
import io.searchbox.core.Index;
import io.searchbox.params.Parameters;
import java.io.IOException;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -104,11 +100,10 @@ public void retireApi(Api api, final IAsyncResultHandler handler) {
*/
@Override
public void registerClient(final Client client, final IAsyncResultHandler handler) {
- final Map apiMap = new HashMap<>();
-
try {
// Validate the client and populate the api map with apis found during validation.
- validateClient(client, apiMap);
+ validateClient(client);
+
String id = getClientId(client);
Index index = new Index.Builder(client)
.refresh(false).index(getIndexName())
@@ -117,18 +112,8 @@ public void registerClient(final Client client, final IAsyncResultHandler
JestResult result = getClient().execute(index);
if (!result.isSucceeded()) {
throw new IOException(result.getErrorMessage());
- } else {
- // Remove all the api contracts, then re-add them
- unregisterApiContracts(client);
-
- // Register all the api contracts.
- Set contracts = client.getContracts();
- client.setContracts(null);
- for (Contract contract : contracts) {
- registerContract(client, contract, apiMap);
- }
- handler.handle(AsyncResultImpl.create((Void) null));
- }
+ }
+ handler.handle(AsyncResultImpl.create((Void) null));
} catch (IOException e) {
handler.handle(AsyncResultImpl.create(
new RegistrationException(Messages.i18n.format("ESRegistry.ErrorRegisteringClient"), e), //$NON-NLS-1$
@@ -141,15 +126,14 @@ public void registerClient(final Client client, final IAsyncResultHandler
/**
* Validate that the client should be registered.
* @param client
- * @param apiMap
*/
- private void validateClient(Client client, Map apiMap) throws RegistrationException {
+ private void validateClient(Client client) throws RegistrationException {
Set contracts = client.getContracts();
if (contracts.isEmpty()) {
throw new RegistrationException(Messages.i18n.format("ESRegistry.NoContracts")); //$NON-NLS-1$
}
for (Contract contract : contracts) {
- validateContract(contract, apiMap);
+ validateContract(contract);
}
}
@@ -159,19 +143,14 @@ private void validateClient(Client client, Map apiMap) throws Regis
* @param contract
* @param apiMap
*/
- private void validateContract(final Contract contract, final Map apiMap)
+ private void validateContract(final Contract contract)
throws RegistrationException {
-
final String id = getApiId(contract);
try {
Get get = new Get.Builder(getIndexName(), id).type("api").build(); //$NON-NLS-1$
JestResult result = getClient().execute(get);
- if (result.isSucceeded()) {
- Api api = result.getSourceAsObject(Api.class);
- api.setApiPolicies(null);
- apiMap.put(id, api);
- } else {
+ if (!result.isSucceeded()) {
String apiId = contract.getApiId();
String orgId = contract.getApiOrgId();
throw new RegistrationException(Messages.i18n.format("ESRegistry.ApiNotFoundInOrg", apiId, orgId)); //$NON-NLS-1$
@@ -181,34 +160,6 @@ private void validateContract(final Contract contract, final Map ap
}
}
- /**
- * Register all the contracts in ES so they can be looked up quickly by
- * their ID by all nodes in the cluster.
- * @param client
- * @param contracts
- * @param apiMap
- */
- private void registerContract(final Client client, final Contract contract,
- final Map apiMap) throws RegistrationException {
- try {
- String apiId = getApiId(contract);
- Api api = apiMap.get(apiId);
- ApiContract sc = new ApiContract(contract.getApiKey(), api, client,
- contract.getPlan(), contract.getPolicies());
- final String contractId = getContractId(contract);
-
- Index index = new Index.Builder(sc).refresh(false)
- .setParameter(Parameters.OP_TYPE, "create") //$NON-NLS-1$
- .index(getIndexName()).type("apiContract").id(contractId).build(); //$NON-NLS-1$
- JestResult result = getClient().execute(index);
- if (!result.isSucceeded()) {
- throw new RegistrationException(Messages.i18n.format("ESRegistry.ContractAlreadyPublished", contractId)); //$NON-NLS-1$
- }
- } catch (Exception e) {
- throw new RegistrationException(Messages.i18n.format("ESRegistry.ErrorRegisteringContract"), e); //$NON-NLS-1$
- }
- }
-
/**
* @see io.apiman.gateway.engine.IRegistry#unregisterClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@@ -220,7 +171,6 @@ public void unregisterClient(final Client client, final IAsyncResultHandler handler) {
- final String id = getContractId(request);
-
+ public void getApi(String organizationId, String apiId, String apiVersion,
+ IAsyncResultHandler handler) {
+ String id = getApiId(organizationId, apiId, apiVersion);
try {
- Get get = new Get.Builder(getIndexName(), id).type("apiContract").build(); //$NON-NLS-1$
- JestResult result = getClient().execute(get);
- if (!result.isSucceeded()) {
- Exception error = new InvalidContractException(Messages.i18n.format("ESRegistry.NoContractForAPIKey", id)); //$NON-NLS-1$
- handler.handle(AsyncResultImpl.create(error, ApiContract.class));
- } else {
- ApiContract contract = result.getSourceAsObject(ApiContract.class);
- checkApi(contract);
- handler.handle(AsyncResultImpl.create(contract));
- }
+ Api api = getApi(id);
+ handler.handle(AsyncResultImpl.create(api));
} catch (IOException e) {
- handler.handle(AsyncResultImpl.create(e, ApiContract.class));
+ handler.handle(AsyncResultImpl.create(e, Api.class));
}
}
/**
- * Ensure that the api still exists. If not, it was retired.
- * @param contract
- * @throws InvalidContractException
+ * Gets the api synchronously.
+ * @param id
* @throws IOException
*/
- protected void checkApi(final ApiContract contract) throws InvalidContractException, IOException {
- final Api api = contract.getApi();
- String id = getApiId(api);
-
+ protected Api getApi(String id) throws IOException {
Get get = new Get.Builder(getIndexName(), id).type("api").build(); //$NON-NLS-1$
JestResult result = getClient().execute(get);
- if (!result.isSucceeded()) {
- throw new InvalidContractException(Messages.i18n.format("ESRegistry.ApiWasRetired", //$NON-NLS-1$
- api.getApiId(), api.getOrganizationId()));
+ if (result.isSucceeded()) {
+ Api api = result.getSourceAsObject(Api.class);
+ return api;
+ } else {
+ return null;
}
}
/**
- * @see io.apiman.gateway.engine.IRegistry#getApi(java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- public void getApi(String organizationId, String apiId, String apiVersion,
- IAsyncResultHandler handler) {
- String id = getApiId(organizationId, apiId, apiVersion);
- getApi(id, handler);
- }
-
- /**
- * Asynchronously gets a api.
- * @param id
- * @param handler
- */
- protected void getApi(String id, final IAsyncResultHandler handler) {
+ public void getClient(String apiKey, IAsyncResultHandler handler) {
+ String id = apiKey;
try {
- Api api = getApi(id);
- handler.handle(AsyncResultImpl.create(api));
+ Client client = getClient(id);
+ handler.handle(AsyncResultImpl.create(client));
} catch (IOException e) {
- handler.handle(AsyncResultImpl.create(e, Api.class));
+ handler.handle(AsyncResultImpl.create(e, Client.class));
}
}
/**
- * Gets the api synchronously.
+ * Gets the client synchronously.
* @param id
* @throws IOException
*/
- protected Api getApi(String id) throws IOException {
- Get get = new Get.Builder(getIndexName(), id).type("api").build(); //$NON-NLS-1$
+ protected Client getClient(String id) throws IOException {
+ Get get = new Get.Builder(getIndexName(), id).type("client").build(); //$NON-NLS-1$
JestResult result = getClient().execute(get);
if (result.isSucceeded()) {
- Api api = result.getSourceAsObject(Api.class);
- return api;
+ Client client = result.getSourceAsObject(Client.class);
+ return client;
} else {
return null;
}
}
+
+ /**
+ * @see io.apiman.gateway.engine.IRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ */
+ @Override
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
+ IAsyncResultHandler handler) {
+
+ try {
+ Client client = getClient(apiKey);
+ Api api = getApi(getApiId(apiOrganizationId, apiId, apiVersion));
+
+ if (client == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("ESRegistry.NoClientForAPIKey", apiKey)); //$NON-NLS-1$
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+ if (api == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("ESRegistry.ApiWasRetired", //$NON-NLS-1$
+ apiId, apiOrganizationId));
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+
+ Contract matchedContract = null;
+ for (Contract contract : client.getContracts()) {
+ if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
+ matchedContract = contract;
+ break;
+ }
+ }
+
+ if (matchedContract == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("ESRegistry.NoContractFound", //$NON-NLS-1$
+ client.getClientId(), api.getApiId()));
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+
+ ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
+ handler.handle(AsyncResultImpl.create(contract));
+ } catch (Exception e) {
+ handler.handle(AsyncResultImpl.create(e, ApiContract.class));
+ }
+
+ }
/**
* Generates a valid document ID for a api, used to index the api in ES.
@@ -348,42 +310,26 @@ private String getApiId(Contract contract) {
* @param orgId
* @param apiId
* @param version
- * @return a api key
+ * @return a api id
*/
protected String getApiId(String orgId, String apiId, String version) {
return orgId + ":" + apiId + ":" + version; //$NON-NLS-1$ //$NON-NLS-2$
}
-
+
/**
- * Generates a valid document ID for an client, used to index the client in ES.
- * @param client an client
- * @return an client key
+ * Generates a valid document ID for the client - used to index the client in ES.
+ * @param client
+ * @return an id
*/
protected String getClientId(Client client) {
- return client.getOrganizationId() + ":" + client.getClientId() + ":" + client.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Generates a valid document ID for a contract, used to index the contract in ES.
- * @param request
- */
- private String getContractId(ApiRequest request) {
- return request.getApiKey();
- }
-
- /**
- * Generates a valid document ID for a contract, used to index the contract in ES.
- * @param contract
- */
- private String getContractId(Contract contract) {
- return contract.getApiKey();
+ return client.getApiKey();
}
/**
- * @see io.apiman.gateway.engine.es.AbstractESComponent#getIndexName()
+ * @see io.apiman.gateway.engine.es.AbstractESComponent#getDefaultIndexName()
*/
@Override
- protected String getIndexName() {
+ protected String getDefaultIndexName() {
return ESConstants.GATEWAY_INDEX_NAME;
}
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESSharedStateComponent.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESSharedStateComponent.java
index 4790942b6d..31c011cf76 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESSharedStateComponent.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/ESSharedStateComponent.java
@@ -179,10 +179,10 @@ protected Object readPrimitive(JestResult result) throws Exception {
}
/**
- * @see io.apiman.gateway.engine.es.AbstractESComponent#getIndexName()
+ * @see io.apiman.gateway.engine.es.AbstractESComponent#getDefaultIndexName()
*/
@Override
- protected String getIndexName() {
+ protected String getDefaultIndexName() {
return ESConstants.GATEWAY_INDEX_NAME;
}
diff --git a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/PollCachingESRegistry.java b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/PollCachingESRegistry.java
index 22b402ec54..5101c1a575 100644
--- a/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/PollCachingESRegistry.java
+++ b/gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/PollCachingESRegistry.java
@@ -51,6 +51,7 @@ public class PollCachingESRegistry extends CachingESRegistry {
/**
* Constructor.
+ * @param config
*/
public PollCachingESRegistry(Map config) {
super(config);
@@ -149,7 +150,7 @@ protected void updateDataVersion() {
DataVersionBean dv = new DataVersionBean();
dv.setUpdatedOn(System.currentTimeMillis());
Index index = new Index.Builder(dv).refresh(false)
- .index(getIndexName())
+ .index(getDefaultIndexName())
.type("dataVersion").id("instance").build(); //$NON-NLS-1$ //$NON-NLS-2$
getClient().executeAsync(index, new JestResultHandler() {
@Override
@@ -200,7 +201,7 @@ protected void checkCacheVersion() {
// Be very aggressive in invalidating the cache.
boolean invalidate = true;
try {
- Get get = new Get.Builder(getIndexName(), "instance").type("dataVersion").build(); //$NON-NLS-1$ //$NON-NLS-2$
+ Get get = new Get.Builder(getDefaultIndexName(), "instance").type("dataVersion").build(); //$NON-NLS-1$ //$NON-NLS-2$
JestResult result = getClient().execute(get);
if (result.isSucceeded()) {
String latestDV = result.getJsonObject().get("_version").getAsString(); //$NON-NLS-1$
diff --git a/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/apiman_gateway-settings.json b/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/apiman_gateway-settings.json
index b63d9f2d61..701147d87c 100644
--- a/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/apiman_gateway-settings.json
+++ b/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/apiman_gateway-settings.json
@@ -12,7 +12,10 @@
},
"client": {
"properties": {
+ "apiKey" : { "type" : "string", "index" : "not_analyzed" },
+ "organizationId": { "type" : "string", "index" : "not_analyzed" },
"clientId": { "type" : "string", "index" : "not_analyzed" },
+ "version": { "type" : "string", "index" : "not_analyzed" },
"contracts": {
"properties": {
"apiKey": { "type" : "string", "index" : "not_analyzed" },
@@ -20,33 +23,8 @@
"apiOrgId": { "type" : "string", "index" : "not_analyzed" },
"apiVersion": { "type" : "string", "index" : "not_analyzed" }
}
- },
- "organizationId": { "type" : "string", "index" : "not_analyzed" },
- "version": { "type" : "string", "index" : "not_analyzed" }
- }
- },
- "apiContract" : {
- "properties" : {
- "apiKey" : { "type" : "string", "index" : "not_analyzed" },
- "plan" : { "type" : "string", "index" : "not_analyzed" },
- "client" : {
- "properties" : {
- "clientId" : { "type" : "string", "index" : "not_analyzed" },
- "organizationId" : { "type" : "string", "index" : "not_analyzed" },
- "version" : { "type" : "string", "index" : "not_analyzed" }
- }
- },
- "api" : {
- "properties" : {
- "endpoint" : { "type" : "string", "index" : "not_analyzed" },
- "endpointType" : { "type" : "string", "index" : "not_analyzed" },
- "organizationId" : { "type" : "string", "index" : "not_analyzed" },
- "publicAPI" : { "type" : "string", "index" : "not_analyzed" },
- "apiId" : { "type" : "string", "index" : "not_analyzed" },
- "version" : { "type" : "string", "index" : "not_analyzed" }
- }
}
}
- }
+ }
}
}
diff --git a/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/i18n/messages.properties b/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/i18n/messages.properties
index 6130dd9241..1207fdf865 100644
--- a/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/i18n/messages.properties
+++ b/gateway/engine/es/src/main/resources/io/apiman/gateway/engine/es/i18n/messages.properties
@@ -1,6 +1,5 @@
ESRegistry.ClientNotFound=Client not found.
ESRegistry.ContractAlreadyPublished=Contract with API Key {0} has already been published.
-ESRegistry.NoContractForAPIKey=No contract found for API Key {0}
ESRegistry.ApiNotFound=API not found.
ESRegistry.ApiNotFoundInOrg=API {0} not found in Organization {1}.
ESRegistry.ApiWasRetired=API {0} in Organization {1} has been retired.
@@ -10,4 +9,6 @@ ESRegistry.ErrorRegisteringClient=Error registering client.
ESRegistry.NoContracts=Client has no contracts.
ESRegistry.ErrorRegisteringContract=Error registering a contract.
ESRegistry.ErrorRetiringApi=Error retiring API.
-ESRegistry.ErrorUnregisteringClient=Error unregistering client.
\ No newline at end of file
+ESRegistry.ErrorUnregisteringClient=Error unregistering client.
+ESRegistry.NoClientForAPIKey=No client found for API Key {0}
+ESRegistry.NoContractFound=No contract found between Client {0} and API {1}.
diff --git a/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/CachingJdbcRegistry.java b/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/CachingJdbcRegistry.java
index cbd6d5fed5..2e729acf87 100644
--- a/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/CachingJdbcRegistry.java
+++ b/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/CachingJdbcRegistry.java
@@ -16,16 +16,15 @@
package io.apiman.gateway.engine.jdbc;
import io.apiman.gateway.engine.async.AsyncResultImpl;
-import io.apiman.gateway.engine.async.IAsyncResult;
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
+import io.apiman.gateway.engine.beans.Client;
+import io.apiman.gateway.engine.beans.Contract;
import io.apiman.gateway.engine.beans.exceptions.InvalidContractException;
import io.apiman.gateway.engine.jdbc.i18n.Messages;
import java.sql.SQLException;
-import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -38,8 +37,8 @@
*/
public abstract class CachingJdbcRegistry extends JdbcRegistry {
- private Map contractCache = new ConcurrentHashMap<>();
- private Map apiCache = new HashMap<>();
+ private Map apiCache = new ConcurrentHashMap<>();
+ private Map clientCache = new ConcurrentHashMap<>();
private Object mutex = new Object();
/**
@@ -55,44 +54,51 @@ public CachingJdbcRegistry(Map config) {
*/
protected void invalidateCache() {
synchronized (mutex) {
- contractCache.clear();
+ clientCache.clear();
apiCache.clear();
}
}
-
+
/**
- * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#getContract(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- public void getContract(final ApiRequest request, final IAsyncResultHandler handler) {
- ApiContract contract;
-
- final String contractKey = getContractKey(request);
- synchronized (mutex) {
- contract = contractCache.get(contractKey);
- }
-
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
+ IAsyncResultHandler handler) {
+ Client client = null;
+ Api api = null;
+
try {
- if (contract == null) {
- super.getContract(request, new IAsyncResultHandler() {
- @Override
- public void handle(IAsyncResult result) {
- if (result.isSuccess()) {
- contractCache.put(contractKey, result.getResult());
- }
- handler.handle(result);
- }
- });
- } else {
- Api api = getApi(request.getApiOrgId(), request.getApiId(), request.getApiVersion());
- if (api == null) {
- throw new InvalidContractException(Messages.i18n.format("ESRegistry.ApiWasRetired", //$NON-NLS-1$
- request.getApiId(), request.getApiOrgId()));
+ synchronized (mutex) {
+ client = getClient(apiKey);
+ api = getApi(apiOrganizationId, apiId, apiVersion);
+ }
+ if (client == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("JdbcRegistry.NoClientForAPIKey", apiKey)); //$NON-NLS-1$
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+ if (api == null) {
+ throw new InvalidContractException(Messages.i18n.format("JdbcRegistry.ApiWasRetired", //$NON-NLS-1$
+ apiId, apiOrganizationId));
+ }
+
+ Contract matchedContract = null;
+ for (Contract contract : client.getContracts()) {
+ if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
+ matchedContract = contract;
+ break;
}
- contract.setApi(api);
- handler.handle(AsyncResultImpl.create(contract));
}
- } catch (Throwable e) {
+
+ if (matchedContract == null) {
+ throw new InvalidContractException(Messages.i18n.format("JdbcRegistry.NoContractFound", //$NON-NLS-1$
+ client.getClientId(), api.getApiId()));
+ }
+
+ ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
+ handler.handle(AsyncResultImpl.create(contract));
+ } catch (Exception e) {
handler.handle(AsyncResultImpl.create(e, ApiContract.class));
}
}
@@ -118,17 +124,17 @@ public void getApi(final String organizationId, final String apiId, final String
* @param version
*/
protected Api getApi(String orgId, String apiId, String version) throws SQLException {
- String apiKey = getApiKey(orgId, apiId, version);
+ String apiIdx = getApiId(orgId, apiId, version);
Api api;
synchronized (mutex) {
- api = apiCache.get(apiKey);
+ api = apiCache.get(apiIdx);
}
if (api == null) {
api = super.getApiInternal(orgId, apiId, version);
synchronized (mutex) {
if (api != null) {
- apiCache.put(apiKey, api);
+ apiCache.put(apiIdx, api);
}
}
}
@@ -137,37 +143,40 @@ protected Api getApi(String orgId, String apiId, String version) throws SQLExcep
}
/**
- * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#checkApi(io.apiman.gateway.engine.beans.ApiContract)
+ * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- protected void checkApi(ApiContract contract) throws InvalidContractException, SQLException {
- Api api = getApi(contract.getApi().getOrganizationId(),
- contract.getApi().getApiId(),
- contract.getApi().getVersion());
- if (api == null) {
- throw new InvalidContractException(Messages.i18n.format("JdbcRegistry.ApiWasRetired", //$NON-NLS-1$
- contract.getApi().getApiId(), contract.getApi().getOrganizationId()));
+ public void getClient(String apiKey, IAsyncResultHandler handler) {
+ try {
+ Client client = getClient(apiKey);
+ handler.handle(AsyncResultImpl.create(client));
+ } catch (SQLException e) {
+ handler.handle(AsyncResultImpl.create(e, Client.class));
}
}
/**
- * Generates an in-memory key for an API, used to index the app for later quick
- * retrieval.
+ * Gets the client either from the cache or from ES.
* @param orgId
- * @param apiId
+ * @param clientId
* @param version
- * @return a API key
*/
- private String getApiKey(String orgId, String apiId, String version) {
- return "API::" + orgId + "|" + apiId + "|" + version; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
+ protected Client getClient(String apiKey) throws SQLException {
+ Client client;
+ synchronized (mutex) {
+ client = clientCache.get(apiKey);
+ }
- /**
- * Generates an in-memory key for a contract.
- * @param request
- */
- private String getContractKey(ApiRequest request) {
- return "CONTRACT::" + request.getApiKey(); //$NON-NLS-1$
- }
+ if (client == null) {
+ client = super.getClientInternal(apiKey);
+ synchronized (mutex) {
+ if (client != null) {
+ clientCache.put(apiKey, client);
+ }
+ }
+ }
+ return client;
+ }
+
}
diff --git a/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/JdbcRegistry.java b/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/JdbcRegistry.java
index 3299f42a5f..f7ddfb9e14 100644
--- a/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/JdbcRegistry.java
+++ b/gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/JdbcRegistry.java
@@ -21,7 +21,6 @@
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.Client;
import io.apiman.gateway.engine.beans.Contract;
import io.apiman.gateway.engine.beans.exceptions.InvalidContractException;
@@ -35,7 +34,6 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -130,8 +128,6 @@ public void publishApi(Api api, IAsyncResultHandler handler) {
*/
@Override
public void registerClient(Client client, IAsyncResultHandler handler) {
- final Map apiMap = new HashMap<>();
-
Connection conn = null;
try {
conn = ds.getConnection();
@@ -139,24 +135,15 @@ public void registerClient(Client client, IAsyncResultHandler handler) {
QueryRunner run = new QueryRunner();
// Validate the client and populate the api map with apis found during validation.
- validateClient(client, apiMap, conn);
+ validateClient(client, conn);
// Remove any old data first, then (re)insert
- run.update(conn, "DELETE FROM contracts WHERE client_org_id = ? AND client_id = ? AND client_version = ?", //$NON-NLS-1$
- client.getOrganizationId(), client.getClientId(), client.getVersion());
run.update(conn, "DELETE FROM clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
client.getOrganizationId(), client.getClientId(), client.getVersion());
String bean = mapper.writeValueAsString(client);
- run.update(conn, "INSERT INTO clients (org_id, id, version, bean) VALUES (?, ?, ?, ?)", //$NON-NLS-1$
- client.getOrganizationId(), client.getClientId(), client.getVersion(), bean);
-
- // Register all the api contracts.
- Set contracts = client.getContracts();
- client.setContracts(null);
- for (Contract contract : contracts) {
- registerContract(client, contract, apiMap, conn);
- }
+ run.update(conn, "INSERT INTO clients (api_key, org_id, id, version, bean) VALUES (?, ?, ?, ?, ?)", //$NON-NLS-1$
+ client.getApiKey(), client.getOrganizationId(), client.getClientId(), client.getVersion(), bean);
DbUtils.commitAndClose(conn);
handler.handle(AsyncResultImpl.create((Void) null));
@@ -181,11 +168,10 @@ protected void unregisterApiContracts(Client client, Connection connection) thro
/**
* Ensures that the api referenced by the Contract actually exists (is published).
* @param contract
- * @param apiMap
* @param connection
* @throws RegistrationException
*/
- private void validateContract(final Contract contract, final Map apiMap, Connection connection)
+ private void validateContract(final Contract contract, Connection connection)
throws RegistrationException {
QueryRunner run = new QueryRunner();
try {
@@ -208,50 +194,23 @@ private void validateContract(final Contract contract, final Map ap
String orgId = contract.getApiOrgId();
throw new RegistrationException(Messages.i18n.format("JdbcRegistry.ApiNotFoundInOrg", apiId, orgId)); //$NON-NLS-1$
}
- api.setApiPolicies(null);
- final String id = getApiId(contract);
- apiMap.put(id, api);
} catch (SQLException e) {
throw new RegistrationException(Messages.i18n.format("JdbcRegistry.ErrorValidatingApp"), e); //$NON-NLS-1$
}
}
- /**
- * Register a single contract by inserting it into the database.
- * @param client
- * @param contracts
- * @param apiMap
- * @param connection
- */
- private void registerContract(final Client client, final Contract contract,
- final Map apiMap, Connection connection) throws RegistrationException {
- QueryRunner run = new QueryRunner();
- try {
- String apiId = getApiId(contract);
- Api api = apiMap.get(apiId);
- ApiContract sc = new ApiContract(contract.getApiKey(), api, client,
- contract.getPlan(), contract.getPolicies());
- String bean = mapper.writeValueAsString(sc);
- run.update(connection, "INSERT INTO contracts (api_key, client_org_id, client_id, client_version, bean) VALUES (?, ?, ?, ?, ?)", //$NON-NLS-1$
- sc.getApikey(), sc.getClient().getOrganizationId(), sc.getClient().getClientId(), sc.getClient().getVersion(), bean);
- } catch (Exception e) {
- throw new RegistrationException(Messages.i18n.format("JdbcRegistry.ErrorRegisteringContract"), e); //$NON-NLS-1$
- }
- }
-
/**
* Validate that the client should be registered.
* @param client
- * @param apiMap
* @param connection
*/
- private void validateClient(Client client, Map apiMap, Connection connection) throws RegistrationException {
+ private void validateClient(Client client, Connection connection) throws RegistrationException {
Set contracts = client.getContracts();
if (contracts.isEmpty()) {
throw new RegistrationException(Messages.i18n.format("JdbcRegistry.NoContracts")); //$NON-NLS-1$
}
for (Contract contract : contracts) {
- validateContract(contract, apiMap, connection);
+ validateContract(contract, connection);
}
}
@@ -275,17 +234,10 @@ public void retireApi(Api api, IAsyncResultHandler handler) {
*/
@Override
public void unregisterClient(Client client, IAsyncResultHandler handler) {
- Connection conn = null;
- QueryRunner run = new QueryRunner();
try {
- conn = ds.getConnection();
- conn.setAutoCommit(false);
- run.update(conn, "DELETE FROM contracts WHERE client_org_id = ? AND client_id = ? AND client_version = ?", //$NON-NLS-1$
- client.getOrganizationId(), client.getClientId(), client.getVersion());
- run.update(conn, "DELETE FROM clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
+ QueryRunner run = new QueryRunner(ds);
+ run.update("DELETE FROM clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
client.getOrganizationId(), client.getClientId(), client.getVersion());
-
- DbUtils.commitAndClose(conn);
handler.handle(AsyncResultImpl.create((Void) null));
} catch (SQLException e) {
handler.handle(AsyncResultImpl.create(new PublishingException(Messages.i18n.format("JdbcRegistry.ErrorUnregisteringApp"), e), Void.class)); //$NON-NLS-1$
@@ -298,15 +250,14 @@ public void unregisterClient(Client client, IAsyncResultHandler handler) {
@Override
public void getApi(String organizationId, String apiId, String apiVersion,
IAsyncResultHandler handler) {
- QueryRunner run = new QueryRunner(ds);
try {
- Api api = getApi(organizationId, apiId, apiVersion, run);
+ Api api = getApiInternal(organizationId, apiId, apiVersion);
handler.handle(AsyncResultImpl.create(api));
} catch (SQLException e) {
handler.handle(AsyncResultImpl.create(e));
}
}
-
+
/**
* Gets an api from the DB.
* @param organizationId
@@ -316,67 +267,84 @@ public void getApi(String organizationId, String apiId, String apiVersion,
*/
protected Api getApiInternal(String organizationId, String apiId, String apiVersion) throws SQLException {
QueryRunner run = new QueryRunner(ds);
- Api api = getApi(organizationId, apiId, apiVersion, run);
- return api;
+ return run.query("SELECT bean FROM apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
+ Handlers.API_HANDLER, organizationId, apiId, apiVersion);
}
/**
- * Gets an API by its orgid, id, version. Return null if not found.
- * @param organizationId
- * @param apiId
- * @param apiVersion
- * @param run
+ * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ */
+ @Override
+ public void getClient(String apiKey, IAsyncResultHandler handler) {
+ try {
+ Client client = getClientInternal(apiKey);
+ handler.handle(AsyncResultImpl.create(client));
+ } catch (SQLException e) {
+ handler.handle(AsyncResultImpl.create(e, Client.class));
+ }
+ }
+
+ /**
+ * Simply pull the client from storage.
+ * @param apiKey
* @throws SQLException
*/
- private Api getApi(String organizationId, String apiId, String apiVersion, QueryRunner run)
- throws SQLException {
- return run.query("SELECT bean FROM apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
- Handlers.API_HANDLER, organizationId, apiId, apiVersion);
+ protected Client getClientInternal(String apiKey) throws SQLException {
+ QueryRunner run = new QueryRunner(ds);
+ return run.query("SELECT bean FROM clients WHERE api_key = ?", //$NON-NLS-1$
+ Handlers.CLIENT_HANDLER, apiKey);
}
/**
- * @see io.apiman.gateway.engine.IRegistry#getContract(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.async.IAsyncResultHandler)
+ * @see io.apiman.gateway.engine.IRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
- public void getContract(ApiRequest request, IAsyncResultHandler handler) {
- QueryRunner run = new QueryRunner(ds);
-
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
+ IAsyncResultHandler handler) {
try {
- ApiContract contract = run.query("SELECT bean FROM contracts WHERE api_key = ?", //$NON-NLS-1$
- Handlers.API_CONTRACT_HANDLER, request.getApiKey());
- if (contract == null) {
- Exception error = new InvalidContractException(Messages.i18n.format("JdbcRegistry.NoContractForAPIKey", request.getApiKey())); //$NON-NLS-1$
+ Client client = getClientInternal(apiKey);
+ Api api = getApiInternal(apiOrganizationId, apiId, apiVersion);
+
+ if (client == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("JdbcRegistry.NoClientForAPIKey", apiKey)); //$NON-NLS-1$
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+ if (api == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("JdbcRegistry.ApiWasRetired", //$NON-NLS-1$
+ apiId, apiOrganizationId));
+ handler.handle(AsyncResultImpl.create(error, ApiContract.class));
+ return;
+ }
+
+ Contract matchedContract = null;
+ for (Contract contract : client.getContracts()) {
+ if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
+ matchedContract = contract;
+ break;
+ }
+ }
+
+ if (matchedContract == null) {
+ Exception error = new InvalidContractException(Messages.i18n.format("JdbcRegistry.NoContractFound", //$NON-NLS-1$
+ client.getClientId(), api.getApiId()));
handler.handle(AsyncResultImpl.create(error, ApiContract.class));
- } else {
- checkApi(contract);
- handler.handle(AsyncResultImpl.create(contract));
+ return;
}
+
+ ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
+ handler.handle(AsyncResultImpl.create(contract));
} catch (Exception e) {
handler.handle(AsyncResultImpl.create(e, ApiContract.class));
}
}
- /**
- * Ensure that the api still exists. If not, it was retired.
- * @param contract
- * @throws InvalidContractException
- * @throws IOException
- */
- protected void checkApi(final ApiContract contract) throws InvalidContractException, SQLException {
- final Api api = contract.getApi();
- Api storedApi = getApi(api.getOrganizationId(), api.getApiId(), api.getVersion(), new QueryRunner(ds));
- if (storedApi == null) {
- throw new InvalidContractException(Messages.i18n.format("JdbcRegistry.ApiWasRetired", //$NON-NLS-1$
- api.getApiId(), api.getOrganizationId()));
- }
- }
-
/**
* Generates a valid document ID for a api referenced by a contract, used to
* retrieve the api from ES.
* @param contract
*/
- private String getApiId(Contract contract) {
+ protected String getApiId(Contract contract) {
return getApiId(contract.getApiOrgId(), contract.getApiId(), contract.getApiVersion());
}
@@ -387,8 +355,8 @@ private String getApiId(Contract contract) {
* @param version
* @return a api key
*/
- private String getApiId(String orgId, String apiId, String version) {
- return orgId + ":" + apiId + ":" + version; //$NON-NLS-1$ //$NON-NLS-2$
+ protected String getApiId(String orgId, String apiId, String version) {
+ return orgId + "|" + apiId + "|" + version; //$NON-NLS-1$ //$NON-NLS-2$
}
private static final class Handlers {
@@ -405,14 +373,14 @@ private static final class Handlers {
}
};
- public static final ResultSetHandler API_CONTRACT_HANDLER = (ResultSet rs) -> {
+ public static final ResultSetHandler CLIENT_HANDLER = (ResultSet rs) -> {
if (!rs.next()) {
return null;
}
Clob clob = rs.getClob(1);
InputStream is = clob.getAsciiStream();
try {
- return mapper.reader(ApiContract.class).readValue(is);
+ return mapper.reader(Client.class).readValue(is);
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/gateway/engine/jdbc/src/main/resources/io/apiman/gateway/engine/jdbc/i18n/messages.properties b/gateway/engine/jdbc/src/main/resources/io/apiman/gateway/engine/jdbc/i18n/messages.properties
index 4676b1f78c..15089f17b1 100644
--- a/gateway/engine/jdbc/src/main/resources/io/apiman/gateway/engine/jdbc/i18n/messages.properties
+++ b/gateway/engine/jdbc/src/main/resources/io/apiman/gateway/engine/jdbc/i18n/messages.properties
@@ -1,6 +1,5 @@
JdbcRegistry.ClientNotFound=Client not found.
JdbcRegistry.ContractAlreadyPublished=Contract with API Key {0} has already been published.
-JdbcRegistry.NoContractForAPIKey=No contract found for API Key {0}
JdbcRegistry.ApiNotFound=API not found.
JdbcRegistry.ApiNotFoundInOrg=API {0} not found in Organization {1}.
JdbcRegistry.ApiWasRetired=API {0} in Organization {1} has been retired.
@@ -10,4 +9,6 @@ JdbcRegistry.ErrorRegisteringClient=Error registering client.
JdbcRegistry.NoContracts=Client has no contracts.
JdbcRegistry.ErrorRegisteringContract=Error registering a contract.
JdbcRegistry.ErrorRetiringApi=Error retiring API.
-JdbcRegistry.ErrorUnregisteringClient=Error unregistering client.
\ No newline at end of file
+JdbcRegistry.ErrorUnregisteringClient=Error unregistering client.
+JdbcRegistry.NoClientForAPIKey=No client found for API Key {0}
+JdbcRegistry.NoContractFound=No contract found between Client {0} and API {1}.
diff --git a/gateway/engine/policies/src/test/java/io/apiman/gateway/engine/policies/RateLimitingPolicyTest.java b/gateway/engine/policies/src/test/java/io/apiman/gateway/engine/policies/RateLimitingPolicyTest.java
index f0a2d67c7f..6c42860fe2 100644
--- a/gateway/engine/policies/src/test/java/io/apiman/gateway/engine/policies/RateLimitingPolicyTest.java
+++ b/gateway/engine/policies/src/test/java/io/apiman/gateway/engine/policies/RateLimitingPolicyTest.java
@@ -139,10 +139,11 @@ private ApiContract createTestContract() {
api.setApiId("Api");
api.setVersion("1.0");
Client app = new Client();
+ app.setApiKey("12345");
app.setOrganizationId("AppOrg");
app.setClientId("App");
app.setVersion("1.0");
- return new ApiContract("12345", api, app, "Gold", null);
+ return new ApiContract(api, app, "Gold", null);
}
}
diff --git a/gateway/engine/vertx-eb-inmemory/src/main/java/io/apiman/gateway/engine/vertxebinmemory/EBInMemoryRegistry.java b/gateway/engine/vertx-eb-inmemory/src/main/java/io/apiman/gateway/engine/vertxebinmemory/EBInMemoryRegistry.java
index b8c92f3261..0d324d4fab 100644
--- a/gateway/engine/vertx-eb-inmemory/src/main/java/io/apiman/gateway/engine/vertxebinmemory/EBInMemoryRegistry.java
+++ b/gateway/engine/vertx-eb-inmemory/src/main/java/io/apiman/gateway/engine/vertxebinmemory/EBInMemoryRegistry.java
@@ -20,7 +20,6 @@
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
import io.apiman.gateway.engine.beans.ApiContract;
-import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.Client;
import io.apiman.gateway.engine.impl.InMemoryRegistry;
import io.apiman.gateway.engine.vertxebinmemory.apis.EBRegistryProxy;
@@ -57,10 +56,16 @@ public EBInMemoryRegistry(Vertx vertx, VertxEngineConfig vxConfig, Map handler) {
+ super.getClient(apiKey, handler);
+ }
+
@Override
- public void getContract(ApiRequest request, IAsyncResultHandler handler) {
- super.getContract(request, handler);
+ public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
+ IAsyncResultHandler handler) {
+ super.getContract(apiOrganizationId, apiId, apiVersion, apiKey, handler);
}
@Override
diff --git a/gateway/test/src/test/java/io/apiman/gateway/test/junit/vertx3/EsResetter.java b/gateway/test/src/test/java/io/apiman/gateway/test/junit/vertx3/EsResetter.java
index 1962585187..645ab781b3 100644
--- a/gateway/test/src/test/java/io/apiman/gateway/test/junit/vertx3/EsResetter.java
+++ b/gateway/test/src/test/java/io/apiman/gateway/test/junit/vertx3/EsResetter.java
@@ -48,7 +48,7 @@ public void reset() {
// and subtly horrible things will happen, and you'll waste a whole day debugging it! :-)
ESClientFactory.clearClientCache();
- getClient().executeAsync(new Delete.Builder(getIndexName()).build(),
+ getClient().executeAsync(new Delete.Builder(getDefaultIndexName()).build(),
new JestResultHandler() {
@Override
@@ -72,7 +72,7 @@ public void failed(Exception ex) {
}
@Override
- protected String getIndexName() {
+ protected String getDefaultIndexName() {
return ESConstants.GATEWAY_INDEX_NAME;
}
}
diff --git a/gateway/test/src/test/resources/test-plan-data/api/clients/001-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/api/clients/001-register-client.resttest
index 15090bb8a1..24a380f7c2 100644
--- a/gateway/test/src/test/resources/test-plan-data/api/clients/001-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/api/clients/001-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "GatewayApiTest",
"clientId" : "test-client",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "GatewayApiTest",
"apiId" : "echo",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/api/clients/002-register-client-invalid.resttest b/gateway/test/src/test/resources/test-plan-data/api/clients/002-register-client-invalid.resttest
index dcde3e6fac..4e1946230e 100644
--- a/gateway/test/src/test/resources/test-plan-data/api/clients/002-register-client-invalid.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/api/clients/002-register-client-invalid.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "GatewayApiTest",
"clientId" : "invalid-test-client",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345_002",
"apiOrgId" : "GatewayApiTest",
"apiId" : "invalid-api",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/api/clients/003-register-client-retired.resttest b/gateway/test/src/test/resources/test-plan-data/api/clients/003-register-client-retired.resttest
index f12f10dc90..77f0d8cda5 100644
--- a/gateway/test/src/test/resources/test-plan-data/api/clients/003-register-client-retired.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/api/clients/003-register-client-retired.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "GatewayApiTest",
"clientId" : "retired-test-client",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345_003",
"apiOrgId" : "GatewayApiTest",
"apiId" : "echo",
"apiVersion" : "3.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/api/clients/004-register-client-duplicate.resttest b/gateway/test/src/test/resources/test-plan-data/api/clients/004-register-client-duplicate.resttest
index 15090bb8a1..24a380f7c2 100644
--- a/gateway/test/src/test/resources/test-plan-data/api/clients/004-register-client-duplicate.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/api/clients/004-register-client-duplicate.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "GatewayApiTest",
"clientId" : "test-client",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "GatewayApiTest",
"apiId" : "echo",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/api/clients/006-reregister-client.resttest b/gateway/test/src/test/resources/test-plan-data/api/clients/006-reregister-client.resttest
index 15090bb8a1..24a380f7c2 100644
--- a/gateway/test/src/test/resources/test-plan-data/api/clients/006-reregister-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/api/clients/006-reregister-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "GatewayApiTest",
"clientId" : "test-client",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "GatewayApiTest",
"apiId" : "echo",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/001-api-1.resttest b/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/001-api-1.resttest
index cf396daae9..0a6a5ac46f 100644
--- a/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/001-api-1.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/001-api-1.resttest
@@ -1,5 +1,5 @@
GET /ClientReregisterTest/echo-1/1.0/path/to/app/resource admin/admin
-X-API-Key: api-1
+X-API-Key: 12345
Accept: application/json
----
diff --git a/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/002-api-2.resttest b/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/002-api-2.resttest
index 89bd264d95..6e74223452 100644
--- a/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/002-api-2.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/002-api-2.resttest
@@ -1,5 +1,5 @@
GET /ClientReregisterTest/echo-2/1.0/path/to/app/resource admin/admin
-X-API-Key: api-2
+X-API-Key: 12345
Accept: application/json
----
diff --git a/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/003-api-1-404.resttest b/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/003-api-1-404.resttest
index 692f73df25..7816d6c118 100644
--- a/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/003-api-1-404.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/client-reregister/echo/003-api-1-404.resttest
@@ -1,5 +1,5 @@
GET /ClientReregisterTest/echo-1/1.0/path/to/app/resource admin/admin
-X-API-Key: api-1
+X-API-Key: 12345
Accept: application/json
----
@@ -8,5 +8,5 @@ Content-Type: application/json
{
"responseCode" : 500,
- "message" : "No contract found for API Key api-1 "
+ "message" : "No contract found between Client test and API echo-1."
}
diff --git a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/003-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/003-register-client.resttest
index d41eb988fe..bc87d5cc8d 100644
--- a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/003-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/003-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "ClientReregisterTest",
"clientId" : "test",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "api-1",
"apiOrgId" : "ClientReregisterTest",
"apiId" : "echo-1",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/004-reregister-client.resttest b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/004-reregister-client.resttest
index 4eebd4d95e..43dcf16aec 100644
--- a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/004-reregister-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/004-reregister-client.resttest
@@ -5,15 +5,14 @@ Content-Type: application/json
"organizationId" : "ClientReregisterTest",
"clientId" : "test",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "api-1",
"apiOrgId" : "ClientReregisterTest",
"apiId" : "echo-1",
"apiVersion" : "1.0"
},
{
- "apiKey" : "api-2",
"apiOrgId" : "ClientReregisterTest",
"apiId" : "echo-2",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/005-break-contract.resttest b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/005-break-contract.resttest
index 935f204099..7512742295 100644
--- a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/005-break-contract.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/005-break-contract.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "ClientReregisterTest",
"clientId" : "test",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "api-2",
"apiOrgId" : "ClientReregisterTest",
"apiId" : "echo-2",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/006-restore-contract-api-1.resttest b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/006-restore-contract-api-1.resttest
index 4eebd4d95e..43dcf16aec 100644
--- a/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/006-restore-contract-api-1.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/client-reregister/setup/006-restore-contract-api-1.resttest
@@ -5,15 +5,14 @@ Content-Type: application/json
"organizationId" : "ClientReregisterTest",
"clientId" : "test",
"version" : "1.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "api-1",
"apiOrgId" : "ClientReregisterTest",
"apiId" : "echo-1",
"apiVersion" : "1.0"
},
{
- "apiKey" : "api-2",
"apiOrgId" : "ClientReregisterTest",
"apiId" : "echo-2",
"apiVersion" : "1.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/perf/overhead/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/perf/overhead/002-register-client.resttest
index 0c16cf8b3e..3a56c443ea 100644
--- a/gateway/test/src/test/resources/test-plan-data/perf/overhead/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/perf/overhead/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "PerfOverheadTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "PerfOverheadTest",
"apiId" : "echo",
"apiVersion" : "1.0.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/002-register-client.resttest
index e61f7c263e..35863aa7a8 100644
--- a/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "Policy_BasicAuthStatic",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "Policy_BasicAuthStatic",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/006-register-client-2.resttest b/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/006-register-client-2.resttest
index f88f75ace4..f5b70f8f08 100644
--- a/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/006-register-client-2.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/policies/basic-auth-static/006-register-client-2.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "Policy_BasicAuthStatic",
"clientId" : "test-require-basic",
"version" : "1.0.0",
+ "apiKey" : "23456",
"contracts" : [
{
- "apiKey" : "23456",
"apiOrgId" : "Policy_BasicAuthStatic",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources-xml/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources-xml/002-register-client.resttest
index 20ccb4dd10..b9ec01e9d7 100644
--- a/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources-xml/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources-xml/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "Policy_IgnoredResourcesXmlTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "Policy_IgnoredResourcesXmlTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources/002-register-client.resttest
index 9eb08803de..44e8206ba6 100644
--- a/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ignored-resources/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "Policy_IgnoredResourcesTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "Policy_IgnoredResourcesTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002-register-client.resttest
deleted file mode 100644
index d0fa1b7c1e..0000000000
--- a/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002-register-client.resttest
+++ /dev/null
@@ -1,60 +0,0 @@
-PUT /clients admin/admin
-Content-Type: application/json
-
-{
- "organizationId" : "Policy_IPBlacklistTest",
- "clientId" : "test",
- "version" : "1.0.0",
- "contracts" : [
- {
- "apiKey" : "12345",
- "apiOrgId" : "Policy_IPBlacklistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
- "policyJsonConfig" : "{ \"ipList\" : [ \"1.2.3.4\" ] }"
- }
- ]
- },
- {
- "apiKey" : "54321",
- "apiOrgId" : "Policy_IPBlacklistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
- "policyJsonConfig" : "{ \"ipList\": [ \"127.0.0.1\" ] }"
- }
- ]
- },
- {
- "apiKey" : "54321_404",
- "apiOrgId" : "Policy_IPBlacklistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
- "policyJsonConfig" : "{ \"responseCode\" : \"404\", \"ipList\": [ \"127.0.0.1\" ] }"
- }
- ]
- },
- {
- "apiKey" : "54321_403",
- "apiOrgId" : "Policy_IPBlacklistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
- "policyJsonConfig" : "{ \"responseCode\" : \"403\", \"ipList\": [ \"127.0.0.1\" ] }"
- }
- ]
- }
- ]
-}
-----
-204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.01-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.01-register-client.resttest
new file mode 100644
index 0000000000..cd07d7ed5b
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.01-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPBlacklistTest",
+ "clientId" : "test.01",
+ "version" : "1.0.0",
+ "apiKey" : "12345",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPBlacklistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
+ "policyJsonConfig" : "{ \"ipList\" : [ \"1.2.3.4\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.02-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.02-register-client.resttest
new file mode 100644
index 0000000000..d776376484
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.02-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPBlacklistTest",
+ "clientId" : "test.02",
+ "version" : "1.0.0",
+ "apiKey" : "54321",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPBlacklistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
+ "policyJsonConfig" : "{ \"ipList\": [ \"127.0.0.1\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.03-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.03-register-client.resttest
new file mode 100644
index 0000000000..4b0541d8f0
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.03-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPBlacklistTest",
+ "clientId" : "test.03",
+ "version" : "1.0.0",
+ "apiKey" : "54321_404",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPBlacklistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
+ "policyJsonConfig" : "{ \"responseCode\" : \"404\", \"ipList\": [ \"127.0.0.1\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.04-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.04-register-client.resttest
new file mode 100644
index 0000000000..b50086ab6e
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-blacklist/002.04-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPBlacklistTest",
+ "clientId" : "test.04",
+ "version" : "1.0.0",
+ "apiKey" : "54321_403",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPBlacklistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPBlacklistPolicy",
+ "policyJsonConfig" : "{ \"responseCode\" : \"403\", \"ipList\": [ \"127.0.0.1\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002-register-client.resttest
deleted file mode 100644
index d083ec04c7..0000000000
--- a/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002-register-client.resttest
+++ /dev/null
@@ -1,60 +0,0 @@
-PUT /clients admin/admin
-Content-Type: application/json
-
-{
- "organizationId" : "Policy_IPWhitelistTest",
- "clientId" : "test",
- "version" : "1.0.0",
- "contracts" : [
- {
- "apiKey" : "12345",
- "apiOrgId" : "Policy_IPWhitelistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
- "policyJsonConfig" : "{ \"ipList\" : [ \"1.2.3.4\" ] }"
- }
- ]
- },
- {
- "apiKey" : "12345_403",
- "apiOrgId" : "Policy_IPWhitelistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
- "policyJsonConfig" : "{ \"responseCode\" : \"403\", \"ipList\" : [ \"1.2.3.4\" ] }"
- }
- ]
- },
- {
- "apiKey" : "12345_404",
- "apiOrgId" : "Policy_IPWhitelistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
- "policyJsonConfig" : "{ \"responseCode\" : \"404\", \"ipList\" : [ \"1.2.3.4\" ] }"
- }
- ]
- },
- {
- "apiKey" : "54321",
- "apiOrgId" : "Policy_IPWhitelistTest",
- "apiId" : "echo",
- "apiVersion" : "1.0.0",
- "policies" : [
- {
- "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
- "policyJsonConfig" : "{ \"ipList\": [ \"127.0.0.1\" ] }"
- }
- ]
- }
- ]
-}
-----
-204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.01-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.01-register-client.resttest
new file mode 100644
index 0000000000..c75924fe1d
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.01-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPWhitelistTest",
+ "clientId" : "test.01",
+ "version" : "1.0.0",
+ "apiKey" : "12345",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPWhitelistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
+ "policyJsonConfig" : "{ \"ipList\" : [ \"1.2.3.4\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.02-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.02-register-client.resttest
new file mode 100644
index 0000000000..05cd4d0090
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.02-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPWhitelistTest",
+ "clientId" : "test.02",
+ "version" : "1.0.0",
+ "apiKey" : "12345_403",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPWhitelistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
+ "policyJsonConfig" : "{ \"responseCode\" : \"403\", \"ipList\" : [ \"1.2.3.4\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.03-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.03-register-client.resttest
new file mode 100644
index 0000000000..806959284f
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.03-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPWhitelistTest",
+ "clientId" : "test.03",
+ "version" : "1.0.0",
+ "apiKey" : "12345_404",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPWhitelistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
+ "policyJsonConfig" : "{ \"responseCode\" : \"404\", \"ipList\" : [ \"1.2.3.4\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.04-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.04-register-client.resttest
new file mode 100644
index 0000000000..481ff5e770
--- /dev/null
+++ b/gateway/test/src/test/resources/test-plan-data/policies/ip-whitelist/002.04-register-client.resttest
@@ -0,0 +1,24 @@
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_IPWhitelistTest",
+ "clientId" : "test.04",
+ "version" : "1.0.0",
+ "apiKey" : "54321",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_IPWhitelistTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.IPWhitelistPolicy",
+ "policyJsonConfig" : "{ \"ipList\": [ \"127.0.0.1\" ] }"
+ }
+ ]
+ }
+ ]
+}
+----
+204
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/rate-limiting/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/rate-limiting/002-register-client.resttest
index e37fdbba7b..2993bf600b 100644
--- a/gateway/test/src/test/resources/test-plan-data/policies/rate-limiting/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/policies/rate-limiting/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "Policy_RateLimitingTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "Policy_RateLimitingTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/policies/time-restricted-access/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/policies/time-restricted-access/002-register-client.resttest
index fc0fb989a1..164208b556 100644
--- a/gateway/test/src/test/resources/test-plan-data/policies/time-restricted-access/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/policies/time-restricted-access/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "Policy_IgnoredResourcesTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "Policy_IgnoredResourcesTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/bean-shared-state-policy/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/bean-shared-state-policy/setup/002-register-client.resttest
index 2257cafaad..78b6c85de0 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/bean-shared-state-policy/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/bean-shared-state-policy/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "BeanSharedStatePolicyTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "BeanSharedStatePolicyTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-conversation-policy/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-conversation-policy/setup/002-register-client.resttest
index 9773ff9e06..72cbf40236 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-conversation-policy/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-conversation-policy/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimpleConversationPolicyTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimpleConversationPolicyTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-data-policy/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-data-policy/setup/002-register-client.resttest
index bd873f0238..a8ed43a601 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-data-policy/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-data-policy/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimpleDataPolicyTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimpleDataPolicyTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-replacement/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-replacement/setup/002-register-client.resttest
index fce7901790..c43ce90dd5 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-replacement/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-replacement/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimpleEchoReplacementTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimpleEchoReplacementTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/errors/000-not-published.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/errors/000-not-published.resttest
index b96a3a5690..bfe0045c79 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/errors/000-not-published.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/errors/000-not-published.resttest
@@ -6,4 +6,4 @@ X-API-Key: 12345
500
Content-Type: application/json
-{"responseCode":500,"message":"No contract found for API Key 12345 "}
\ No newline at end of file
+{"responseCode":500,"message":"No client found for API Key 12345"}
\ No newline at end of file
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/setup/002-register-client.resttest
index 6277d2eb6a..dc42de7887 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimpleEchoTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimpleEchoTest",
"apiId" : "echo",
"apiVersion" : "1.0.0"
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-httpclient-policy/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-httpclient-policy/setup/002-register-client.resttest
index 13db872624..27b7324600 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-httpclient-policy/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-httpclient-policy/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimpleHttpClientPolicyTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimpleHttpClientPolicyTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-httpheader-policy/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-httpheader-policy/setup/002-register-client.resttest
index f6af034cfc..0afd550179 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-httpheader-policy/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-httpheader-policy/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimpleHttpHeaderPolicyTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimpleHttpHeaderPolicyTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-policy/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-policy/setup/002-register-client.resttest
index 47c2375460..0b897c430f 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-policy/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-policy/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimplePolicyTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimplePolicyTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-shared-state-policy/setup/002-register-client.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-shared-state-policy/setup/002-register-client.resttest
index 8985663c6a..96f038642b 100644
--- a/gateway/test/src/test/resources/test-plan-data/simple/simple-shared-state-policy/setup/002-register-client.resttest
+++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-shared-state-policy/setup/002-register-client.resttest
@@ -5,9 +5,9 @@ Content-Type: application/json
"organizationId" : "SimpleSharedStatePolicyTest",
"clientId" : "test",
"version" : "1.0.0",
+ "apiKey" : "12345",
"contracts" : [
{
- "apiKey" : "12345",
"apiOrgId" : "SimpleSharedStatePolicyTest",
"apiId" : "echo",
"apiVersion" : "1.0.0",
diff --git a/gateway/test/src/test/resources/test-plans/policies/ip-blacklist-testPlan.xml b/gateway/test/src/test/resources/test-plans/policies/ip-blacklist-testPlan.xml
index a7a0d88782..fa2a806c56 100644
--- a/gateway/test/src/test/resources/test-plans/policies/ip-blacklist-testPlan.xml
+++ b/gateway/test/src/test/resources/test-plans/policies/ip-blacklist-testPlan.xml
@@ -3,7 +3,10 @@
test-plan-data/policies/ip-blacklist/001-publish-api.resttest
- test-plan-data/policies/ip-blacklist/002-register-client.resttest
+ test-plan-data/policies/ip-blacklist/002.01-register-client.resttest
+ test-plan-data/policies/ip-blacklist/002.02-register-client.resttest
+ test-plan-data/policies/ip-blacklist/002.03-register-client.resttest
+ test-plan-data/policies/ip-blacklist/002.04-register-client.resttest
test-plan-data/policies/ip-blacklist/003-success.resttest
test-plan-data/policies/ip-blacklist/004-failure.resttest
test-plan-data/policies/ip-blacklist/005-failure-404.resttest
diff --git a/gateway/test/src/test/resources/test-plans/policies/ip-whitelist-testPlan.xml b/gateway/test/src/test/resources/test-plans/policies/ip-whitelist-testPlan.xml
index c2f7114cc0..41d5783f8e 100644
--- a/gateway/test/src/test/resources/test-plans/policies/ip-whitelist-testPlan.xml
+++ b/gateway/test/src/test/resources/test-plans/policies/ip-whitelist-testPlan.xml
@@ -3,7 +3,10 @@
test-plan-data/policies/ip-whitelist/001-publish-api.resttest
- test-plan-data/policies/ip-whitelist/002-register-client.resttest
+ test-plan-data/policies/ip-whitelist/002.01-register-client.resttest
+ test-plan-data/policies/ip-whitelist/002.02-register-client.resttest
+ test-plan-data/policies/ip-whitelist/002.03-register-client.resttest
+ test-plan-data/policies/ip-whitelist/002.04-register-client.resttest
test-plan-data/policies/ip-whitelist/003-success.resttest
test-plan-data/policies/ip-whitelist/004-failure.resttest
test-plan-data/policies/ip-whitelist/005-failure-403.resttest
diff --git a/manager/api/beans/pom.xml b/manager/api/beans/pom.xml
index 3d3eed10fd..f116b414ae 100644
--- a/manager/api/beans/pom.xml
+++ b/manager/api/beans/pom.xml
@@ -33,6 +33,11 @@
jackson-databind
provided
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+ provided
+
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiBean.java
index a09cf17aa1..fc54f84300 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiBean.java
@@ -15,10 +15,12 @@
*/
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.manager.api.beans.orgs.OrganizationBasedCompositeId;
import io.apiman.manager.api.beans.orgs.OrganizationBean;
+import java.io.Serializable;
+import java.util.Date;
+
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@@ -27,8 +29,9 @@
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
-import java.io.Serializable;
-import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
/**
* Models an API.
@@ -38,7 +41,7 @@
@Entity
@Table(name = "apis")
@IdClass(OrganizationBasedCompositeId.class)
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ApiBean implements Serializable {
private static final long serialVersionUID = 1526742536153467539L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiDefinitionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiDefinitionBean.java
index 4cd62552fc..010271d6fb 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiDefinitionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiDefinitionBean.java
@@ -15,6 +15,9 @@
*/
package io.apiman.manager.api.beans.apis;
+import java.io.Serializable;
+import java.util.Arrays;
+
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
@@ -22,8 +25,6 @@
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
-import java.io.Serializable;
-import java.util.Arrays;
/**
* Bean used to store an API definition.
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiGatewayBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiGatewayBean.java
index ae9335a2f6..751ce14646 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiGatewayBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiGatewayBean.java
@@ -15,9 +15,10 @@
*/
package io.apiman.manager.api.beans.apis;
+import java.io.Serializable;
+
import javax.persistence.Column;
import javax.persistence.Embeddable;
-import java.io.Serializable;
/**
* Models a gateway that an API should be published to.
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiPlanBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiPlanBean.java
index cece8c3d2e..657d61ae94 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiPlanBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiPlanBean.java
@@ -15,9 +15,10 @@
*/
package io.apiman.manager.api.beans.apis;
+import java.io.Serializable;
+
import javax.persistence.Column;
import javax.persistence.Embeddable;
-import java.io.Serializable;
/**
* Models a plan+version that is available for use with a particular API. This
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionBean.java
index a3df452bc3..3053b20fab 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionBean.java
@@ -15,7 +15,11 @@
*/
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
@@ -32,11 +36,9 @@
import javax.persistence.MapKeyColumn;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
/**
* Models a single version of an API. Every API in APIMan has basic meta-data
@@ -49,7 +51,7 @@
@Entity
@Table(name = "api_versions",
uniqueConstraints = { @UniqueConstraint(columnNames = { "api_id", "api_org_id", "version" }) })
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ApiVersionBean implements Serializable {
private static final long serialVersionUID = -2218697175049442690L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionStatusBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionStatusBean.java
index 17a2ad31fc..6898df6731 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionStatusBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/ApiVersionStatusBean.java
@@ -16,11 +16,12 @@
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.util.ArrayList;
import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A simple status bean for a version of an API. This bean includes
* information about the list of tasks that must be completed before an
@@ -29,7 +30,7 @@
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ApiVersionStatusBean {
private ApiStatus status;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiBean.java
index c9c1c38c98..c8a6820042 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiBean.java
@@ -15,17 +15,18 @@
*/
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Set;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when creating an API.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class NewApiBean implements Serializable {
private static final long serialVersionUID = 8811488441452291116L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiDefinitionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiDefinitionBean.java
index 31486ee51f..d12b2271ec 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiDefinitionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiDefinitionBean.java
@@ -15,16 +15,17 @@
*/
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when updating an API definition via a URL.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class NewApiDefinitionBean implements Serializable {
private static final long serialVersionUID = 8305206288757642775L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiVersionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiVersionBean.java
index da5ccea6c1..89d7c3860a 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiVersionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/NewApiVersionBean.java
@@ -15,17 +15,18 @@
*/
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Set;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when creating a new version of an API.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class NewApiVersionBean implements Serializable {
private static final long serialVersionUID = 7207058698209555294L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/StatusItemBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/StatusItemBean.java
index 00dea63025..c22eb9e26e 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/StatusItemBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/StatusItemBean.java
@@ -16,14 +16,15 @@
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
/**
* A single item in the API status.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class StatusItemBean {
private String id;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiBean.java
index a8d36769f3..84ffa7886e 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiBean.java
@@ -15,10 +15,10 @@
*/
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
/**
* Bean used when updating an API.
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiVersionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiVersionBean.java
index e3d469eaec..e3bd8be793 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiVersionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/UpdateApiVersionBean.java
@@ -15,20 +15,21 @@
*/
package io.apiman.manager.api.beans.apis;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when updating a version of an API.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class UpdateApiVersionBean implements Serializable {
private static final long serialVersionUID = 4126848584932708146L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ApiKeyBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ApiKeyBean.java
new file mode 100644
index 0000000000..4e191f0c4e
--- /dev/null
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ApiKeyBean.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2014 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.apiman.manager.api.beans.clients;
+
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
+/**
+ * Bean used when updating the API Key for a client. This allows you to either
+ * provide your own custom API key *or* let apiman generate a new one.
+ *
+ * @author eric.wittmann@redhat.com
+ */
+@JsonInclude(Include.NON_NULL)
+public class ApiKeyBean implements Serializable {
+
+ private static final long serialVersionUID = -137553871443650975L;
+
+ private String apiKey;
+
+ /**
+ * Constructor.
+ */
+ public ApiKeyBean() {
+ }
+
+ /**
+ * @return the apiKey
+ */
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ /**
+ * @param apiKey the apiKey to set
+ */
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
+}
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientBean.java
index 1a678d5512..49b8976ca5 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientBean.java
@@ -15,7 +15,6 @@
*/
package io.apiman.manager.api.beans.clients;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.manager.api.beans.orgs.OrganizationBasedCompositeId;
import io.apiman.manager.api.beans.orgs.OrganizationBean;
@@ -31,6 +30,9 @@
import javax.persistence.ManyToOne;
import javax.persistence.Table;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models a client.
*
@@ -39,7 +41,7 @@
@Entity
@Table(name = "clients")
@IdClass(OrganizationBasedCompositeId.class)
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ClientBean implements Serializable {
private static final long serialVersionUID = -197129444021040365L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientVersionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientVersionBean.java
index e1bddc7dfd..e3b1347626 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientVersionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/ClientVersionBean.java
@@ -15,8 +15,6 @@
*/
package io.apiman.manager.api.beans.clients;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Date;
@@ -32,6 +30,9 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models a single version of a client "impl". Every client in
* APIMan has basic meta-data stored in {@link ClientBean}. All
@@ -43,8 +44,10 @@
*/
@Entity
@Table(name = "client_versions",
- uniqueConstraints = { @UniqueConstraint(columnNames = { "client_id", "client_org_id", "version" }) })
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+ uniqueConstraints = {
+ @UniqueConstraint(columnNames = { "client_id", "client_org_id", "version" }),
+ @UniqueConstraint(columnNames = { "apikey" })})
+@JsonInclude(Include.NON_NULL)
public class ClientVersionBean implements Serializable {
private static final long serialVersionUID = -2218697175049442690L;
@@ -74,6 +77,8 @@ public class ClientVersionBean implements Serializable {
private Date publishedOn;
@Column(name = "retired_on")
private Date retiredOn;
+ @Column(updatable=true, nullable=false)
+ private String apikey;
/**
* Constructor.
@@ -221,6 +226,20 @@ public void setModifiedOn(Date modifiedOn) {
this.modifiedOn = modifiedOn;
}
+ /**
+ * @return the apikey
+ */
+ public String getApikey() {
+ return apikey;
+ }
+
+ /**
+ * @param apikey the apikey to set
+ */
+ public void setApikey(String apikey) {
+ this.apikey = apikey;
+ }
+
/**
* @see java.lang.Object#hashCode()
*/
@@ -261,7 +280,7 @@ public String toString() {
return "ClientVersionBean [id=" + id + ", client=" + client + ", status=" + status
+ ", version=" + version + ", createdBy=" + createdBy + ", createdOn=" + createdOn
+ ", modifiedBy=" + modifiedBy + ", modifiedOn=" + modifiedOn + ", publishedOn="
- + publishedOn + ", retiredOn=" + retiredOn + "]";
+ + publishedOn + ", retiredOn=" + retiredOn + ", apikey=" + apikey + "]";
}
}
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientBean.java
index 8e66e10b2d..5d31d624d2 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientBean.java
@@ -15,10 +15,10 @@
*/
package io.apiman.manager.api.beans.clients;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
/**
* Bean used when creating a client.
*
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientVersionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientVersionBean.java
index 8b5ba51bd6..c677cd1325 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientVersionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/NewClientVersionBean.java
@@ -15,16 +15,17 @@
*/
package io.apiman.manager.api.beans.clients;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when creating a new client version.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class NewClientVersionBean implements Serializable {
private static final long serialVersionUID = 960818800225855945L;
@@ -33,6 +34,8 @@ public class NewClientVersionBean implements Serializable {
private boolean clone;
private String cloneVersion;
+ private String apiKey;
+
/**
* Constructor.
*/
@@ -81,6 +84,20 @@ public void setCloneVersion(String cloneVersion) {
this.cloneVersion = cloneVersion;
}
+ /**
+ * @return the apiKey
+ */
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ /**
+ * @param apiKey the apiKey to set
+ */
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/UpdateClientBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/UpdateClientBean.java
index e48cf3c482..93561f11c0 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/UpdateClientBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/clients/UpdateClientBean.java
@@ -15,16 +15,17 @@
*/
package io.apiman.manager.api.beans.clients;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when updating an client.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class UpdateClientBean implements Serializable {
private static final long serialVersionUID = 5549391329361400489L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/ContractBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/ContractBean.java
index 1c0548aeba..def6f0e549 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/ContractBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/ContractBean.java
@@ -43,7 +43,7 @@
*/
@Entity
@Table(name = "contracts",
- uniqueConstraints = { @UniqueConstraint(columnNames = { "clientv_id", "apiv_id", "planv_id" }) })
+ uniqueConstraints = { @UniqueConstraint(columnNames = { "clientv_id", "apiv_id" }) })
public class ContractBean implements Serializable {
private static final long serialVersionUID = -8534463608508756791L;
@@ -69,8 +69,6 @@ public class ContractBean implements Serializable {
private String createdBy;
@Column(name = "created_on", updatable=false, nullable=false)
private Date createdOn;
- @Column(updatable=false, nullable=false)
- private String apikey;
/**
* Constructor.
@@ -162,20 +160,6 @@ public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
- /**
- * @return the apikey
- */
- public String getApikey() {
- return apikey;
- }
-
- /**
- * @param apikey the apikey to set
- */
- public void setApikey(String apikey) {
- this.apikey = apikey;
- }
-
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -183,7 +167,7 @@ public void setApikey(String apikey) {
@SuppressWarnings("nls")
public String toString() {
return "ContractBean [id=" + id + ", client=" + client + ", api=" + api + ", plan="
- + plan + ", createdBy=" + createdBy + ", createdOn=" + createdOn + ", apikey=" + apikey + "]";
+ + plan + ", createdBy=" + createdBy + ", createdOn=" + createdOn + "]";
}
}
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/NewContractBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/NewContractBean.java
index 666899d484..1d0f16b9de 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/NewContractBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/contracts/NewContractBean.java
@@ -31,7 +31,6 @@ public class NewContractBean implements Serializable {
private String apiVersion;
private String planId;
- private String apiKey;
/**
* Constructor.
@@ -99,20 +98,6 @@ public void setPlanId(String planId) {
this.planId = planId;
}
- /**
- * @return the contractKey
- */
- public String getApiKey() {
- return apiKey;
- }
-
- /**
- * @param apiKey to set
- */
- public void setApiKey(String apiKey) {
- this.apiKey = apiKey;
- }
-
/**
* @see java.lang.Object#hashCode()
*/
@@ -124,7 +109,6 @@ public int hashCode() {
result = prime * result + ((apiId == null) ? 0 : apiId.hashCode());
result = prime * result + ((apiOrgId == null) ? 0 : apiOrgId.hashCode());
result = prime * result + ((apiVersion == null) ? 0 : apiVersion.hashCode());
- result = prime * result + ((apiKey == null) ? 0 : apiKey.hashCode());
return result;
}
@@ -160,11 +144,6 @@ public boolean equals(Object obj) {
return false;
} else if (!apiVersion.equals(other.apiVersion))
return false;
- if (apiKey == null) {
- if (other.apiKey != null)
- return false;
- } else if (!apiKey.equals(other.apiKey))
- return false;
return true;
}
@@ -175,7 +154,7 @@ public boolean equals(Object obj) {
@SuppressWarnings("nls")
public String toString() {
return "NewContractBean [apiOrgId=" + apiOrgId + ", apiId=" + apiId + ", apiVersion=" + apiVersion
- + ", planId=" + planId + ", apiKey=" + apiKey + "]";
+ + ", planId=" + planId + "]";
}
}
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/gateways/GatewayBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/gateways/GatewayBean.java
index 7c0641a6c6..7e0fb49674 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/gateways/GatewayBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/gateways/GatewayBean.java
@@ -15,7 +15,6 @@
*/
package io.apiman.manager.api.beans.gateways;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.common.util.crypt.CurrentDataEncrypter;
import java.io.Serializable;
@@ -36,6 +35,9 @@
import org.hibernate.annotations.Type;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models a single gateway configured by an admin. When publishing APIs,
* the user must specific which Gateway to publish to.
@@ -44,7 +46,7 @@
*/
@Entity
@Table(name = "gateways")
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class GatewayBean implements Serializable {
private static final long serialVersionUID = 388316225715740602L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/NewOrganizationBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/NewOrganizationBean.java
index e23892a2c3..ec744ce680 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/NewOrganizationBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/NewOrganizationBean.java
@@ -15,17 +15,18 @@
*/
package io.apiman.manager.api.beans.orgs;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when creating a new organization.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class NewOrganizationBean implements Serializable {
private static final long serialVersionUID = 6967624347251134433L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/OrganizationBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/OrganizationBean.java
index 0a06d04e65..b23ff28757 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/OrganizationBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/OrganizationBean.java
@@ -15,8 +15,6 @@
*/
package io.apiman.manager.api.beans.orgs;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Date;
@@ -25,6 +23,9 @@
import javax.persistence.Id;
import javax.persistence.Table;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* An APIMan Organization. This is an important top level entity in the APIMan
* data model. It contains the APIs, Plans, etc.
@@ -33,7 +34,7 @@
*/
@Entity
@Table(name = "organizations")
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class OrganizationBean implements Serializable {
private static final long serialVersionUID = -506427154633682906L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/UpdateOrganizationBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/UpdateOrganizationBean.java
index fec88afebc..12627624b5 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/UpdateOrganizationBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/orgs/UpdateOrganizationBean.java
@@ -15,16 +15,17 @@
*/
package io.apiman.manager.api.beans.orgs;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when updating an organization.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class UpdateOrganizationBean implements Serializable {
private static final long serialVersionUID = 2687797041244565943L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/NewPlanBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/NewPlanBean.java
index a3284ecb68..0b281edd6e 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/NewPlanBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/NewPlanBean.java
@@ -15,15 +15,16 @@
*/
package io.apiman.manager.api.beans.plans;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when creating a plan.
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class NewPlanBean implements Serializable {
private static final long serialVersionUID = 3950418276301140111L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/PlanBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/PlanBean.java
index 902c296fd1..1aaedb4568 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/PlanBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/PlanBean.java
@@ -15,7 +15,6 @@
*/
package io.apiman.manager.api.beans.plans;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.manager.api.beans.orgs.OrganizationBasedCompositeId;
import io.apiman.manager.api.beans.orgs.OrganizationBean;
@@ -31,6 +30,9 @@
import javax.persistence.ManyToOne;
import javax.persistence.Table;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models a plan.
*
@@ -39,7 +41,7 @@
@Entity
@Table(name = "plans")
@IdClass(OrganizationBasedCompositeId.class)
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class PlanBean implements Serializable {
private static final long serialVersionUID = -7961331943587584049L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/UpdatePlanBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/UpdatePlanBean.java
index 0f6df67340..759dbcdc28 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/UpdatePlanBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plans/UpdatePlanBean.java
@@ -15,16 +15,17 @@
*/
package io.apiman.manager.api.beans.plans;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Bean used when creating a plan.
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class UpdatePlanBean implements Serializable {
private static final long serialVersionUID = 5836879095486293752L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/NewPluginBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/NewPluginBean.java
index fb80784053..3f65e40a82 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/NewPluginBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/NewPluginBean.java
@@ -15,16 +15,17 @@
*/
package io.apiman.manager.api.beans.plugins;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models a single plugin when creating.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class NewPluginBean implements Serializable {
private static final long serialVersionUID = 3246882829241218365L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/PluginBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/PluginBean.java
index 214d9112fb..a5a88634ae 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/PluginBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/plugins/PluginBean.java
@@ -15,8 +15,6 @@
*/
package io.apiman.manager.api.beans.plugins;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Date;
@@ -27,6 +25,9 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models a single plugin configured by an admin.
*
@@ -34,7 +35,7 @@
*/
@Entity
@Table(name = "plugins", uniqueConstraints = { @UniqueConstraint(columnNames = { "group_id", "artifact_id" }) })
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class PluginBean implements Serializable {
private static final long serialVersionUID = 2932636903455749308L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyBean.java
index 6b4baed598..023acc3f73 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyBean.java
@@ -15,7 +15,6 @@
*/
package io.apiman.manager.api.beans.policies;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.common.util.crypt.CurrentDataEncrypter;
import java.io.Serializable;
@@ -40,6 +39,9 @@
import org.hibernate.annotations.Type;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A Policy is the primary unit of work for the runtime engine, which is
* essentially a chain of policies that are applied to the Request and
@@ -49,7 +51,7 @@
*/
@Entity
@Table(name = "policies")
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class PolicyBean implements Serializable {
private static final long serialVersionUID = -8534463608508756791L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyChainBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyChainBean.java
index 0f0c67b4e1..5c9d17aab6 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyChainBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyChainBean.java
@@ -15,13 +15,14 @@
*/
package io.apiman.manager.api.beans.policies;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.manager.api.beans.summary.PolicySummaryBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
/**
* Models the list of policies that would get applied if an API were invoked
* via a particular plan.
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyDefinitionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyDefinitionBean.java
index a663556c8d..97a1007780 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyDefinitionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyDefinitionBean.java
@@ -15,7 +15,6 @@
*/
package io.apiman.manager.api.beans.policies;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.manager.api.beans.summary.PolicyFormType;
import java.io.Serializable;
@@ -35,6 +34,9 @@
import javax.persistence.JoinColumn;
import javax.persistence.Table;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A Policy Definition describes a type of policy that can be added to
@@ -45,7 +47,7 @@
*/
@Entity
@Table(name = "policydefs")
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class PolicyDefinitionBean implements Serializable {
private static final long serialVersionUID = 1801150127602136865L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/UpdatePolicyDefinitionBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/UpdatePolicyDefinitionBean.java
index 0faa51fe59..125e0b4e42 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/UpdatePolicyDefinitionBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/UpdatePolicyDefinitionBean.java
@@ -15,16 +15,17 @@
*/
package io.apiman.manager.api.beans.policies;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* The bean/model used when updating a new policy definition.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class UpdatePolicyDefinitionBean implements Serializable {
private static final long serialVersionUID = 350049376316732992L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiCatalogBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiCatalogBean.java
index 860383feac..3e639b5559 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiCatalogBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiCatalogBean.java
@@ -15,17 +15,18 @@
*/
package io.apiman.manager.api.beans.summary;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models an API catalog.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ApiCatalogBean implements Serializable {
private static final long serialVersionUID = 2410545128036209373L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiEntryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiEntryBean.java
index 0c3dde607c..cd737d4868 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiEntryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiEntryBean.java
@@ -15,19 +15,20 @@
*/
package io.apiman.manager.api.beans.summary;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A single entry in the {@link ApiRegistryBean}.
*
* @author eric.wittmann@redhat.com
*/
@XmlRootElement(name = "api")
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ApiEntryBean implements Serializable {
private static final long serialVersionUID = -7578173174922025902L;
@@ -43,7 +44,6 @@ public class ApiEntryBean implements Serializable {
private String planVersion;
private String httpEndpoint;
- private String apiKey;
private String gatewayId;
@@ -179,20 +179,6 @@ public void setHttpEndpoint(String httpEndpoint) {
this.httpEndpoint = httpEndpoint;
}
- /**
- * @return the apiKey
- */
- public String getApiKey() {
- return apiKey;
- }
-
- /**
- * @param apiKey the apiKey to set
- */
- public void setApiKey(String apiKey) {
- this.apiKey = apiKey;
- }
-
/**
* @return the gatewayId
*/
@@ -216,7 +202,7 @@ public String toString() {
return "ApiEntryBean [apiOrgId=" + apiOrgId + ", apiOrgName=" + apiOrgName
+ ", apiId=" + apiId + ", apiName=" + apiName + ", apiVersion="
+ apiVersion + ", planId=" + planId + ", planName=" + planName + ", planVersion="
- + planVersion + ", httpEndpoint=" + httpEndpoint + ", apiKey=" + apiKey + ", gatewayId="
+ + planVersion + ", httpEndpoint=" + httpEndpoint + ", gatewayId="
+ gatewayId + "]";
}
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiRegistryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiRegistryBean.java
index 00ad9bf546..1d0bfb3326 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiRegistryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiRegistryBean.java
@@ -37,6 +37,7 @@ public class ApiRegistryBean implements Serializable {
private static final long serialVersionUID = 7369169626368271089L;
+ private String apiKey;
private List apis = new ArrayList<>();
/**
@@ -59,6 +60,20 @@ public void setApis(List apis) {
this.apis = apis;
}
+ /**
+ * @return the apiKey
+ */
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ /**
+ * @param apiKey the apiKey to set
+ */
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -66,7 +81,7 @@ public void setApis(List apis) {
@SuppressWarnings("nls")
public String toString() {
final int maxLen = 10;
- return "ApiRegistryBean [apis="
+ return "ApiRegistryBean [apiKey=" + apiKey + ", apis="
+ (apis != null ? apis.subList(0, Math.min(apis.size(), maxLen)) : null) + "]";
}
}
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiSummaryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiSummaryBean.java
index a6bbbfd217..180d44a6ed 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiSummaryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ApiSummaryBean.java
@@ -15,11 +15,12 @@
*/
package io.apiman.manager.api.beans.summary;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A bean modeling a summary of an API. Typically used when listing
@@ -27,7 +28,7 @@
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ApiSummaryBean implements Serializable {
private static final long serialVersionUID = -4213543715123177461L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/AvailableApiBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/AvailableApiBean.java
index ee015771dd..1caa38a9e7 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/AvailableApiBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/AvailableApiBean.java
@@ -15,19 +15,21 @@
*/
package io.apiman.manager.api.beans.summary;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.apiman.manager.api.beans.apis.ApiDefinitionType;
import io.apiman.manager.api.beans.apis.EndpointType;
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A bean modeling an API available in one of the configured API catalogs.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class AvailableApiBean implements Serializable {
private static final long serialVersionUID = 8809181555186141741L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientSummaryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientSummaryBean.java
index 75eaac5e8d..51f0ca3ca5 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientSummaryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientSummaryBean.java
@@ -15,17 +15,18 @@
*/
package io.apiman.manager.api.beans.summary;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A bean modeling a summary of a Client. Typically used when listing
* all Clients visible to a user.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ClientSummaryBean implements Serializable {
private static final long serialVersionUID = -4213543715123177461L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientVersionSummaryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientVersionSummaryBean.java
index e2287af9ac..a04e413cc1 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientVersionSummaryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ClientVersionSummaryBean.java
@@ -36,6 +36,7 @@ public class ClientVersionSummaryBean implements Serializable {
private String description;
private ClientStatus status;
private String version;
+ private String apiKey;
/**
* Constructor.
@@ -149,7 +150,21 @@ public void setVersion(String version) {
public String toString() {
return "ClientVersionSummaryBean [organizationId=" + organizationId + ", organizationName="
+ organizationName + ", id=" + id + ", name=" + name + ", description=" + description
- + ", status=" + status + ", version=" + version + "]";
+ + ", status=" + status + ", version=" + version + ", apiKey=" + apiKey + "]";
+ }
+
+ /**
+ * @return the apiKey
+ */
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ /**
+ * @param apiKey the apiKey to set
+ */
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
}
}
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ContractSummaryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ContractSummaryBean.java
index 9f5fed6ac8..b5fd60feca 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ContractSummaryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/ContractSummaryBean.java
@@ -29,7 +29,6 @@ public class ContractSummaryBean implements Serializable {
private static final long serialVersionUID = 1412354024017539782L;
private Long contractId;
- private String apikey;
private String clientOrganizationId;
private String clientOrganizationName;
private String clientId;
@@ -276,20 +275,6 @@ public void setApiName(String apiName) {
this.apiName = apiName;
}
- /**
- * @return the apikey
- */
- public String getApikey() {
- return apikey;
- }
-
- /**
- * @param apikey the apikey to set
- */
- public void setApikey(String apikey) {
- this.apikey = apikey;
- }
-
/**
* @see java.lang.Object#hashCode()
*/
@@ -327,7 +312,7 @@ public boolean equals(Object obj) {
@Override
@SuppressWarnings("nls")
public String toString() {
- return "ContractSummaryBean [contractId=" + contractId + ", apikey=" + apikey
+ return "ContractSummaryBean [contractId=" + contractId
+ ", clientOrganizationId=" + clientOrganizationId + ", clientOrganizationName=" + clientOrganizationName
+ ", clientId=" + clientId + ", clientName=" + clientName + ", clientVersion=" + clientVersion
+ ", apiOrganizationId=" + apiOrganizationId + ", apiOrganizationName="
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PlanSummaryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PlanSummaryBean.java
index 455febc8fd..6cee0a34f2 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PlanSummaryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PlanSummaryBean.java
@@ -15,17 +15,18 @@
*/
package io.apiman.manager.api.beans.summary;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* A bean modeling a summary of a Plan. Typically used when listing
* plans in an org.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class PlanSummaryBean implements Serializable {
private static final long serialVersionUID = -8380665445108131206L;
diff --git a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PluginSummaryBean.java b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PluginSummaryBean.java
index 6c02c39d4d..05d0c3dd5f 100644
--- a/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PluginSummaryBean.java
+++ b/manager/api/beans/src/main/java/io/apiman/manager/api/beans/summary/PluginSummaryBean.java
@@ -15,18 +15,19 @@
*/
package io.apiman.manager.api.beans.summary;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
import java.io.Serializable;
import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
/**
* Models a single gateway configured by an admin. When publishing APIs,
* the user must specific which Plugin to publish to.
*
* @author eric.wittmann@redhat.com
*/
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class PluginSummaryBean implements Serializable {
private static final long serialVersionUID = 7157863269972852063L;
diff --git a/manager/api/es/src/main/java/io/apiman/manager/api/es/EsMarshalling.java b/manager/api/es/src/main/java/io/apiman/manager/api/es/EsMarshalling.java
index 4383fd22d6..d5cc2e74c5 100644
--- a/manager/api/es/src/main/java/io/apiman/manager/api/es/EsMarshalling.java
+++ b/manager/api/es/src/main/java/io/apiman/manager/api/es/EsMarshalling.java
@@ -188,7 +188,6 @@ public static XContentBuilder marshall(ContractBean bean) throws StorageExceptio
builder
.startObject()
.field("id", bean.getId())
- .field("apiKey", bean.getApikey())
.field("clientOrganizationId", bean.getClient().getClient().getOrganization().getId())
.field("clientOrganizationName", bean.getClient().getClient().getOrganization().getName())
.field("clientId", bean.getClient().getClient().getId())
@@ -412,6 +411,7 @@ public static XContentBuilder marshall(ClientVersionBean bean) throws StorageExc
.field("clientName", client.getName())
.field("clientDescription", client.getDescription())
.field("version", bean.getVersion())
+ .field("apikey", bean.getApikey())
.field("status", bean.getStatus())
.field("createdBy", bean.getCreatedBy())
.field("createdOn", bean.getCreatedOn().getTime())
@@ -760,7 +760,6 @@ public static ContractBean unmarshallContract(Map source) {
}
ContractBean bean = new ContractBean();
bean.setId(asLong(source.get("id")));
- bean.setApikey(asString(source.get("apiKey")));
bean.setCreatedBy(asString(source.get("createdBy")));
bean.setCreatedOn(asDate(source.get("createdOn")));
postMarshall(bean);
@@ -778,7 +777,6 @@ public static ContractSummaryBean unmarshallContractSummary(Map
}
ContractSummaryBean bean = new ContractSummaryBean();
bean.setContractId(asLong(source.get("id")));
- bean.setApikey(asString(source.get("apiKey")));
bean.setCreatedOn(asDate(source.get("createdOn")));
bean.setClientOrganizationId(asString(source.get("clientOrganizationId")));
bean.setClientOrganizationName(asString(source.get("clientOrganizationName")));
@@ -808,7 +806,6 @@ public static ApiEntryBean unmarshallApiEntry(Map source) {
return null;
}
ApiEntryBean bean = new ApiEntryBean();
- bean.setApiKey(asString(source.get("apiKey")));
bean.setApiOrgId(asString(source.get("apiOrganizationId")));
bean.setApiOrgName(asString(source.get("apiOrganizationName")));
bean.setApiId(asString(source.get("apiId")));
@@ -1066,6 +1063,7 @@ public static ClientVersionBean unmarshallClientVersion(Map sour
}
ClientVersionBean bean = new ClientVersionBean();
bean.setVersion(asString(source.get("version")));
+ bean.setApikey(asString(source.get("apikey")));
bean.setStatus(asEnum(source.get("status"), ClientStatus.class));
bean.setCreatedBy(asString(source.get("createdBy")));
bean.setCreatedOn(asDate(source.get("createdOn")));
@@ -1094,6 +1092,7 @@ public static ClientVersionSummaryBean unmarshallClientVersionSummary(Map aggregateContractPolicies(ContractBean contractBean, Entity
*/
private void importContracts() throws StorageException {
for (ContractBean contract : contracts) {
- logger.info(Messages.i18n.format("StorageImportDispatcher.ImportingClientContract") + contract.getApikey()); //$NON-NLS-1$
+ logger.info(Messages.i18n.format("StorageImportDispatcher.ImportingClientContract")); //$NON-NLS-1$
String clientId = contract.getClient().getClient().getId();
String clientOrganizationId = contract.getClient().getClient().getOrganization().getId();
String clientVersion = contract.getClient().getVersion();
diff --git a/manager/api/export-import/src/main/resources/io/apiman/manager/api/exportimport/i18n/messages.properties b/manager/api/export-import/src/main/resources/io/apiman/manager/api/exportimport/i18n/messages.properties
index 3121b23f41..a3afe29f45 100644
--- a/manager/api/export-import/src/main/resources/io/apiman/manager/api/exportimport/i18n/messages.properties
+++ b/manager/api/export-import/src/main/resources/io/apiman/manager/api/exportimport/i18n/messages.properties
@@ -1,7 +1,7 @@
StorageImportDispatcher.StartingImport=Starting apiman data import.
StorageImportDispatcher.FromVersion=Importing data from apiman version:
StorageImportDispatcher.ImportingClient=\ \ Importing a client:
-StorageImportDispatcher.ImportingClientContract=+Importing a client contract:
+StorageImportDispatcher.ImportingClientContract=Importing a client contract.
StorageImportDispatcher.ImportingClientPolicy=\ \ \ \ \ \ Importing a client policy:
StorageImportDispatcher.ImportingClientVersion=\ \ \ \ Importing a client version:
StorageImportDispatcher.ImportingAuditEntry=\ \ Importing an audit entry:
diff --git a/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java b/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java
index 8b0f34a756..b4baa50a22 100644
--- a/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java
+++ b/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java
@@ -166,6 +166,16 @@ public void createClientVersion(ClientVersionBean version) throws StorageExcepti
*/
@Override
public void createContract(ContractBean contract) throws StorageException {
+ List contracts = getClientContractsInternal(contract.getClient().getClient().getOrganization().getId(),
+ contract.getClient().getClient().getId(), contract.getClient().getVersion());
+ for (ContractSummaryBean csb : contracts) {
+ if (csb.getApiOrganizationId().equals(contract.getApi().getApi().getOrganization().getId()) &&
+ csb.getApiId().equals(contract.getApi().getApi().getId()) &&
+ csb.getApiVersion().equals(contract.getApi().getVersion()))
+ {
+ throw new StorageException("Error creating contract: duplicate contract detected."); //$NON-NLS-1$
+ }
+ }
super.create(contract);
}
@@ -1217,7 +1227,6 @@ public List getContracts(String organizationId, String apiI
ContractSummaryBean csb = new ContractSummaryBean();
csb.setClientId(client.getId());
- csb.setApikey(contractBean.getApikey());
csb.setClientOrganizationId(client.getOrganization().getId());
csb.setClientOrganizationName(clientOrg.getName());
csb.setClientName(client.getName());
@@ -1300,6 +1309,7 @@ public List getClientVersions(String orgId, String cli
avsb.setName(clientVersion.getClient().getName());
avsb.setDescription(clientVersion.getClient().getDescription());
avsb.setVersion(clientVersion.getVersion());
+ avsb.setApiKey(clientVersion.getApikey());
avsb.setStatus(clientVersion.getStatus());
rval.add(avsb);
@@ -1319,61 +1329,71 @@ public List getClientVersions(String orgId, String cli
@Override
public List getClientContracts(String organizationId, String clientId,
String version) throws StorageException {
- List rval = new ArrayList<>();
-
beginTx();
try {
- EntityManager entityManager = getActiveEntityManager();
- @SuppressWarnings("nls")
- String jpql =
- "SELECT c from ContractBean c " +
- " JOIN c.client clientv " +
- " JOIN clientv.client client " +
- " JOIN client.organization aorg" +
- " WHERE client.id = :clientId " +
- " AND aorg.id = :orgId " +
- " AND clientv.version = :version " +
- " ORDER BY aorg.id, client.id ASC";
- Query query = entityManager.createQuery(jpql);
- query.setParameter("orgId", organizationId); //$NON-NLS-1$
- query.setParameter("clientId", clientId); //$NON-NLS-1$
- query.setParameter("version", version); //$NON-NLS-1$
- List contracts = query.getResultList();
- for (ContractBean contractBean : contracts) {
- ClientBean client = contractBean.getClient().getClient();
- ApiBean api = contractBean.getApi().getApi();
- PlanBean plan = contractBean.getPlan().getPlan();
-
- OrganizationBean clientOrg = entityManager.find(OrganizationBean.class, client.getOrganization().getId());
- OrganizationBean apiOrg = entityManager.find(OrganizationBean.class, api.getOrganization().getId());
-
- ContractSummaryBean csb = new ContractSummaryBean();
- csb.setClientId(client.getId());
- csb.setApikey(contractBean.getApikey());
- csb.setClientOrganizationId(client.getOrganization().getId());
- csb.setClientOrganizationName(clientOrg.getName());
- csb.setClientName(client.getName());
- csb.setClientVersion(contractBean.getClient().getVersion());
- csb.setContractId(contractBean.getId());
- csb.setCreatedOn(contractBean.getCreatedOn());
- csb.setPlanId(plan.getId());
- csb.setPlanName(plan.getName());
- csb.setPlanVersion(contractBean.getPlan().getVersion());
- csb.setApiDescription(api.getDescription());
- csb.setApiId(api.getId());
- csb.setApiName(api.getName());
- csb.setApiOrganizationId(apiOrg.getId());
- csb.setApiOrganizationName(apiOrg.getName());
- csb.setApiVersion(contractBean.getApi().getVersion());
-
- rval.add(csb);
- }
+ return getClientContractsInternal(organizationId, clientId, version);
} catch (Throwable t) {
logger.error(t.getMessage(), t);
throw new StorageException(t);
} finally {
rollbackTx();
}
+ }
+
+ /**
+ * Returns a list of all contracts for the given client.
+ * @param organizationId
+ * @param clientId
+ * @param version
+ * @throws StorageException
+ */
+ protected List getClientContractsInternal(String organizationId, String clientId,
+ String version) throws StorageException {
+ List rval = new ArrayList<>();
+ EntityManager entityManager = getActiveEntityManager();
+ @SuppressWarnings("nls")
+ String jpql =
+ "SELECT c from ContractBean c " +
+ " JOIN c.client clientv " +
+ " JOIN clientv.client client " +
+ " JOIN client.organization aorg" +
+ " WHERE client.id = :clientId " +
+ " AND aorg.id = :orgId " +
+ " AND clientv.version = :version " +
+ " ORDER BY aorg.id, client.id ASC";
+ Query query = entityManager.createQuery(jpql);
+ query.setParameter("orgId", organizationId); //$NON-NLS-1$
+ query.setParameter("clientId", clientId); //$NON-NLS-1$
+ query.setParameter("version", version); //$NON-NLS-1$
+ List contracts = query.getResultList();
+ for (ContractBean contractBean : contracts) {
+ ClientBean client = contractBean.getClient().getClient();
+ ApiBean api = contractBean.getApi().getApi();
+ PlanBean plan = contractBean.getPlan().getPlan();
+
+ OrganizationBean clientOrg = entityManager.find(OrganizationBean.class, client.getOrganization().getId());
+ OrganizationBean apiOrg = entityManager.find(OrganizationBean.class, api.getOrganization().getId());
+
+ ContractSummaryBean csb = new ContractSummaryBean();
+ csb.setClientId(client.getId());
+ csb.setClientOrganizationId(client.getOrganization().getId());
+ csb.setClientOrganizationName(clientOrg.getName());
+ csb.setClientName(client.getName());
+ csb.setClientVersion(contractBean.getClient().getVersion());
+ csb.setContractId(contractBean.getId());
+ csb.setCreatedOn(contractBean.getCreatedOn());
+ csb.setPlanId(plan.getId());
+ csb.setPlanName(plan.getName());
+ csb.setPlanVersion(contractBean.getPlan().getVersion());
+ csb.setApiDescription(api.getDescription());
+ csb.setApiId(api.getId());
+ csb.setApiName(api.getName());
+ csb.setApiOrganizationId(apiOrg.getId());
+ csb.setApiOrganizationName(apiOrg.getName());
+ csb.setApiVersion(contractBean.getApi().getVersion());
+
+ rval.add(csb);
+ }
return rval;
}
@@ -1420,7 +1440,6 @@ public ApiRegistryBean getApiRegistry(String organizationId, String clientId, St
entry.setPlanId(plan.getId());
entry.setPlanName(plan.getName());
entry.setPlanVersion(contractBean.getPlan().getVersion());
- entry.setApiKey(contractBean.getApikey());
Set gateways = svb.getGateways();
if (gateways != null && !gateways.isEmpty()) {
diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ActionResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ActionResourceImpl.java
index 9ac62f6d5b..a2f031c4e3 100644
--- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ActionResourceImpl.java
+++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ActionResourceImpl.java
@@ -357,11 +357,11 @@ private void registerClient(ActionBean action) throws ActionException {
client.setOrganizationId(versionBean.getClient().getOrganization().getId());
client.setClientId(versionBean.getClient().getId());
client.setVersion(versionBean.getVersion());
+ client.setApiKey(versionBean.getApikey());
Set contracts = new HashSet<>();
for (ContractSummaryBean contractBean : contractBeans) {
Contract contract = new Contract();
- contract.setApiKey(contractBean.getApikey());
contract.setPlan(contractBean.getPlanId());
contract.setApiId(contractBean.getApiId());
contract.setApiOrgId(contractBean.getApiOrganizationId());
@@ -494,7 +494,8 @@ private List aggregateContractPolicies(ContractSummaryBean contractBean)
}
return policies;
} catch (Exception e) {
- throw ExceptionFactory.actionException(Messages.i18n.format("ErrorAggregatingPolicies", contractBean.getApikey()), e); //$NON-NLS-1$
+ throw ExceptionFactory.actionException(
+ Messages.i18n.format("ErrorAggregatingPolicies", contractBean.getClientId() + "->" + contractBean.getApiDescription()), e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java
index b54a4f9797..998cd3be80 100644
--- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java
+++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java
@@ -34,6 +34,7 @@
import io.apiman.manager.api.beans.audit.AuditEntryBean;
import io.apiman.manager.api.beans.audit.data.EntityUpdatedData;
import io.apiman.manager.api.beans.audit.data.MembershipData;
+import io.apiman.manager.api.beans.clients.ApiKeyBean;
import io.apiman.manager.api.beans.clients.ClientBean;
import io.apiman.manager.api.beans.clients.ClientStatus;
import io.apiman.manager.api.beans.clients.ClientVersionBean;
@@ -172,6 +173,7 @@
import javax.ws.rs.core.Response.ResponseBuilder;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;
@@ -550,7 +552,7 @@ public ClientVersionBean createClientVersion(String organizationId, String clien
if (bean.isClone() && bean.getCloneVersion() != null) {
try {
- List contracts = getclientVersionContracts(organizationId, clientId, bean.getCloneVersion());
+ List contracts = getClientVersionContracts(organizationId, clientId, bean.getCloneVersion());
for (ContractSummaryBean contract : contracts) {
NewContractBean ncb = new NewContractBean();
ncb.setPlanId(contract.getPlanId());
@@ -574,6 +576,63 @@ public ClientVersionBean createClientVersion(String organizationId, String clien
return newVersion;
}
+
+ /**
+ * @see io.apiman.manager.api.rest.contract.IOrganizationResource#getClientApiKey(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApiKeyBean getClientApiKey(String organizationId, String clientId, String version)
+ throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException {
+ if (!securityContext.hasPermission(PermissionType.clientView, organizationId) ) {
+ throw ExceptionFactory.notAuthorizedException();
+ }
+ ClientVersionBean client = getClientVersionInternal(organizationId, clientId, version, true);
+ ApiKeyBean apiKeyBean = new ApiKeyBean();
+ apiKeyBean.setApiKey(client.getApikey());
+ return apiKeyBean;
+ }
+
+ /**
+ * @see io.apiman.manager.api.rest.contract.IOrganizationResource#updateClientApiKey(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.clients.ApiKeyBean)
+ */
+ @Override
+ public ApiKeyBean updateClientApiKey(String organizationId, String clientId, String version, ApiKeyBean bean)
+ throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException,
+ InvalidClientStatusException {
+ if (!securityContext.hasPermission(PermissionType.clientEdit, organizationId) ) {
+ throw ExceptionFactory.notAuthorizedException();
+ }
+
+ try {
+ storage.beginTx();
+ ClientVersionBean clientVersion = storage.getClientVersion(organizationId, clientId, version);
+ if (clientVersion == null) {
+ throw ExceptionFactory.clientVersionNotFoundException(clientId, version);
+ }
+
+ String newApiKey = bean.getApiKey();
+ if (StringUtils.isEmpty(newApiKey)) {
+ newApiKey = apiKeyGenerator.generate();
+ }
+
+ clientVersion.setApikey(newApiKey);
+ clientVersion.setModifiedBy(securityContext.getCurrentUser());
+ clientVersion.setModifiedOn(new Date());
+ storage.updateClientVersion(clientVersion);
+
+ storage.commitTx();
+ log.debug(String.format("Updated an API Key for client %s version %s", clientVersion.getClient().getName(), clientVersion)); //$NON-NLS-1$
+ ApiKeyBean rval = new ApiKeyBean();
+ rval.setApiKey(newApiKey);
+ return rval;
+ } catch (AbstractRestException e) {
+ storage.rollbackTx();
+ throw e;
+ } catch (Exception e) {
+ storage.rollbackTx();
+ throw new SystemErrorException(e);
+ }
+ }
/**
* Creates a new client version.
@@ -595,6 +654,10 @@ protected ClientVersionBean createClientVersionInternal(NewClientVersionBean bea
newVersion.setModifiedOn(new Date());
newVersion.setStatus(ClientStatus.Created);
newVersion.setVersion(bean.getVersion());
+ newVersion.setApikey(bean.getApiKey());
+ if (newVersion.getApikey() == null) {
+ newVersion.setApikey(apiKeyGenerator.generate());
+ }
storage.createClientVersion(newVersion);
storage.createAuditEntry(AuditUtils.clientVersionCreated(newVersion, securityContext));
@@ -609,12 +672,30 @@ protected ClientVersionBean createClientVersionInternal(NewClientVersionBean bea
@Override
public ClientVersionBean getClientVersion(String organizationId, String clientId, String version)
throws ClientVersionNotFoundException, NotAuthorizedException {
+ boolean hasPermission = securityContext.hasPermission(PermissionType.clientView, organizationId);
+ return getClientVersionInternal(organizationId, clientId, version, hasPermission);
+ }
+
+ /**
+ * Does the same thing as getClientVersion() but accepts the 'hasPermission' param,
+ * which lets callers dictate whether the user has clientView permission for the org.
+ * @param organizationId
+ * @param clientId
+ * @param version
+ * @param hasPermission
+ */
+ protected ClientVersionBean getClientVersionInternal(String organizationId, String clientId, String version,
+ boolean hasPermission) {
try {
storage.beginTx();
ClientVersionBean clientVersion = storage.getClientVersion(organizationId, clientId, version);
if (clientVersion == null) {
throw ExceptionFactory.clientVersionNotFoundException(clientId, version);
}
+ // Hide some data if the user doesn't have the clientView permission
+ if (!hasPermission) {
+ clientVersion.setApikey(null);
+ }
storage.commitTx();
log.debug(String.format("Got new client version %s: %s", clientVersion.getClient().getName(), clientVersion)); //$NON-NLS-1$
return clientVersion;
@@ -692,7 +773,14 @@ public List listClientVersions(String organizationId,
getClient(organizationId, clientId);
try {
- return query.getClientVersions(organizationId, clientId);
+ List clientVersions = query.getClientVersions(organizationId, clientId);
+ boolean hasPermission = securityContext.hasPermission(PermissionType.clientView, organizationId);
+ if (!hasPermission) {
+ for (ClientVersionSummaryBean clientVersionSummaryBean : clientVersions) {
+ clientVersionSummaryBean.setApiKey(null);
+ }
+ }
+ return clientVersions;
} catch (StorageException e) {
throw new SystemErrorException(e);
}
@@ -786,7 +874,6 @@ protected ContractBean createContractInternal(String organizationId, String clie
contract.setPlan(pvb);
contract.setCreatedBy(securityContext.getCurrentUser());
contract.setCreatedOn(new Date());
- contract.setApikey((bean.getApiKey() == null) ? apiKeyGenerator.generate() : bean.getApiKey());
// Move the client to the "Ready" state if necessary.
if (cvb.getStatus() == ClientStatus.Created && clientValidator.isReady(cvb, true)) {
@@ -838,7 +925,6 @@ private boolean contractAlreadyExists(String organizationId, String clientId, St
@Override
public ContractBean getContract(String organizationId, String clientId, String version,
Long contractId) throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException {
- boolean hasPermission = securityContext.hasPermission(PermissionType.clientView, organizationId);
try {
storage.beginTx();
ContractBean contract = storage.getContract(contractId);
@@ -847,11 +933,6 @@ public ContractBean getContract(String organizationId, String clientId, String v
storage.commitTx();
- // Hide some data if the user doesn't have the clientView permission
- if (!hasPermission) {
- contract.setApikey(null);
- }
-
log.debug(String.format("Got contract %s: %s", contract.getId(), contract)); //$NON-NLS-1$
return contract;
} catch (AbstractRestException e) {
@@ -871,7 +952,7 @@ public void deleteAllContracts(String organizationId, String clientId, String ve
throws ClientNotFoundException, NotAuthorizedException {
if (!securityContext.hasPermission(PermissionType.clientEdit, organizationId))
throw ExceptionFactory.notAuthorizedException();
- List contracts = getclientVersionContracts(organizationId, clientId, version);
+ List contracts = getClientVersionContracts(organizationId, clientId, version);
for (ContractSummaryBean contract : contracts) {
deleteContract(organizationId, clientId, version, contract.getContractId());
}
@@ -926,26 +1007,16 @@ public void deleteContract(String organizationId, String clientId, String versio
}
/**
- * @see io.apiman.manager.api.rest.contract.IOrganizationResource#getclientVersionContracts(java.lang.String, java.lang.String, java.lang.String)
+ * @see io.apiman.manager.api.rest.contract.IOrganizationResource#getClientVersionContracts(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
- public List getclientVersionContracts(String organizationId, String clientId, String version)
+ public List getClientVersionContracts(String organizationId, String clientId, String version)
throws ClientNotFoundException, NotAuthorizedException {
- boolean hasPermission = securityContext.hasPermission(PermissionType.clientView, organizationId);
-
// Try to get the client first - will throw a ClientNotFoundException if not found.
getClientVersion(organizationId, clientId, version);
try {
List contracts = query.getClientContracts(organizationId, clientId, version);
-
- // Hide some stuff if the user doesn't have the clientView permission
- if (!hasPermission) {
- for (ContractSummaryBean contract : contracts) {
- contract.setApikey(null);
- }
- }
-
return contracts;
} catch (AbstractRestException e) {
storage.rollbackTx();
@@ -1031,7 +1102,7 @@ public Response getApiRegistryXML(String organizationId, String clientId, String
protected ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version,
boolean hasPermission) throws ClientNotFoundException, NotAuthorizedException {
// Try to get the client first - will throw a ClientNotFoundException if not found.
- getClientVersion(organizationId, clientId, version);
+ ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version, hasPermission);
Map gatewayLinks = new HashMap<>();
Map gateways = new HashMap<>();
@@ -1040,11 +1111,8 @@ protected ApiRegistryBean getApiRegistry(String organizationId, String clientId,
ApiRegistryBean apiRegistry = query.getApiRegistry(organizationId, clientId, version);
// Hide some stuff if the user doesn't have the clientView permission
- if (!hasPermission) {
- List apis = apiRegistry.getApis();
- for (ApiEntryBean api : apis) {
- api.setApiKey(null);
- }
+ if (hasPermission) {
+ apiRegistry.setApiKey(clientVersion.getApikey());
}
List apis = apiRegistry.getApis();
@@ -2338,13 +2406,6 @@ public List getApiVersionContracts(String organizationId,
try {
List contracts = query.getContracts(organizationId, apiId, version, page, pageSize);
-
- for (ContractSummaryBean contract : contracts) {
- if (!securityContext.hasPermission(PermissionType.clientView, contract.getClientOrganizationId())) {
- contract.setApikey(null);
- }
- }
-
log.debug(String.format("Got API %s version %s contracts: %s", apiId, version, contracts)); //$NON-NLS-1$
return contracts;
} catch (StorageException e) {
diff --git a/manager/api/rest/src/main/java/io/apiman/manager/api/rest/contract/IOrganizationResource.java b/manager/api/rest/src/main/java/io/apiman/manager/api/rest/contract/IOrganizationResource.java
index efeb777583..36f4723ab8 100644
--- a/manager/api/rest/src/main/java/io/apiman/manager/api/rest/contract/IOrganizationResource.java
+++ b/manager/api/rest/src/main/java/io/apiman/manager/api/rest/contract/IOrganizationResource.java
@@ -25,6 +25,7 @@
import io.apiman.manager.api.beans.apis.UpdateApiBean;
import io.apiman.manager.api.beans.apis.UpdateApiVersionBean;
import io.apiman.manager.api.beans.audit.AuditEntryBean;
+import io.apiman.manager.api.beans.clients.ApiKeyBean;
import io.apiman.manager.api.beans.clients.ClientBean;
import io.apiman.manager.api.beans.clients.ClientVersionBean;
import io.apiman.manager.api.beans.clients.NewClientBean;
@@ -315,7 +316,58 @@ public ClientVersionBean createClientVersion(@PathParam("organizationId") String
@PathParam("clientId") String clientId, NewClientVersionBean bean)
throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException,
ClientVersionAlreadyExistsException;
+
+ /**
+ * Use this endpoint to update the API Key for the given client. You can either
+ * provide your own custom (must be unique) API Key, or you can send an empty request
+ * and apiman will generate a new API key for you. Note that if the client is already
+ * registered with one or more Gateways, this call will fail (the API Key can only be
+ * modified if the client is not currently registered).
+ * @summary Update API Key
+ * @param organizationId The Organization ID.
+ * @param clientId The Client ID.
+ * @param version The Client Version.
+ * @param bean The new custom API Key (or empty to auto-generate a new one).
+ * @statuscode 200 If the Client's API Key is successfully updated.
+ * @statuscode 404 If the Client does not exist.
+ * @statuscode 409 If the Client has the wrong status.
+ * @return The new API Key value.
+ * @throws ClientNotFoundException when the client does not exist
+ * @throws NotAuthorizedException when the user attempts to do or see something that they are not authorized (do not have permission) to
+ * @throws InvalidVersionException when the user attempts to use an invalid version of the client
+ * @throws InvalidClientStatusException when the client is not in the proper status
+ */
+ @PUT
+ @Path("{organizationId}/clients/{clientId}/versions/{version}/apikey")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public ApiKeyBean updateClientApiKey(@PathParam("organizationId") String organizationId,
+ @PathParam("clientId") String clientId, @PathParam("version") String version, ApiKeyBean bean)
+ throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException,
+ InvalidClientStatusException;
+ /**
+ * Use this endpoint to get the client's current API Key. This call will fail if
+ * you do not have the proper permission to see the information.
+ * @summary Get API Key
+ * @param organizationId The Organization ID.
+ * @param clientId The Client ID.
+ * @param version The Client Version.
+ * @statuscode 200 If the Client's API Key is successfully returned.
+ * @statuscode 404 If the Client does not exist.
+ * @return The API Key value.
+ * @throws ClientNotFoundException when the client does not exist
+ * @throws NotAuthorizedException when the user attempts to do or see something that they are not authorized (do not have permission) to
+ * @throws InvalidVersionException when the user attempts to use an invalid version of the client
+ */
+ @GET
+ @Path("{organizationId}/clients/{clientId}/versions/{version}/apikey")
+ @Produces(MediaType.APPLICATION_JSON)
+ public ApiKeyBean getClientApiKey(@PathParam("organizationId") String organizationId,
+ @PathParam("clientId") String clientId, @PathParam("version") String version)
+ throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException;
+
+
/**
* Use this endpoint to list all of the versions of an Client.
* @summary List Client Versions
@@ -469,7 +521,7 @@ public ContractBean getContract(@PathParam("organizationId") String organization
@GET
@Path("{organizationId}/clients/{clientId}/versions/{version}/contracts")
@Produces(MediaType.APPLICATION_JSON)
- public List getclientVersionContracts(@PathParam("organizationId") String organizationId,
+ public List getClientVersionContracts(@PathParam("organizationId") String organizationId,
@PathParam("clientId") String clientId, @PathParam("version") String version)
throws ClientNotFoundException, NotAuthorizedException;
diff --git a/manager/test/api/src/test/resources/test-plan-data/clients/versions/010_update-version-1.0-apikey.resttest b/manager/test/api/src/test/resources/test-plan-data/clients/versions/010_update-version-1.0-apikey.resttest
new file mode 100644
index 0000000000..f0011827ed
--- /dev/null
+++ b/manager/test/api/src/test/resources/test-plan-data/clients/versions/010_update-version-1.0-apikey.resttest
@@ -0,0 +1,13 @@
+PUT /organizations/Organization1/clients/Client1/versions/1.0/apikey admin/admin
+Content-Type: application/json
+
+{
+ "apiKey" : "0112358"
+}
+----
+200
+Content-Type: application/json
+
+{
+ "apiKey" : "0112358"
+}
diff --git a/manager/test/api/src/test/resources/test-plan-data/clients/versions/011_get-version-1.0-apikey.resttest b/manager/test/api/src/test/resources/test-plan-data/clients/versions/011_get-version-1.0-apikey.resttest
new file mode 100644
index 0000000000..74698f10d6
--- /dev/null
+++ b/manager/test/api/src/test/resources/test-plan-data/clients/versions/011_get-version-1.0-apikey.resttest
@@ -0,0 +1,8 @@
+GET /organizations/Organization1/clients/Client1/versions/1.0/apikey admin/admin
+----
+200
+Content-Type: application/json
+
+{
+ "apiKey" : "0112358"
+}
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/auditing/001_client_activity.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/auditing/001_client_activity.resttest
index 5ff0e0a894..2fd8d7dde1 100644
--- a/manager/test/api/src/test/resources/test-plan-data/contracts/auditing/001_client_activity.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/auditing/001_client_activity.resttest
@@ -59,6 +59,15 @@ Content-Type: application/json
"what": "CreateContract",
"data": "{\"clientOrgId\":\"Organization1\",\"clientId\":\"Client1\",\"clientVersion\":\"1.0\",\"apiOrgId\":\"Organization1\",\"apiId\":\"API1\",\"apiVersion\":\"1.0\",\"planId\":\"Plan1\",\"planVersion\":\"1.0\"}"
},
+ {
+ "who": "admin",
+ "organizationId": "Organization1",
+ "entityType": "Client",
+ "entityId": "Client1",
+ "entityVersion": "1.1",
+ "what": "Create",
+ "data": null
+ },
{
"who": "admin",
"organizationId": "Organization1",
@@ -78,5 +87,5 @@ Content-Type: application/json
"data": null
}
],
- "totalSize": 8
+ "totalSize": 9
}
\ No newline at end of file
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/003_create-contract1.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/003_create-contract1.resttest
index 73fbc72425..7c1187116c 100644
--- a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/003_create-contract1.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/003_create-contract1.resttest
@@ -5,13 +5,11 @@ Content-Type: application/json
"apiOrgId" : "Organization1",
"apiId" : "API1",
"apiVersion" : "1.0",
- "planId" : "Plan1",
- "apiKey" : "customApiKey"
+ "planId" : "Plan1"
}
----
200
Content-Type: application/json
-X-RestTest-BindTo-api-key: apikey
X-RestTest-BindTo-contractId: id
{
@@ -61,6 +59,5 @@ X-RestTest-BindTo-contractId: id
"status" : "Locked",
"version" : "1.0",
"createdBy" : "admin"
- },
- "apikey" : "customApiKey"
+ }
}
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/004_get-contracts.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/004_get-contracts.resttest
index 9276e16ec4..d4427c9b93 100644
--- a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/004_get-contracts.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/004_get-contracts.resttest
@@ -6,7 +6,6 @@ Content-Type: application/json
[
{
- "apikey" : "${api-key}",
"clientOrganizationId" : "Organization1",
"clientOrganizationName" : "Organization 1",
"clientId" : "Client1",
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/007_get-apiregistry_json.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/007_get-apiregistry_json.resttest
index 224abcdb10..4b821601b3 100644
--- a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/007_get-apiregistry_json.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/007_get-apiregistry_json.resttest
@@ -4,7 +4,8 @@ GET /organizations/Organization1/clients/Client1/versions/1.0/apiregistry/json a
200
Content-Type: application/json
-{
+{
+ "apiKey" : "*",
"apis" : [
{
"httpEndpoint" : "http://example.org/endpoint",
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/008_get-apiregistry_xml.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/008_get-apiregistry_xml.resttest
index 31b4ab25a5..378b2da30c 100644
--- a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/008_get-apiregistry_xml.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/008_get-apiregistry_xml.resttest
@@ -6,8 +6,8 @@ Content-Type: application/xml
+ *
- *
http://example.org/endpoint
Plan1
Plan 1
@@ -19,7 +19,6 @@ Content-Type: application/xml
1.0
- *
http://example.org/endpoint
PlanA
Plan A
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/010_get-apiregistry_json_download.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/010_get-apiregistry_json_download.resttest
index 9999229129..1f8aaa85b9 100644
--- a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/010_get-apiregistry_json_download.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/010_get-apiregistry_json_download.resttest
@@ -5,7 +5,8 @@ GET /downloads/${download-id}
Content-Type: application/json
Content-Disposition: attachment; filename=api-registry.json
-{
+{
+ "apiKey" : "*",
"apis" : [
{
"httpEndpoint" : "http://example.org/endpoint",
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/012_get-apiregistry_xml_download.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/012_get-apiregistry_xml_download.resttest
index d87ff4412b..29059de871 100644
--- a/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/012_get-apiregistry_xml_download.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/contracts/012_get-apiregistry_xml_download.resttest
@@ -7,8 +7,8 @@ Content-Disposition: attachment; filename=api-registry.xml
+ *
- *
http://example.org/endpoint
Plan1
Plan 1
@@ -20,7 +20,6 @@ Content-Disposition: attachment; filename=api-registry.xml
1.0
- *
http://example.org/endpoint
PlanA
Plan A
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/create/003.5_create-client-version-1.1-custom-key.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/create/003.5_create-client-version-1.1-custom-key.resttest
new file mode 100644
index 0000000000..84a6ec6f4d
--- /dev/null
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/create/003.5_create-client-version-1.1-custom-key.resttest
@@ -0,0 +1,25 @@
+POST /organizations/Organization1/clients/Client1/versions admin/admin
+Content-Type: application/json
+
+{
+ "version" : "1.1",
+ "apiKey" : "client-1-12345"
+}
+----
+200
+Content-Type: application/json
+
+{
+ "client" : {
+ "organization" : {
+ "id" : "Organization1"
+ },
+ "id" : "Client1",
+ "name" : "Client 1",
+ "description" : "This is the description of Client 1.",
+ "createdBy":"admin"
+ },
+ "status" : "Created",
+ "version" : "1.1",
+ "createdBy" : "admin"
+}
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/001_create-client-version-2.0.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/001_create-client-version-2.0.resttest
new file mode 100644
index 0000000000..4b75f9ec3a
--- /dev/null
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/001_create-client-version-2.0.resttest
@@ -0,0 +1,24 @@
+POST /organizations/Organization1/clients/Client1/versions admin/admin
+Content-Type: application/json
+
+{
+ "version" : "2.0"
+}
+----
+200
+Content-Type: application/json
+
+{
+ "client" : {
+ "organization" : {
+ "id" : "Organization1"
+ },
+ "id" : "Client1",
+ "name" : "Client 1",
+ "description" : "This is the description of Client 1.",
+ "createdBy":"admin"
+ },
+ "status" : "Created",
+ "version" : "2.0",
+ "createdBy" : "admin"
+}
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/002_create-contract-1.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/002_create-contract-1.resttest
new file mode 100644
index 0000000000..3b0c84d473
--- /dev/null
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/002_create-contract-1.resttest
@@ -0,0 +1,15 @@
+POST /organizations/Organization1/clients/Client1/versions/2.0/contracts admin/admin
+Content-Type: application/json
+
+{
+ "apiOrgId" : "Organization2",
+ "apiId" : "API2",
+ "apiVersion" : "1.5",
+ "planId" : "PlanA"
+}
+----
+200
+Content-Type: application/json
+
+{
+}
diff --git a/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/003_create-contract-2.resttest b/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/003_create-contract-2.resttest
new file mode 100644
index 0000000000..7c977ef07d
--- /dev/null
+++ b/manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/003_create-contract-2.resttest
@@ -0,0 +1,18 @@
+POST /organizations/Organization1/clients/Client1/versions/2.0/contracts admin/admin
+Content-Type: application/json
+
+{
+ "apiOrgId" : "Organization2",
+ "apiId" : "API2",
+ "apiVersion" : "1.5",
+ "planId" : "PlanB"
+}
+----
+500
+Content-Type: application/json
+
+{
+ "type": "SystemErrorException",
+ "message": "io.apiman.manager.api.core.exceptions.StorageException: Error creating contract: duplicate contract detected.",
+ "stacktrace": "*"
+}
\ No newline at end of file
diff --git a/manager/test/api/src/test/resources/test-plan-data/import/001_import.resttest b/manager/test/api/src/test/resources/test-plan-data/import/001_import.resttest
index be355d593c..5950456964 100644
--- a/manager/test/api/src/test/resources/test-plan-data/import/001_import.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/import/001_import.resttest
@@ -127,7 +127,8 @@ Content-Type: application/json
"createdOn": 1445973206959,
"modifiedBy": "admin",
"modifiedOn": 1445973207627,
- "publishedOn": 1445973207765
+ "publishedOn": 1445973207765,
+ "apikey": "6ec478ca-8ccd-48d0-973e-479f42c68a6c"
},
"Policies": [],
"Contracts": [
@@ -224,8 +225,7 @@ Content-Type: application/json
"lockedOn": 1445973206889
},
"createdBy": "admin",
- "createdOn": 1445973207620,
- "apikey": "6ec478ca-8ccd-48d0-973e-479f42c68a6c"
+ "createdOn": 1445973207620
}
]
}
@@ -394,7 +394,7 @@ INFO: Importing an audit entry: 13
INFO: Importing an audit entry: 15
INFO: Importing an audit entry: 16
INFO: Importing an audit entry: 17
-INFO: +Importing a client contract: 6ec478ca-8ccd-48d0-973e-479f42c68a6c
+INFO: Importing a client contract.
INFO: Publishing APIs to the gateway.
INFO: Publishing API: Organization1 / API1 -> 1.0
INFO: Registering clients in the gateway.
diff --git a/manager/test/api/src/test/resources/test-plan-data/publishing/create/013_create-contract1.resttest b/manager/test/api/src/test/resources/test-plan-data/publishing/create/013_create-contract1.resttest
index 0dc75e7ff9..7c1187116c 100644
--- a/manager/test/api/src/test/resources/test-plan-data/publishing/create/013_create-contract1.resttest
+++ b/manager/test/api/src/test/resources/test-plan-data/publishing/create/013_create-contract1.resttest
@@ -10,7 +10,6 @@ Content-Type: application/json
----
200
Content-Type: application/json
-X-RestTest-BindTo-api-key: apikey
X-RestTest-BindTo-contractId: id
{
diff --git a/manager/test/api/src/test/resources/test-plans/clients-testPlan.xml b/manager/test/api/src/test/resources/test-plans/clients-testPlan.xml
index 8e2665fbe5..410b1b94dd 100644
--- a/manager/test/api/src/test/resources/test-plans/clients-testPlan.xml
+++ b/manager/test/api/src/test/resources/test-plans/clients-testPlan.xml
@@ -33,6 +33,8 @@
test-plan-data/clients/versions/007_get-version-1.0.resttest
test-plan-data/clients/versions/008_create-version-invalid.resttest
test-plan-data/clients/versions/009_create-version-duplicate.resttest
+ test-plan-data/clients/versions/010_update-version-1.0-apikey.resttest
+ test-plan-data/clients/versions/011_get-version-1.0-apikey.resttest
diff --git a/manager/test/api/src/test/resources/test-plans/contracts-testPlan.xml b/manager/test/api/src/test/resources/test-plans/contracts-testPlan.xml
index 1d51378c9c..bc82141458 100644
--- a/manager/test/api/src/test/resources/test-plans/contracts-testPlan.xml
+++ b/manager/test/api/src/test/resources/test-plans/contracts-testPlan.xml
@@ -7,6 +7,7 @@
test-plan-data/contracts/create/001_create-org1.resttest
test-plan-data/contracts/create/002_create-client1.resttest
test-plan-data/contracts/create/003_create-client-version-1.0.resttest
+ test-plan-data/contracts/create/003.5_create-client-version-1.1-custom-key.resttest
test-plan-data/contracts/create/004_create-plan1.resttest
test-plan-data/contracts/create/005_create-plan-version-1.0.resttest
@@ -38,7 +39,7 @@
test-plan-data/contracts/publish/001_publish-api-1.resttest
test-plan-data/contracts/publish/002_publish-api-2.resttest
- test-plan-data/contracts/contracts/003_create-contract1.resttest
+ test-plan-data/contracts/contracts/003_create-contract1.resttest
test-plan-data/contracts/contracts/004_get-contracts.resttest
test-plan-data/contracts/contracts/005_create-contract2.resttest
test-plan-data/contracts/contracts/006_get-contracts.resttest
@@ -73,4 +74,11 @@
test-plan-data/contracts/auditing/002_api_activity.resttest
+
+
+ test-plan-data/contracts/multi-contract/001_create-client-version-2.0.resttest
+ test-plan-data/contracts/multi-contract/002_create-contract-1.resttest
+ test-plan-data/contracts/multi-contract/003_create-contract-2.resttest
+
+
diff --git a/test/common/src/main/java/io/apiman/test/common/util/TestPlanRunner.java b/test/common/src/main/java/io/apiman/test/common/util/TestPlanRunner.java
index d552b7e7ef..4e51caa959 100644
--- a/test/common/src/main/java/io/apiman/test/common/util/TestPlanRunner.java
+++ b/test/common/src/main/java/io/apiman/test/common/util/TestPlanRunner.java
@@ -500,8 +500,10 @@ public int compare(JsonNode o1, JsonNode o2) {
}
}
- Assert.assertEquals("Value mismatch for text field '" + expectedFieldName + "'.", expected,
- actual);
+ if (!expected.equals("*")) {
+ Assert.assertEquals("Value mismatch for text field '" + expectedFieldName + "'.", expected,
+ actual);
+ }
} else if (expectedValue instanceof NumericNode) {
NumericNode numeric = (NumericNode) expectedValue;
Number expected = numeric.numberValue();
diff --git a/test/suite/src/main/resources/data/clients/002_create-client1-version-1.0.resttest b/test/suite/src/main/resources/data/clients/002_create-client1-version-1.0.resttest
index c5c9b30e20..316eb0a479 100644
--- a/test/suite/src/main/resources/data/clients/002_create-client1-version-1.0.resttest
+++ b/test/suite/src/main/resources/data/clients/002_create-client1-version-1.0.resttest
@@ -7,6 +7,7 @@ Content-Type: application/json
----
200
Content-Type: application/json
+X-RestTest-BindTo-client10-api-key: apikey
{
"client" : {
diff --git a/test/suite/src/main/resources/data/clients/003_create-client1-version-1.1.resttest b/test/suite/src/main/resources/data/clients/003_create-client1-version-1.1.resttest
new file mode 100644
index 0000000000..6bde6ea085
--- /dev/null
+++ b/test/suite/src/main/resources/data/clients/003_create-client1-version-1.1.resttest
@@ -0,0 +1,22 @@
+POST /organizations/Test/clients/client1/versions ${apiman.suite.api-username}/${apiman.suite.api-password}
+Content-Type: application/json
+
+{
+ "version" : "1.1",
+ "apiKey" : "client1-1.1_12345"
+}
+----
+200
+Content-Type: application/json
+
+{
+ "client" : {
+ "organization" : {
+ "id" : "Test"
+ },
+ "id" : "client1",
+ "name" : "client1"
+ },
+ "status" : "Created",
+ "version" : "1.1"
+}
diff --git a/test/suite/src/main/resources/data/clients/003_create-gold-contract.resttest b/test/suite/src/main/resources/data/clients/004_create-gold-contract.resttest
similarity index 95%
rename from test/suite/src/main/resources/data/clients/003_create-gold-contract.resttest
rename to test/suite/src/main/resources/data/clients/004_create-gold-contract.resttest
index 61a50c8a5f..2f66f4925a 100644
--- a/test/suite/src/main/resources/data/clients/003_create-gold-contract.resttest
+++ b/test/suite/src/main/resources/data/clients/004_create-gold-contract.resttest
@@ -10,7 +10,6 @@ Content-Type: application/json
----
200
Content-Type: application/json
-X-RestTest-BindTo-gold-api-key: apikey
X-RestTest-BindTo-gold-contractId: id
{
diff --git a/test/suite/src/main/resources/data/clients/004_create-silver-contract.resttest b/test/suite/src/main/resources/data/clients/005_create-silver-contract.resttest
similarity index 84%
rename from test/suite/src/main/resources/data/clients/004_create-silver-contract.resttest
rename to test/suite/src/main/resources/data/clients/005_create-silver-contract.resttest
index 20e67f5007..790625f8af 100644
--- a/test/suite/src/main/resources/data/clients/004_create-silver-contract.resttest
+++ b/test/suite/src/main/resources/data/clients/005_create-silver-contract.resttest
@@ -1,4 +1,4 @@
-POST /organizations/Test/clients/client1/versions/1.0/contracts ${apiman.suite.api-username}/${apiman.suite.api-password}
+POST /organizations/Test/clients/client1/versions/1.1/contracts ${apiman.suite.api-username}/${apiman.suite.api-password}
Content-Type: application/json
{
@@ -10,7 +10,6 @@ Content-Type: application/json
----
200
Content-Type: application/json
-X-RestTest-BindTo-silver-api-key: apikey
X-RestTest-BindTo-silver-contractId: id
{
@@ -21,7 +20,7 @@ X-RestTest-BindTo-silver-contractId: id
},
"id" : "client1"
},
- "version" : "1.0"
+ "version" : "1.1"
},
"api":{
diff --git a/test/suite/src/main/resources/data/publish/002_register-client1.resttest b/test/suite/src/main/resources/data/publish/002_register-client1-1.0.resttest
similarity index 100%
rename from test/suite/src/main/resources/data/publish/002_register-client1.resttest
rename to test/suite/src/main/resources/data/publish/002_register-client1-1.0.resttest
diff --git a/test/suite/src/main/resources/data/publish/002_register-client1-1.1.resttest b/test/suite/src/main/resources/data/publish/002_register-client1-1.1.resttest
new file mode 100644
index 0000000000..850351f372
--- /dev/null
+++ b/test/suite/src/main/resources/data/publish/002_register-client1-1.1.resttest
@@ -0,0 +1,11 @@
+POST /actions ${apiman.suite.api-username}/${apiman.suite.api-password}
+Content-Type: application/json
+
+{
+ "type" : "registerClient",
+ "organizationId" : "Test",
+ "entityId" : "client1",
+ "entityVersion" : "1.1"
+}
+----
+204
diff --git a/test/suite/src/main/resources/data/runtime/echo_gold_success.resttest b/test/suite/src/main/resources/data/runtime/echo_gold_success.resttest
index 197e02f2b0..33affc4622 100644
--- a/test/suite/src/main/resources/data/runtime/echo_gold_success.resttest
+++ b/test/suite/src/main/resources/data/runtime/echo_gold_success.resttest
@@ -1,6 +1,6 @@
GET /Test/echo/1.0
X-Custom-Header: custom-value
-X-API-Key: ${gold-api-key}
+X-API-Key: ${client10-api-key}
----
200
diff --git a/test/suite/src/main/resources/data/runtime/echo_silver_fail.resttest b/test/suite/src/main/resources/data/runtime/echo_silver_fail.resttest
index 0f08bdd528..e5a30efd61 100644
--- a/test/suite/src/main/resources/data/runtime/echo_silver_fail.resttest
+++ b/test/suite/src/main/resources/data/runtime/echo_silver_fail.resttest
@@ -1,6 +1,6 @@
GET /Test/echo/1.0
X-Customer-Header: custom-value
-X-API-Key: ${silver-api-key}
+X-API-Key: client1-1.1_12345
----
429
diff --git a/test/suite/src/main/resources/data/runtime/echo_silver_success.resttest b/test/suite/src/main/resources/data/runtime/echo_silver_success.resttest
index a5c087a1a0..554e30978e 100644
--- a/test/suite/src/main/resources/data/runtime/echo_silver_success.resttest
+++ b/test/suite/src/main/resources/data/runtime/echo_silver_success.resttest
@@ -1,6 +1,6 @@
GET /Test/echo/1.0
X-Custom-Header: custom-value
-X-API-Key: ${silver-api-key}
+X-API-Key: client1-1.1_12345
----
200
diff --git a/test/suite/src/main/resources/scripts/api-manager-testPlan.xml b/test/suite/src/main/resources/scripts/api-manager-testPlan.xml
index cd09fe73d7..899c4e9259 100644
--- a/test/suite/src/main/resources/scripts/api-manager-testPlan.xml
+++ b/test/suite/src/main/resources/scripts/api-manager-testPlan.xml
@@ -34,9 +34,11 @@
data/clients/001_create-client1.resttest
data/clients/002_create-client1-version-1.0.resttest
- data/clients/003_create-gold-contract.resttest
- data/clients/004_create-silver-contract.resttest
- data/publish/002_register-client1.resttest
+ data/clients/003_create-client1-version-1.1.resttest
+ data/clients/004_create-gold-contract.resttest
+ data/clients/005_create-silver-contract.resttest
+ data/publish/002_register-client1-1.0.resttest
+ data/publish/002_register-client1-1.1.resttest
\ No newline at end of file