Search in sources :

Example 1 with ResourceInterface

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;
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResourceInstance(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 2 with ResourceInterface

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);
    }
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 3 with ResourceInterface

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;
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 4 with ResourceInterface

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);
    }
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 5 with ResourceInterface

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;
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Aggregations

ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)45 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)8 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 Category (com.agiletec.aps.system.services.category.Category)4 AbstractResourceAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute)4 ImageResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource)4 ResourceInstance (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance)3 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)2 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)2 Lang (com.agiletec.aps.system.services.lang.Lang)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 AttachResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)2 ResourceRecordVO (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO)2 ArrayList (java.util.ArrayList)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)2 MockResourcesDAO (com.agiletec.aps.services.mock.MockResourcesDAO)1 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1