Search in sources :

Example 1 with ResourceCrn

use of com.sequenceiq.authorization.annotation.ResourceCrn in project cloudbreak by hortonworks.

the class UserV1Controller method getUserSyncState.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)
public EnvironmentUserSyncState getUserSyncState(@ResourceCrn @TenantAwareParam @NotEmpty String environmentCrn) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    Crn envCrn = Crn.safeFromString(environmentCrn);
    return environmentUserSyncStateCalculator.calculateEnvironmentUserSyncState(accountId, envCrn);
}
Also used : ResourceCrn(com.sequenceiq.authorization.annotation.ResourceCrn) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 2 with ResourceCrn

use of com.sequenceiq.authorization.annotation.ResourceCrn in project cloudbreak by hortonworks.

the class CDPStructuredEventV1Controller method getAuditEventsZipResponse.

private Response getAuditEventsZipResponse(Collection<CDPStructuredNotificationEvent> events, String resourceCrn) {
    StreamingOutput streamingOutput = output -> {
        try (ZipOutputStream zipOutputStream = new ZipOutputStream(output)) {
            zipOutputStream.putNextEntry(new ZipEntry("struct-events.json"));
            zipOutputStream.write(JsonUtil.writeValueAsString(events).getBytes());
            zipOutputStream.closeEntry();
        }
    };
    String resourceType = Crn.safeFromString(resourceCrn).getResourceType().getName();
    String fileName = String.format("audit-%s.zip", resourceType);
    return Response.ok(streamingOutput).header("content-disposition", String.format("attachment; filename = %s", fileName)).build();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ResourceCrn(com.sequenceiq.authorization.annotation.ResourceCrn) Collection(java.util.Collection) PageRequest(org.springframework.data.domain.PageRequest) CDPStructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredNotificationEvent) StreamingOutput(javax.ws.rs.core.StreamingOutput) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Controller(org.springframework.stereotype.Controller) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) CDPStructuredEventV1Endpoint(com.sequenceiq.cloudbreak.structuredevent.rest.endpoint.CDPStructuredEventV1Endpoint) Inject(javax.inject.Inject) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) List(java.util.List) CustomPermissionCheck(com.sequenceiq.authorization.annotation.CustomPermissionCheck) Response(javax.ws.rs.core.Response) Sort(org.springframework.data.domain.Sort) ZipEntry(java.util.zip.ZipEntry) CDPStructuredEventDBService(com.sequenceiq.cloudbreak.structuredevent.service.db.CDPStructuredEventDBService) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 3 with ResourceCrn

use of com.sequenceiq.authorization.annotation.ResourceCrn in project cloudbreak by hortonworks.

the class EnvironmentPlatformResourceController method getPrivateDnsZones.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)
public PlatformPrivateDnsZonesResponse getPrivateDnsZones(@ResourceCrn String environmentCrn, String platformVariant) {
    String accountId = getAccountId();
    validateEnvironmentCrnPattern(environmentCrn);
    PlatformResourceRequest request = platformParameterService.getPlatformResourceRequestByEnvironment(accountId, environmentCrn, platformVariant, null);
    LOGGER.debug("Get /platform_resources/private_dns_zones, request: {}", request);
    CloudPrivateDnsZones privateDnsZones = platformParameterService.getPrivateDnsZones(request);
    List<PlatformPrivateDnsZoneResponse> platformPrivateDnsZones = privateDnsZones.getPrivateDnsZones().stream().map(pdz -> new PlatformPrivateDnsZoneResponse(pdz.getPrivateDnsZoneId())).collect(Collectors.toList());
    PlatformPrivateDnsZonesResponse response = new PlatformPrivateDnsZonesResponse(platformPrivateDnsZones);
    LOGGER.debug("Resp /platform_resources/private_dns_zones, request: {}, privateDnsZones: {}, response: {}", request, privateDnsZones, response);
    return response;
}
Also used : PlatformPrivateDnsZoneResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformPrivateDnsZoneResponse) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) ResourceCrn(com.sequenceiq.authorization.annotation.ResourceCrn) CloudEncryptionKeysToPlatformEncryptionKeysV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudEncryptionKeysToPlatformEncryptionKeysV1ResponseConverter) LoggerFactory(org.slf4j.LoggerFactory) PlatformGatewaysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformGatewaysResponse) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) AccessConfigTypeQueryParam(com.sequenceiq.environment.api.v1.platformresource.model.AccessConfigTypeQueryParam) BadRequestException(javax.ws.rs.BadRequestException) PlatformNetworksResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNetworksResponse) TxType(javax.transaction.Transactional.TxType) PlatformParameterService(com.sequenceiq.environment.platformresource.PlatformParameterService) Transactional(javax.transaction.Transactional) CloudSshKeysToPlatformSshKeysV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudSshKeysToPlatformSshKeysV1ResponseConverter) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) CloudResourceGroups(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups) CloudAccessConfigsToPlatformAccessConfigsV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudAccessConfigsToPlatformAccessConfigsV1ResponseConverter) PlatformEncryptionKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) CloudIpPoolsToPlatformIpPoolsV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudIpPoolsToPlatformIpPoolsV1ResponseConverter) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) PlatformPrivateDnsZonesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformPrivateDnsZonesResponse) List(java.util.List) CloudPrivateDnsZones(com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZones) CloudSecurityGroupsToPlatformSecurityGroupsV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudSecurityGroupsToPlatformSecurityGroupsV1ResponseConverter) CloudVmTypesToPlatformVmTypesV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudVmTypesToPlatformVmTypesV1ResponseConverter) PlatformResourceGroupsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformResourceGroupsResponse) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Controller(org.springframework.stereotype.Controller) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) PlatformVmtypesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformVmtypesResponse) Inject(javax.inject.Inject) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) PlatformAccessConfigsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformAccessConfigsResponse) CloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter) PlatformIpPoolsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformIpPoolsResponse) PlatformRegionsToRegionV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.PlatformRegionsToRegionV1ResponseConverter) Logger(org.slf4j.Logger) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) EnvironmentPlatformResourceEndpoint(com.sequenceiq.environment.api.v1.platformresource.EnvironmentPlatformResourceEndpoint) RegionResponse(com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse) CrnParseException(com.sequenceiq.cloudbreak.auth.crn.CrnParseException) PlatformResourceGroupResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformResourceGroupResponse) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) CloudNetworksToPlatformNetworksV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudNetworksToPlatformNetworksV1ResponseConverter) PlatformSshKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformSshKeysResponse) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) PlatformSecurityGroupsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformSecurityGroupsResponse) CloudGatewayssToPlatformGatewaysV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudGatewayssToPlatformGatewaysV1ResponseConverter) PlatformNoSqlTablesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse) PlatformPrivateDnsZonesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformPrivateDnsZonesResponse) PlatformPrivateDnsZoneResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformPrivateDnsZoneResponse) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CloudPrivateDnsZones(com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZones) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 4 with ResourceCrn

use of com.sequenceiq.authorization.annotation.ResourceCrn in project cloudbreak by hortonworks.

the class EnvironmentPlatformResourceController method getResourceGroups.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)
public PlatformResourceGroupsResponse getResourceGroups(@ResourceCrn String environmentCrn, String region, String platformVariant, String availabilityZone) {
    String accountId = getAccountId();
    validateEnvironmentCrnPattern(environmentCrn);
    PlatformResourceRequest request = platformParameterService.getPlatformResourceRequestByEnvironment(accountId, environmentCrn, region, platformVariant, availabilityZone, null);
    LOGGER.info("Get /platform_resources/resource_groups, request: {}", request);
    CloudResourceGroups resourceGroups = platformParameterService.getResourceGroups(request);
    List<PlatformResourceGroupResponse> platformResourceGroups = resourceGroups.getResourceGroups().stream().map(rg -> new PlatformResourceGroupResponse(rg.getName())).collect(Collectors.toList());
    PlatformResourceGroupsResponse response = new PlatformResourceGroupsResponse(platformResourceGroups);
    LOGGER.info("Resp /platform_resources/resource_groups, request: {}, resourceGroups: {}, response: {}", request, resourceGroups, response);
    return response;
}
Also used : PlatformPrivateDnsZoneResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformPrivateDnsZoneResponse) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) ResourceCrn(com.sequenceiq.authorization.annotation.ResourceCrn) CloudEncryptionKeysToPlatformEncryptionKeysV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudEncryptionKeysToPlatformEncryptionKeysV1ResponseConverter) LoggerFactory(org.slf4j.LoggerFactory) PlatformGatewaysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformGatewaysResponse) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) AccessConfigTypeQueryParam(com.sequenceiq.environment.api.v1.platformresource.model.AccessConfigTypeQueryParam) BadRequestException(javax.ws.rs.BadRequestException) PlatformNetworksResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNetworksResponse) TxType(javax.transaction.Transactional.TxType) PlatformParameterService(com.sequenceiq.environment.platformresource.PlatformParameterService) Transactional(javax.transaction.Transactional) CloudSshKeysToPlatformSshKeysV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudSshKeysToPlatformSshKeysV1ResponseConverter) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) CloudResourceGroups(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups) CloudAccessConfigsToPlatformAccessConfigsV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudAccessConfigsToPlatformAccessConfigsV1ResponseConverter) PlatformEncryptionKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) CloudIpPoolsToPlatformIpPoolsV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudIpPoolsToPlatformIpPoolsV1ResponseConverter) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) PlatformPrivateDnsZonesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformPrivateDnsZonesResponse) List(java.util.List) CloudPrivateDnsZones(com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZones) CloudSecurityGroupsToPlatformSecurityGroupsV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudSecurityGroupsToPlatformSecurityGroupsV1ResponseConverter) CloudVmTypesToPlatformVmTypesV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudVmTypesToPlatformVmTypesV1ResponseConverter) PlatformResourceGroupsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformResourceGroupsResponse) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Controller(org.springframework.stereotype.Controller) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) PlatformVmtypesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformVmtypesResponse) Inject(javax.inject.Inject) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) PlatformAccessConfigsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformAccessConfigsResponse) CloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter) PlatformIpPoolsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformIpPoolsResponse) PlatformRegionsToRegionV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.PlatformRegionsToRegionV1ResponseConverter) Logger(org.slf4j.Logger) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) EnvironmentPlatformResourceEndpoint(com.sequenceiq.environment.api.v1.platformresource.EnvironmentPlatformResourceEndpoint) RegionResponse(com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse) CrnParseException(com.sequenceiq.cloudbreak.auth.crn.CrnParseException) PlatformResourceGroupResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformResourceGroupResponse) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) CloudNetworksToPlatformNetworksV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudNetworksToPlatformNetworksV1ResponseConverter) PlatformSshKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformSshKeysResponse) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) PlatformSecurityGroupsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformSecurityGroupsResponse) CloudGatewayssToPlatformGatewaysV1ResponseConverter(com.sequenceiq.environment.platformresource.v1.converter.CloudGatewayssToPlatformGatewaysV1ResponseConverter) PlatformNoSqlTablesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse) PlatformResourceGroupResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformResourceGroupResponse) CloudResourceGroups(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) PlatformResourceGroupsResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformResourceGroupsResponse) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 5 with ResourceCrn

use of com.sequenceiq.authorization.annotation.ResourceCrn in project cloudbreak by hortonworks.

the class UserV1Controller method getLastSyncOperationStatus.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.GET_OPERATION_STATUS)
public SyncOperationStatus getLastSyncOperationStatus(@ResourceCrn @TenantAwareParam @NotEmpty String environmentCrn) {
    Crn envCrn = Crn.safeFromString(environmentCrn);
    EnvironmentUserSyncState userSyncState = environmentUserSyncStateCalculator.calculateEnvironmentUserSyncState(envCrn.getAccountId(), envCrn);
    return operationToSyncOperationStatus.convert(operationService.getOperationForAccountIdAndOperationId(envCrn.getAccountId(), userSyncState.getLastUserSyncOperationId()));
}
Also used : EnvironmentUserSyncState(com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState) ResourceCrn(com.sequenceiq.authorization.annotation.ResourceCrn) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Aggregations

ResourceCrn (com.sequenceiq.authorization.annotation.ResourceCrn)5 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)5 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)4 List (java.util.List)3 Inject (javax.inject.Inject)3 Controller (org.springframework.stereotype.Controller)3 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)2 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)2 CrnParseException (com.sequenceiq.cloudbreak.auth.crn.CrnParseException)2 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)2 CloudEncryptionKeys (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)2 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)2 CloudIpPools (com.sequenceiq.cloudbreak.cloud.model.CloudIpPools)2 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)2 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)2 CloudSecurityGroups (com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups)2 CloudSshKeys (com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)2 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)2 CloudPrivateDnsZones (com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZones)2 CloudNoSqlTables (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables)2