/** * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((organizationId == null) ? 0 : organizationId.hashCode()); result = prime * result + ((getClientId() == null) ? 0 : getClientId().hashCode()); result = prime * result + ((version == null) ? 0 : version.hashCode()); return result; }
@Override public void listClients(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Client) .map(entity -> (Client) entity) .filter(client -> client.getOrganizationId().equals(organizationId)) .map(client -> client.getClientId()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listClients(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Client) .map(entity -> (Client) entity) .filter(client -> client.getOrganizationId().equals(organizationId)) .map(client -> client.getClientId()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listClientVersions(String organizationId, String clientId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Client) .map(entity -> (Client) entity) .filter(client -> client.getOrganizationId().equals(organizationId) && client.getClientId().equals(clientId)) .map(client -> client.getVersion()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listClientVersions(String organizationId, String clientId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Client) .map(entity -> (Client) entity) .filter(client -> client.getOrganizationId().equals(organizationId) && client.getClientId().equals(clientId)) .map(client -> client.getVersion()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
/** * Generates an in-memory key for an client, used to index the client for later quick * retrieval. * @param client an client * @return a client key */ private String getClientIndex(Client client) { return getClientIndex(client.getOrganizationId(), client.getClientId(), client.getVersion()); }
/** * Generates an in-memory key for an client, used to index the client for later quick * retrieval. * @param client an client * @return a client key */ private String getClientIndex(Client client) { return getClientIndex(client.getOrganizationId(), client.getClientId(), client.getVersion()); }
private String getClientIndex(Client client) { return getClientIndex(client.getOrganizationId(), client.getClientId(), client.getVersion()); }
private String getClientIndex(Client client) { return getClientIndex(client.getOrganizationId(), client.getClientId(), client.getVersion()); }
/** * Removes all of the api contracts from the database. * @param client * @param connection * @throws SQLException */ protected void unregisterApiContracts(Client client, Connection connection) throws SQLException { QueryRunner run = new QueryRunner(); run.update(connection, "DELETE FROM contracts WHERE client_org_id = ? AND client_id = ? AND client_version = ?", //$NON-NLS-1$ client.getOrganizationId(), client.getClientId(), client.getVersion()); }
/** * Removes all of the api contracts from the database. * @param client * @param connection * @throws SQLException */ protected void unregisterApiContracts(Client client, Connection connection) throws SQLException { QueryRunner run = new QueryRunner(); run.update(connection, "DELETE FROM contracts WHERE client_org_id = ? AND client_id = ? AND client_version = ?", //$NON-NLS-1$ client.getOrganizationId(), client.getClientId(), client.getVersion()); }
/** * @see io.apiman.manager.api.gateway.IGatewayLink#unregisterClient(io.apiman.gateway.engine.beans.Client) */ @Override public void unregisterClient(Client client) throws RegistrationException, GatewayAuthenticationException { if (!isGatewayUp()) { throw new RegistrationException(Messages.i18n.format("RestGatewayLink.GatewayNotRunning")); //$NON-NLS-1$ } getClient().unregister(client.getOrganizationId(), client.getClientId(), client.getVersion()); }
@Override public void getClient(String organizationId, String clientId, String clientVersion, IAsyncResultHandler<Client> handler) { delegate.getClient(organizationId, clientId, clientVersion, result -> { if (result.isSuccess()) { Client client = result.getResult(); if (client != null) { for (Contract contract : client.getContracts()) { decryptPolicies(client.getOrganizationId(), client.getClientId(), client.getVersion(), EntityType.ClientApp, contract.getPolicies()); } } } handler.handle(result); }); }
/** * @see io.apiman.gateway.engine.IRegistry#unregisterClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void unregisterClient(Client client, IAsyncResultHandler<Void> handler) { try { QueryRunner run = new QueryRunner(ds); run.update("DELETE FROM gw_clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ client.getOrganizationId(), client.getClientId(), client.getVersion()); 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$ } }
@Override public void getClient(String organizationId, String clientId, String clientVersion, IAsyncResultHandler<Client> handler) { delegate.getClient(organizationId, clientId, clientVersion, result -> { if (result.isSuccess()) { Client client = result.getResult(); if (client != null) { for (Contract contract : client.getContracts()) { decryptPolicies(client.getOrganizationId(), client.getClientId(), client.getVersion(), EntityType.ClientApp, contract.getPolicies()); } } } handler.handle(result); }); }
/** * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void getClient(String apiKey, IAsyncResultHandler<Client> handler) { delegate.getClient(apiKey, result -> { if (result.isSuccess()) { Client client = result.getResult(); if (client != null) { for (Contract contract : client.getContracts()) { decryptPolicies(client.getOrganizationId(), client.getClientId(), client.getVersion(), EntityType.ClientApp, contract.getPolicies()); } } } handler.handle(result); }); }
/** * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void getClient(String apiKey, IAsyncResultHandler<Client> handler) { delegate.getClient(apiKey, result -> { if (result.isSuccess()) { Client client = result.getResult(); if (client != null) { for (Contract contract : client.getContracts()) { decryptPolicies(client.getOrganizationId(), client.getClientId(), client.getVersion(), EntityType.ClientApp, contract.getPolicies()); } } } handler.handle(result); }); }
/** * @see io.apiman.gateway.engine.IRegistry#unregisterClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void unregisterClient(Client client, IAsyncResultHandler<Void> handler) { try { QueryRunner run = new QueryRunner(ds); run.update("DELETE FROM gw_clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ client.getOrganizationId(), client.getClientId(), client.getVersion()); 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$ } }
@Override public void handle(IAsyncResult<ApiContract> result) { if (result.isSuccess()) { ApiContract contract = result.getResult(); List<Policy> policies = contract.getPolicies(); decryptPolicies(contract.getClient().getOrganizationId(), contract.getClient().getClientId(), contract.getClient().getVersion(), EntityType.ClientApp, policies); Api api = contract.getApi(); if (api != null) { List<Policy> apiPolicies = api.getApiPolicies(); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, apiPolicies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); } } handler.handle(result); } });
@Override public void handle(IAsyncResult<ApiContract> result) { if (result.isSuccess()) { ApiContract contract = result.getResult(); List<Policy> policies = contract.getPolicies(); decryptPolicies(contract.getClient().getOrganizationId(), contract.getClient().getClientId(), contract.getClient().getVersion(), EntityType.ClientApp, policies); Api api = contract.getApi(); if (api != null) { List<Policy> apiPolicies = api.getApiPolicies(); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, apiPolicies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); } } handler.handle(result); } });