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 + ")");
}
}
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;
}
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 + ")");
}
}
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;
}
Aggregations