Search in sources :

Example 1 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails 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 UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApiContentInterface method addContent.

public StringApiResponse addContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbContent.getTypeCode();
        Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
        }
        Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
        if (null != content.getId()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "You cannot specify Content Id", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        content.setFirstEditor((null != user) ? user.getUsername() : SystemConstants.GUEST_USER_NAME);
        response = this.validateAndSaveContent(content, properties);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error adding content", t);
        throw new ApsSystemException("Error adding content", t);
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 3 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApiContentInterface method extractContents.

protected List<String> extractContents(Properties properties) throws Throwable {
    List<String> contentsId = null;
    try {
        ApiContentListBean bean = this.buildSearchBean(properties);
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        contentsId = this.getContentListHelper().getContentsId(bean, user);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in extractContents", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return contentsId;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApiContentListBean(org.entando.entando.plugins.jacms.aps.system.services.api.model.ApiContentListBean) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 4 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApiResourceInterface method addResource.

public StringApiResponse addResource(JAXBResource jaxbResource, Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    BaseResourceDataBean bean = null;
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.check(jaxbResource, user, response, true);
        if (null != response.getErrors() && !response.getErrors().isEmpty()) {
            return response;
        }
        bean = jaxbResource.createBataBean(this.getCategoryManager());
        String id = bean.getResourceId();
        if (null != id && id.trim().length() > 0) {
            Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
            Matcher matcher = pattern.matcher(id);
            if (!matcher.matches()) {
                throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "The resourceId can contain only alphabetic characters", Response.Status.CONFLICT);
            }
        }
        this.getResourceManager().addResource(bean);
        response.setResult(IResponseBuilder.SUCCESS);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in addResource", t);
        throw new ApsSystemException("Error into API method", t);
    } finally {
        if (null != bean && null != bean.getFile()) {
            bean.getFile().delete();
        }
    }
    return response;
}
Also used : Pattern(java.util.regex.Pattern) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Matcher(java.util.regex.Matcher) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 5 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApiResourceInterface method updateResource.

public StringApiResponse updateResource(JAXBResource jaxbResource, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    BaseResourceDataBean bean = null;
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.check(jaxbResource, user, response, false);
        if (null != response.getErrors() && !response.getErrors().isEmpty()) {
            return response;
        }
        bean = jaxbResource.createBataBean(this.getCategoryManager());
        this.getResourceManager().updateResource(bean);
        response.setResult(IResponseBuilder.SUCCESS);
    } catch (Throwable t) {
        _logger.error("error in updateResource", t);
        throw new ApsSystemException("Error into API method", t);
    } finally {
        if (null != bean && null != bean.getFile()) {
            bean.getFile().delete();
        }
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)271 Test (org.junit.Test)150 ResultActions (org.springframework.test.web.servlet.ResultActions)142 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)77 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)71 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 Group (com.agiletec.aps.system.services.group.Group)15 ArrayList (java.util.ArrayList)15 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)14 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)12 HttpSession (javax.servlet.http.HttpSession)12 RestListRequest (org.entando.entando.web.common.model.RestListRequest)12 HashMap (java.util.HashMap)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)9 IPage (com.agiletec.aps.system.services.page.IPage)8 JspException (javax.servlet.jsp.JspException)8 Page (com.agiletec.aps.system.services.page.Page)7