Search in sources :

Example 46 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class KeystoneService method createOpenStackTenants.

/**
 * Creates representation of OpenStack Tenants in CoprHD.
 *
 * @param param OpenStackTenantListParam OpenStack Tenants representation with all necessary elements.
 * @brief Creates representation of OpenStack Tenants in CoprHD.
 * @return Newly created Tenants.
 * @see
 */
@POST
@Path("/tenants")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public OSTenantListRestRep createOpenStackTenants(OpenStackTenantListParam param) {
    _log.debug("Keystone Service - createOpenStackTenants");
    if (param.getOpenstackTenants() == null || param.getOpenstackTenants().isEmpty()) {
        throw APIException.internalServerErrors.targetIsNullOrEmpty("Tenant list param");
    }
    List<OSTenant> openstackTenants = new ArrayList<>();
    for (OpenStackTenantParam openStackTenantParam : param.getOpenstackTenants()) {
        openstackTenants.add(prepareOpenstackTenant(openStackTenantParam));
    }
    if (!openstackTenants.isEmpty()) {
        _dbClient.createObject(openstackTenants);
    }
    AuthnProvider keystoneProvider = _keystoneUtils.getKeystoneProvider();
    if (keystoneProvider == null) {
        throw APIException.internalServerErrors.targetIsNullOrEmpty("Keystone Authentication Provider");
    }
    if (keystoneProvider.getAutoRegCoprHDNImportOSProjects()) {
        if (_openStackSynchronizationTask.getSynchronizationTask() == null) {
            // Do not create Tenants and Projects once synchronization task is running.
            _authService.createTenantsAndProjectsForAutomaticKeystoneRegistration();
            _openStackSynchronizationTask.startSynchronizationTask(_openStackSynchronizationTask.getTaskInterval(keystoneProvider));
        }
    }
    return map(openstackTenants);
}
Also used : OpenStackTenantParam(com.emc.storageos.model.keystone.OpenStackTenantParam) ArrayList(java.util.ArrayList) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 47 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class MeteringService method getStats.

/**
 * Retrieves the bulk metering stats for all resources in a specified time bucket (minute or hour).
 *
 * @param time_bucket required Time bucket for retrieval of stats. Acceptable formats are: yyyy-MM-dd'T'HH for hour bucket,
 *            yyyy-MM-dd'T'HH:mm for minute bucket
 * @brief List metering statistics for time period
 * @return - Output stream of stats or an error status.
 */
@GET
@Path("/stats")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.SYSTEM_ADMIN })
public Response getStats(@QueryParam("time_bucket") final String timeBucketParam, @Context HttpHeaders header) {
    _logger.debug("getStats: timebucket: {}", timeBucketParam);
    MediaType mediaType = MediaType.APPLICATION_XML_TYPE;
    List<MediaType> mTypes = header.getAcceptableMediaTypes();
    if (mTypes != null) {
        for (MediaType media : mTypes) {
            if (media.equals(MediaType.APPLICATION_JSON_TYPE) || media.equals(MediaType.APPLICATION_XML_TYPE)) {
                mediaType = media;
                break;
            }
        }
    }
    DateTimeFormatter dfHourFormat = DateTimeFormat.forPattern(HOUR_BUCKET_TIME_FORMAT).withZoneUTC();
    DateTimeFormatter dfMinuteFormat = DateTimeFormat.forPattern(MINUTE_BUCKET_TIME_FORMAT).withZoneUTC();
    DateTime timeBucket = null;
    TimeBucket granularity = TimeBucket.HOUR;
    try {
        // we reduce the length by 2 here to account for single quote in yyyy-MM-dd'T'HH format
        if ((null != timeBucketParam) && (timeBucketParam.length() == HOUR_BUCKET_TIME_FORMAT.length() - 2)) {
            timeBucket = dfHourFormat.parseDateTime(timeBucketParam);
            granularity = TimeSeriesMetadata.TimeBucket.HOUR;
        } else if ((null != timeBucketParam) && (timeBucketParam.length() == MINUTE_BUCKET_TIME_FORMAT.length() - 2)) {
            timeBucket = dfMinuteFormat.parseDateTime(timeBucketParam);
            granularity = TimeSeriesMetadata.TimeBucket.MINUTE;
        } else {
            throw APIException.badRequests.invalidTimeBucket(timeBucketParam);
        }
    } catch (final IllegalArgumentException e) {
        throw APIException.badRequests.invalidTimeBucket(timeBucketParam, e);
    }
    if (timeBucket == null) {
        throw APIException.badRequests.invalidTimeBucket(timeBucketParam);
    }
    return Response.ok(getStreamData(timeBucket, granularity, mediaType), mediaType).build();
}
Also used : TimeBucket(com.emc.storageos.db.client.TimeSeriesMetadata.TimeBucket) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 48 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class MigrationService method deleteMigration.

/**
 * Delete a migration that has been committed or cancelled
 *
 * @param id the URN of a ViPR migration.
 *
 * @brief Delete a committed or cancelled migration.
 * @return A TaskResourceRep
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteMigration(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Migration.class, "id");
    Migration migration = queryResource(id);
    if (!BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
        StorageOSUser user = getUserFromContext();
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    }
    String status = migration.getMigrationStatus();
    String migrationName = migration.getLabel();
    if (status == null || status.isEmpty() || migrationName == null || migrationName.isEmpty()) {
        throw APIException.badRequests.migrationHasntStarted(id.toString());
    }
    if (!status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.COMMITTED.getStatusValue()) && !status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue()) && !status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.ERROR.getStatusValue())) {
        throw VPlexApiException.exceptions.cantRemoveMigrationInvalidState(migrationName);
    }
    URI volId = migration.getVolume();
    Volume vplexVol = _dbClient.queryObject(Volume.class, volId);
    // Create a unique task id.
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Volume.class, volId, taskId, ResourceOperationTypeEnum.DELETE_MIGRATION);
    TaskResourceRep task = toTask(vplexVol, taskId, op);
    if (migration.getInactive()) {
        s_logger.info("Migration {} has been deleted", id);
        op.ready();
        vplexVol.getOpStatus().createTaskStatus(taskId, op);
        _dbClient.persistObject(vplexVol);
        return task;
    }
    try {
        VPlexController controller = _vplexBlockServiceApi.getController();
        controller.deleteMigration(vplexVol.getStorageController(), id, taskId);
    } catch (InternalException e) {
        s_logger.error("Error", e);
        String errMsg = String.format("Error: %s", e.getMessage());
        task.setState(Operation.Status.error.name());
        task.setMessage(errMsg);
        op.error(e);
        vplexVol.getOpStatus().updateTaskStatus(taskId, op);
        _dbClient.persistObject(vplexVol);
    }
    return task;
}
Also used : VPlexController(com.emc.storageos.vplexcontroller.VPlexController) Volume(com.emc.storageos.db.client.model.Volume) Migration(com.emc.storageos.db.client.model.Migration) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 49 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class MigrationService method getMigration.

/**
 * Returns the data for the migration with the id specified in the request.
 *
 * @prereq none
 *
 * @param id the URN of a ViPR migration.
 *
 * @brief Show data for a migration.
 * @return A MigrationRestRep instance specifying the information about the
 *         migration.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public MigrationRestRep getMigration(@PathParam("id") URI id) {
    // Return the migration or throw an exception when the user is
    // not authorized or the migration is not found.
    ArgValidator.checkFieldUriType(id, Migration.class, "id");
    Migration migration = queryResource(id);
    if (!BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
        StorageOSUser user = getUserFromContext();
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    } else {
        return map(migration);
    }
}
Also used : Migration(com.emc.storageos.db.client.model.Migration) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 50 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class MigrationService method getMigrations.

/**
 * Returns a list of the migrations the user is permitted to see or an empty
 * list if the user is not authorized for any migrations.
 *
 * @prereq none
 *
 * @brief List migrations
 * @return A MigrationList specifying the name, id, and self link for each
 *         migration.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public MigrationList getMigrations() {
    // Return the migrations the user is authorized to see.
    MigrationList migrationList = new MigrationList();
    List<URI> migrationURIs = _dbClient.queryByType(Migration.class, true);
    Iterator<URI> uriIter = migrationURIs.iterator();
    while (uriIter.hasNext()) {
        Migration migration = queryResource(uriIter.next());
        if (BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
            migrationList.getMigrations().add(toNamedRelatedResource(migration, migration.getLabel()));
        }
    }
    return migrationList;
}
Also used : MigrationList(com.emc.storageos.model.block.MigrationList) Migration(com.emc.storageos.db.client.model.Migration) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CheckPermission (com.emc.storageos.security.authorization.CheckPermission)566 Produces (javax.ws.rs.Produces)512 Path (javax.ws.rs.Path)487 POST (javax.ws.rs.POST)240 Consumes (javax.ws.rs.Consumes)215 GET (javax.ws.rs.GET)194 URI (java.net.URI)185 Operation (com.emc.storageos.db.client.model.Operation)105 ArrayList (java.util.ArrayList)97 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)93 PUT (javax.ws.rs.PUT)85 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)69 Volume (com.emc.storageos.db.client.model.Volume)68 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)65 TaskList (com.emc.storageos.model.TaskList)61 FileShare (com.emc.storageos.db.client.model.FileShare)56 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)54 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)53 NamedURI (com.emc.storageos.db.client.model.NamedURI)47 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)46