use of org.candlepin.common.exceptions.IseException in project candlepin by candlepin.
the class SyncUtils method makeTempDir.
File makeTempDir(String baseName) throws IOException {
File baseDir = new File(config.getString(ConfigProperties.SYNC_WORK_DIR));
if (!baseDir.exists() && !baseDir.mkdirs()) {
throw new IseException("Unable to create base dir for sync: " + baseDir);
}
File tmp = File.createTempFile(baseName, Long.toString(System.nanoTime()), baseDir);
if (!tmp.delete()) {
throw new IOException("Could not delete temp file: " + tmp.getAbsolutePath());
}
if (!tmp.mkdirs()) {
throw new IOException("Could not create temp directory: " + tmp.getAbsolutePath());
}
return (tmp);
}
use of org.candlepin.common.exceptions.IseException in project candlepin by candlepin.
the class ConsumerResource method exportData.
/**
* Retrieves a compressed file representation of a Consumer (manifest).
*
* @deprecated use GET /consumers/:consumer_uuid/export/async
* @param response
* @param consumerUuid
* @param cdnLabel
* @param webAppPrefix
* @param apiUrl
* @return the generated file archive.
*/
@Deprecated
@ApiOperation(notes = "Retrieves a Compressed File representation of a Consumer (manifest).", value = "Consumer Export (manifest)", response = File.class)
@ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") })
@Produces("application/zip")
@GET
@Path("{consumer_uuid}/export")
public File exportData(@Context HttpServletResponse response, @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("cdn_label") String cdnLabel, @QueryParam("webapp_prefix") String webAppPrefix, @QueryParam("api_url") String apiUrl, @QueryParam("ext") @CandlepinParam(type = KeyValueParameter.class) @ApiParam(value = "Key/Value pairs to be passed to the extension adapter when generating a manifest", required = false, example = "ext=version:1.2.3&ext=extension_key:EXT1") List<KeyValueParameter> extensionArgs) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
throw new BadRequestException(i18n.tr("Can not export manifest of a share consumer"));
}
try {
File archive = manifestManager.generateManifest(consumerUuid, cdnLabel, webAppPrefix, apiUrl, getExtensionParamMap(extensionArgs));
response.addHeader("Content-Disposition", "attachment; filename=" + archive.getName());
return archive;
} catch (ExportCreationException e) {
throw new IseException(i18n.tr("Unable to create export archive"), e);
}
}
use of org.candlepin.common.exceptions.IseException in project candlepin by candlepin.
the class CrlResource method getCurrentCrl.
@ApiOperation(notes = "Retrieves the Certificate Revocation List", value = "getCurrentCrl", response = String.class)
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response getCurrentCrl(@Context Principal principal) throws CRLException {
String filePath = getCrlFilePath();
File crlFile = new File(filePath);
try {
this.crlFileUtil.syncCRLWithDB(crlFile);
// Create an empty CRL if we didn't have anything to write
if (!crlFile.exists() || crlFile.length() < 1) {
pkiUtility.writePemEncoded(pkiUtility.createX509CRL(new LinkedList<>(), BigInteger.ZERO), new FileOutputStream(crlFile));
}
return Response.ok().entity(new FileInputStream(crlFile)).build();
} catch (IOException e) {
throw new IseException(e.getMessage(), e);
}
}
use of org.candlepin.common.exceptions.IseException in project candlepin by candlepin.
the class VerifyAuthorizationFilter method runFilter.
@Override
public void runFilter(ContainerRequestContext requestContext) {
HttpRequest request = ResteasyProviderFactory.getContextData(HttpRequest.class);
Principal principal = (Principal) requestContext.getSecurityContext().getUserPrincipal();
ResourceInfo resourceInfo = ResteasyProviderFactory.getContextData(ResourceInfo.class);
Method method = resourceInfo.getResourceMethod();
if (log.isDebugEnabled()) {
log.debug("Authorization check for {} mapping to {}.{}", requestContext.getUriInfo().getPath(), method.getDeclaringClass().getName(), method.getName());
}
Map<Verify, Object> argMap = getArguments(request, method);
// Couldn't find a match in Resteasy for method
if (argMap.isEmpty()) {
/* It would also be possible to get here if a super-admin only method
* were inadvertently being filtered through this filter. Normally the
* AuthorizationFeature takes care of sending methods without any @Verify
* annotations through the SuperAdminAuthorizationFilter */
throw new IseException("Could not get parameters for " + method);
}
Access defaultAccess = getDefaultAccess(method);
if (!hasAccess(argMap, principal, defaultAccess)) {
denyAccess(principal, method);
}
}
use of org.candlepin.common.exceptions.IseException in project candlepin by candlepin.
the class VerifyAuthorizationFilter method hasAccess.
protected boolean hasAccess(Map<Verify, Object> argMap, Principal principal, Access defaultAccess) {
boolean hasAccess = false;
Owner owner = null;
for (Map.Entry<Verify, Object> entry : argMap.entrySet()) {
List<Persisted> accessedObjects = new ArrayList<>();
Object obj = entry.getValue();
Verify verify = entry.getKey();
Class<? extends Persisted> verifyType = verify.value();
accessedObjects.addAll(getAccessedEntities(verify, obj));
Access requiredAccess = defaultAccess;
if (verify.require() != Access.NONE) {
requiredAccess = verify.require();
}
log.debug("Verifying {} access to {}: {}", requiredAccess, verifyType, obj);
SubResource subResource = verify.subResource();
for (Persisted entity : accessedObjects) {
if (!principal.canAccess(entity, subResource, requiredAccess)) {
hasAccess = false;
break;
}
hasAccess = true;
Owner entityOwner = ((EntityStore) storeFactory.getFor(verifyType)).getOwner(entity);
if (entityOwner != null) {
if (owner != null && !owner.equals(entityOwner)) {
log.error("Found entities from multiple orgs in a single request");
throw new IseException("Found entities from multiple orgs in a single request");
}
owner = entityOwner;
}
}
// Stop all further checking with any authorization failure
if (!hasAccess) {
break;
}
}
if (hasAccess && owner != null) {
MDC.put("org", owner.getKey());
if (owner.getLogLevel() != null) {
MDC.put("orgLogLevel", owner.getLogLevel());
}
}
return hasAccess;
}
Aggregations