use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance in project entando-core by entando.
the class ProtectedResourceProvider method provideProtectedResource.
@Override
public boolean provideProtectedResource(HttpServletRequest request, HttpServletResponse response) throws ApsSystemException {
try {
String[] uriSegments = request.getRequestURI().split("/");
int segments = uriSegments.length;
// CONTROLLO ASSOCIAZIONE RISORSA A CONTENUTO
int indexGuardian = 0;
String checkContentAssociation = uriSegments[segments - 2];
if (checkContentAssociation.equals(AbstractResourceAttribute.REFERENCED_RESOURCE_INDICATOR)) {
// LA Sintassi /<RES_ID>/<SIZE>/<LANG_CODE>/<REFERENCED_RESOURCE_INDICATOR>/<CONTENT_ID>
indexGuardian = 2;
}
String resId = uriSegments[segments - 3 - indexGuardian];
UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
if (currentUser == null) {
currentUser = this.getUserManager().getGuestUser();
}
boolean isAuthForProtectedRes = false;
if (indexGuardian != 0) {
if (this.isAuthOnProtectedRes(currentUser, resId, uriSegments[segments - 1])) {
isAuthForProtectedRes = true;
} else {
this.executeLoginRedirect(request, response);
return true;
}
}
ResourceInterface resource = this.getResourceManager().loadResource(resId);
if (resource == null) {
return false;
}
IAuthorizationManager authManager = this.getAuthorizationManager();
if (isAuthForProtectedRes || authManager.isAuthOnGroup(currentUser, resource.getMainGroup()) || authManager.isAuthOnGroup(currentUser, Group.ADMINS_GROUP_NAME)) {
ResourceInstance instance = null;
if (resource.isMultiInstance()) {
String sizeStr = uriSegments[segments - 2 - indexGuardian];
if (!this.isValidNumericString(sizeStr)) {
return false;
}
int size = Integer.parseInt(sizeStr);
String langCode = uriSegments[segments - 1 - indexGuardian];
instance = ((AbstractMultiInstanceResource) resource).getInstance(size, langCode);
} else {
instance = ((AbstractMonoInstanceResource) resource).getInstance();
}
this.createResponse(response, resource, instance);
return true;
}
} catch (Throwable t) {
_logger.error("Error extracting protected resource", t);
throw new ApsSystemException("Error extracting protected resource", t);
}
return false;
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance in project entando-core by entando.
the class AbstractImageResizer method saveResizedImage.
@Override
public ResourceInstance saveResizedImage(String subPath, boolean isProtectedResource, ImageIcon imageIcon, ImageResourceDimension dimension) throws ApsSystemException {
ResourceInstance resizedInstance = new ResourceInstance();
resizedInstance.setSize(dimension.getIdDim());
BufferedImage outImage = this.getResizedImage(imageIcon, dimension.getDimx(), dimension.getDimy());
String filename = subPath.substring(subPath.lastIndexOf("/") + 1);
resizedInstance.setFileName(filename);
String tempFilePath = System.getProperty("java.io.tmpdir") + File.separator + "temp_" + filename;
try {
File tempFile = new File(tempFilePath);
ImageIO.write(outImage, this.getFileExtension(tempFilePath), tempFile);
this.getStorageManager().saveFile(subPath, isProtectedResource, new FileInputStream(tempFile));
// resizedInstance.setMimeType(bean.getMimeType());
long realLength = tempFile.length() / 1000;
resizedInstance.setFileLength(String.valueOf(realLength) + " Kb");
tempFile.delete();
} catch (Throwable t) {
_logger.error("Error creating resized Image", t);
String msg = "Error creating resigned Image";
// ApsSystemUtils.logThrowable(t, this, "saveImageResized", msg);
throw new ApsSystemException(msg, t);
}
String mimeType = URLConnection.guessContentTypeFromName(filename);
resizedInstance.setMimeType(mimeType);
return resizedInstance;
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance in project entando-core by entando.
the class ResourceManagerIntegrationTest method testAddRemoveImageResource.
private void testAddRemoveImageResource(String mainGroup) throws Throwable {
List<String> allowedGroups = this.getAllGroupCodes();
ResourceInterface res = null;
String resDescrToAdd = "Entando Logo";
String resourceType = "Image";
String categoryCodeToAdd = "resCat1";
ResourceDataBean bean = this.getMockResource(resourceType, mainGroup, resDescrToAdd, categoryCodeToAdd);
try {
List<String> resourcesId = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
assertEquals(1, resourcesId.size());
this._resourceManager.addResource(bean);
resourcesId = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, null, allowedGroups);
assertEquals(resourcesId.size(), 1);
resourcesId = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, categoryCodeToAdd, allowedGroups);
assertEquals(resourcesId.size(), 1);
res = this._resourceManager.loadResource(resourcesId.get(0));
assertTrue(res instanceof ImageResource);
assertEquals(res.getCategories().size(), 1);
assertEquals(res.getDescription(), resDescrToAdd);
ResourceInstance instance0 = ((ImageResource) res).getInstance(0, null);
assertEquals("entando_logo.jpg", res.getMasterFileName());
assertEquals("image/jpeg", instance0.getMimeType());
resourcesId = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
assertEquals(resourcesId.size(), 2);
} catch (Throwable t) {
throw t;
} finally {
if (res != null) {
this._resourceManager.deleteResource(res);
List<String> resources = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, null, allowedGroups);
assertEquals(resources.size(), 0);
resources = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
assertEquals(resources.size(), 1);
}
}
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance in project entando-core by entando.
the class ResourceManager method refreshMasterFileNames.
protected void refreshMasterFileNames(String resourceId) {
try {
ResourceInterface resource = this.loadResource(resourceId);
if (resource.isMultiInstance()) {
ResourceInstance instance = ((AbstractMultiInstanceResource) resource).getInstance(0, null);
String filename = instance.getFileName();
int index = filename.lastIndexOf("_d0.");
String masterFileName = filename.substring(0, index) + filename.substring(index + 3);
resource.setMasterFileName(masterFileName);
} else {
ResourceInstance instance = ((AbstractMonoInstanceResource) resource).getInstance();
resource.setMasterFileName(instance.getFileName());
}
this.updateResource(resource);
} catch (Throwable t) {
logger.error("Error reloading master file name of resource {}", resourceId, t);
}
}
Aggregations