use of io.apiman.manager.api.beans.clients.ApiKeyBean in project apiman by apiman.
the class OrganizationResourceImpl method getClientApiKey.
/**
* @see 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 {
securityContext.checkPermissions(PermissionType.clientView, organizationId);
ClientVersionBean client = getClientVersionInternal(organizationId, clientId, version);
ApiKeyBean apiKeyBean = new ApiKeyBean();
apiKeyBean.setApiKey(client.getApikey());
return apiKeyBean;
}
use of io.apiman.manager.api.beans.clients.ApiKeyBean in project apiman by apiman.
the class OrganizationResourceImpl method updateClientApiKey.
/**
* @see 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 {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
try {
ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version);
if (clientVersion.getStatus() == ClientStatus.Registered) {
throw ExceptionFactory.invalidClientStatusException();
}
String newApiKey = bean.getApiKey();
if (StringUtils.isEmpty(newApiKey)) {
newApiKey = apiKeyGenerator.generate();
}
clientVersion.setApikey(newApiKey);
clientVersion.setModifiedBy(securityContext.getCurrentUser());
clientVersion.setModifiedOn(new Date());
storage.beginTx();
storage.updateClientVersion(clientVersion);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Updated an API Key for client %s version %s", clientVersion.getClient().getName(), clientVersion));
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);
}
}
use of io.apiman.manager.api.beans.clients.ApiKeyBean in project apiman by apiman.
the class ClientAppService method getClientApiKey.
public ApiKeyBean getClientApiKey(String organizationId, String clientId, String version) throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException {
ClientVersionBean client = tryAction(() -> getClientVersionInternal(organizationId, clientId, version));
ApiKeyBean apiKeyBean = new ApiKeyBean();
apiKeyBean.setApiKey(client.getApikey());
return apiKeyBean;
}
use of io.apiman.manager.api.beans.clients.ApiKeyBean in project apiman by apiman.
the class ClientAppService method updateClientApiKey.
public ApiKeyBean updateClientApiKey(String organizationId, String clientId, String version, ApiKeyBean bean) throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException, InvalidClientStatusException {
ClientVersionBean clientVersion = tryAction(() -> getClientVersionInternal(organizationId, clientId, version));
if (clientVersion.getStatus() == ClientStatus.Registered) {
throw ExceptionFactory.invalidClientStatusException();
}
String newApiKey = bean.getApiKey();
if (StringUtils.isEmpty(newApiKey)) {
newApiKey = apiKeyGenerator.generate();
}
clientVersion.setApikey(newApiKey);
clientVersion.setModifiedBy(securityContext.getCurrentUser());
clientVersion.setModifiedOn(new Date());
tryAction(() -> storage.updateClientVersion(clientVersion));
// $NON-NLS-1$
LOGGER.debug("Updated an API Key for client {0} version {1}", clientVersion.getClient().getName(), clientVersion);
ApiKeyBean rval = new ApiKeyBean();
rval.setApiKey(newApiKey);
return rval;
}
Aggregations