Search in sources :

Example 1 with ApiKeyBean

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;
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) ApiKeyBean(io.apiman.manager.api.beans.clients.ApiKeyBean)

Example 2 with 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);
    }
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ApiKeyBean(io.apiman.manager.api.beans.clients.ApiKeyBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) Date(java.util.Date) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) MalformedURLException(java.net.MalformedURLException) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)

Example 3 with ApiKeyBean

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;
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) ApiKeyBean(io.apiman.manager.api.beans.clients.ApiKeyBean)

Example 4 with 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;
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) ApiKeyBean(io.apiman.manager.api.beans.clients.ApiKeyBean) Date(java.util.Date)

Aggregations

ApiKeyBean (io.apiman.manager.api.beans.clients.ApiKeyBean)4 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)4 NewClientVersionBean (io.apiman.manager.api.beans.clients.NewClientVersionBean)4 Date (java.util.Date)2 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)1 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)1 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)1 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)1 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)1 ApiVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException)1 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)1 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)1 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)1 ClientVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException)1 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)1 ContractAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException)1 ContractNotFoundException (io.apiman.manager.api.rest.exceptions.ContractNotFoundException)1 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)1 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)1