use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface 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.ResourceInterface in project entando-core by entando.
the class ApiResourceInterface method check.
private void check(JAXBResource jaxbResource, UserDetails user, StringApiResponse response, boolean add) throws Throwable {
ResourceInterface resourcePrototype = this.getResourceManager().createResourceType(jaxbResource.getTypeCode());
if (null == resourcePrototype) {
this.addValidationError("Invalid resource type - '" + jaxbResource.getTypeCode() + "'", response);
}
if (null == user) {
user = this.getUserManager().getGuestUser();
}
String groupName = jaxbResource.getMainGroup();
if (null == groupName || groupName.trim().length() == 0) {
this.addValidationError("Group required", response);
} else {
if (null == this.getGroupManager().getGroup(groupName)) {
// this.addValidationError("Group '" + groupName + "' does not exist", response);
} else if (!this.getAuthorizationManager().isAuthOnGroup(user, groupName)) {
// this.addValidationError("Group '" + groupName + "' not allowed", response);
}
}
if (add) {
if (null == jaxbResource.getBase64()) {
this.addValidationError("Binary Image required", response);
}
if (null == jaxbResource.getFileName() || jaxbResource.getFileName().trim().length() == 0) {
this.addValidationError("FileName required", response);
}
} else {
ResourceInterface oldResource = this.getResourceManager().loadResource(jaxbResource.getId());
if (null == oldResource) {
this.addValidationError("Resource with id '" + jaxbResource.getId() + "' does not exist", response);
} else if (!oldResource.getMainGroup().equals(jaxbResource.getMainGroup())) {
this.addValidationError("Resource group has to be '" + oldResource.getMainGroup() + "'", response);
}
}
/*
if (this.isDuplicateFile(jaxbResource, resourcePrototype, add)) {
this.addValidationError("File '" + jaxbResource.getFileName() + "' is already present on Archive", response);
}
*/
if (null == jaxbResource.getDescription() || jaxbResource.getDescription().trim().length() == 0) {
this.addValidationError("Description required", response);
}
if (null == jaxbResource.getTypeCode() || jaxbResource.getTypeCode().trim().length() == 0) {
this.addValidationError("TypeCode required", response);
}
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class ResourceManager method createResource.
/**
* Metodo di servizio. Restituisce una risorsa
* in base ai dati del corrispondente record.
* @param resourceVo Il vo relativo al record.
* @return La risorsa valorizzata.
* @throws ApsSystemException in caso di errore.
*/
protected ResourceInterface createResource(ResourceRecordVO resourceVo) throws ApsSystemException {
String resourceType = resourceVo.getResourceType();
String resourceXML = resourceVo.getXml();
ResourceInterface resource = this.createResourceType(resourceType);
this.fillEmptyResourceFromXml(resource, resourceXML);
resource.setMainGroup(resourceVo.getMainGroup());
resource.setCreationDate(resourceVo.getCreationDate());
resource.setLastModified(resourceVo.getLastModified());
return resource;
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class ResourceManager method refreshResourceInstances.
protected void refreshResourceInstances(String resourceId) {
try {
ResourceInterface resource = this.loadResource(resourceId);
resource.reloadResourceInstances();
this.updateResource(resource);
} catch (Throwable t) {
logger.error("Error refreshing resource instances of resource {}", resourceId, t);
}
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class ResourceManager method createResource.
protected ResourceInterface createResource(ResourceDataBean bean) throws ApsSystemException {
ResourceInterface resource = this.createResourceType(bean.getResourceType());
resource.setDescription(bean.getDescr());
resource.setMainGroup(bean.getMainGroup());
resource.setCategories(bean.getCategories());
resource.setMasterFileName(bean.getFileName());
resource.setId(bean.getResourceId());
return resource;
}
Aggregations