Search in sources :

Example 1 with RangerSecurityZoneValidator

use of org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator in project ranger by apache.

the class SecurityZoneREST method deleteSecurityZone.

@DELETE
@Path("/zones/{id}")
public void deleteSecurityZone(@PathParam("id") Long zoneId) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> deleteSecurityZone(id=" + zoneId + ")");
    }
    if (zoneId != null && zoneId.equals(RangerSecurityZone.RANGER_UNZONED_SECURITY_ZONE_ID)) {
        throw restErrorUtil.createRESTException("Cannot delete unzoned zone");
    }
    try {
        ensureAdminAccess();
        RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
        validator.validate(zoneId, RangerValidator.Action.DELETE);
        securityZoneStore.deleteSecurityZoneById(zoneId);
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("deleteSecurityZone(" + zoneId + ") failed", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== deleteSecurityZone(id=" + zoneId + ")");
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerSecurityZoneValidator(org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 2 with RangerSecurityZoneValidator

use of org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator in project ranger by apache.

the class SecurityZoneREST method updateSecurityZone.

@PUT
@Path("/zones/{id}")
public RangerSecurityZone updateSecurityZone(@PathParam("id") Long zoneId, RangerSecurityZone securityZone) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> updateSecurityZone(id=" + zoneId + ", " + securityZone + ")");
    }
    if (zoneId != null && zoneId.equals(RangerSecurityZone.RANGER_UNZONED_SECURITY_ZONE_ID)) {
        throw restErrorUtil.createRESTException("Cannot update unzoned zone");
    }
    ensureUserAllowOperationOnServiceForZone(securityZone);
    removeEmptyEntries(securityZone);
    if (securityZone.getId() != null && !zoneId.equals(securityZone.getId())) {
        throw restErrorUtil.createRESTException("zoneId mismatch!!");
    } else {
        securityZone.setId(zoneId);
    }
    RangerSecurityZone ret;
    try {
        RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
        validator.validate(securityZone, RangerValidator.Action.UPDATE);
        ret = securityZoneStore.updateSecurityZoneById(securityZone);
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("updateSecurityZone(" + securityZone + ") failed", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== updateSecurityZone(id=" + zoneId + ", " + securityZone + "):" + ret);
    }
    return ret;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) WebApplicationException(javax.ws.rs.WebApplicationException) RangerSecurityZoneValidator(org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 3 with RangerSecurityZoneValidator

use of org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator in project ranger by apache.

the class SecurityZoneREST method deleteSecurityZone.

@DELETE
@Path("/zones/name/{name}")
public void deleteSecurityZone(@PathParam("name") String zoneName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> deleteSecurityZone(name=" + zoneName + ")");
    }
    try {
        ensureAdminAccess();
        RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
        validator.validate(zoneName, RangerValidator.Action.DELETE);
        securityZoneStore.deleteSecurityZoneByName(zoneName);
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("deleteSecurityZone(" + zoneName + ") failed", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== deleteSecurityZone(name=" + zoneName + ")");
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerSecurityZoneValidator(org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 4 with RangerSecurityZoneValidator

use of org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator in project ranger by apache.

the class SecurityZoneREST method createSecurityZone.

@POST
@Path("/zones")
public RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createSecurityZone(" + securityZone + ")");
    }
    RangerSecurityZone ret;
    try {
        ensureAdminAccess(securityZone);
        removeEmptyEntries(securityZone);
        RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
        validator.validate(securityZone, RangerValidator.Action.CREATE);
        ret = securityZoneStore.createSecurityZone(securityZone);
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("createSecurityZone(" + securityZone + ") failed", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== createSecurityZone(" + securityZone + "):" + ret);
    }
    return ret;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) WebApplicationException(javax.ws.rs.WebApplicationException) RangerSecurityZoneValidator(org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

Path (javax.ws.rs.Path)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 RangerSecurityZoneValidator (org.apache.ranger.plugin.model.validation.RangerSecurityZoneValidator)4 DELETE (javax.ws.rs.DELETE)2 RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)2 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1