Search in sources :

Example 46 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class RequestAuthorizator method service.

/**
 * Verifica che l'utente in sessione sia abilitato all'accesso alla pagina richiesta.
 * Se è autorizzato il metodo termina con CONTINUE, altrimenti
 * con REDIRECT impostando prima i parametri di redirezione alla pagina di login.
 * @param reqCtx Il contesto di richiesta
 * @param status Lo stato di uscita del servizio precedente
 * @return Lo stato di uscita
 */
@Override
public int service(RequestContext reqCtx, int status) {
    _logger.debug("Invoked: {}", this.getClass().getName());
    int retStatus = ControllerManager.INVALID_STATUS;
    if (status == ControllerManager.ERROR) {
        return status;
    }
    try {
        HttpServletRequest req = reqCtx.getRequest();
        HttpSession session = req.getSession();
        IPage currentPage = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        if (null == currentUser) {
            throw new ApsSystemException("no user on session");
        }
        boolean authorized = this.getAuthManager().isAuth(currentUser, currentPage);
        if (authorized) {
            retStatus = ControllerManager.CONTINUE;
        } else {
            StringBuilder targetUrl = new StringBuilder(req.getRequestURL());
            String queryString = req.getQueryString();
            if (null != queryString && queryString.trim().length() > 0) {
                targetUrl.append("?").append(queryString);
            }
            Map<String, String> params = new HashMap<String, String>();
            params.put("returnUrl", URLEncoder.encode(targetUrl.toString(), "UTF-8"));
            retStatus = this.redirect(this.getLoginPageCode(), params, reqCtx);
        }
    } catch (Throwable t) {
        _logger.error("Error while processing the request", t);
        // ApsSystemUtils.logThrowable(t, this, "service", "Error while processing the request");
        retStatus = ControllerManager.SYS_ERROR;
        reqCtx.setHTTPError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return retStatus;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(com.agiletec.aps.system.services.page.IPage) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 47 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class RequestValidator method getPage.

/**
 * Qualora si usasse il mapping /pages/* restituisce un'oggetto IPage solo
 * nel caso in cui il path completo della pagina risulti corretto. Qualora
 * il path sia di lunghezza pari a zero verrà restituita l'homepage.
 *
 * @param Matcher
 * il matcher valorizzato come segue<br>
 * matcher.group(1) -> lang_code<br>
 * matcher.group(2) -> /paginaX/paginaY<br>
 * matcher.group(3) -> /paginaY<br>
 * @return un oggetto Page oppure null
 */
private IPage getPage(Matcher matcher) {
    IPage page = null;
    String rootCode = this.getPageManager().getOnlineRoot().getCode();
    String path = matcher.group(2);
    // Se il path è di tipo /it o /it/ o /it/homepage
    if (path.trim().length() == 0 || path.substring(1).equals(rootCode)) {
        return this.getPageManager().getOnlineRoot();
    }
    String pageCode = matcher.group(3).substring(1);
    IPage tempPage = this.getPageManager().getOnlinePage(pageCode);
    if (null != tempPage) {
        // la pagina esiste ed è di livello 1
        // if(tempPage.getParentCode().equals(rootCode)) return tempPage;
        // la pagina è di livello superiore al primo e il path è corretto
        String fullPath = matcher.group(2).substring(1).trim();
        String createdlFullPath = PageUtils.getFullPath(this.getPageManager(), tempPage, "/").toString();
        if (null != tempPage && createdlFullPath.equals(fullPath)) {
            page = tempPage;
        }
    }
    return page;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage)

Example 48 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class PreviewRequestAuthorizator method service.

/**
 * Verifica che l'utente in sessione sia abilitato all'accesso alla pagina richiesta.
 * Se è autorizzato il metodo termina con CONTINUE, altrimenti con SYS_ERROR.
 * @param reqCtx Il contesto di richiesta
 * @param status Lo stato di uscita del servizio precedente
 * @return Lo stato di uscita
 */
@Override
public int service(RequestContext reqCtx, int status) {
    _logger.debug("Invoked: {}", this.getClass().getName());
    int retStatus = ControllerManager.INVALID_STATUS;
    if (status == ControllerManager.ERROR) {
        return status;
    }
    try {
        HttpServletRequest request = reqCtx.getRequest();
        HttpSession session = request.getSession();
        IPage currentPage = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        if (null == currentUser) {
            currentUser = this.getUserManager().getGuestUser();
            session.setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, currentUser);
        }
        if (this.isAllowed(currentUser, currentPage, request)) {
            retStatus = ControllerManager.CONTINUE;
        } else {
            retStatus = ControllerManager.SYS_ERROR;
        }
    } catch (Throwable t) {
        _logger.error("Error while processing the request", t);
        // ApsSystemUtils.logThrowable(t, this, "service", "Error while processing the request");
        retStatus = ControllerManager.SYS_ERROR;
        reqCtx.setHTTPError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return retStatus;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(com.agiletec.aps.system.services.page.IPage) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HttpSession(javax.servlet.http.HttpSession)

Example 49 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class TestRequestValidator method testService.

public void testService() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();
    ((MockHttpServletRequest) reqCtx.getRequest()).setServletPath("/it/homepage.wp");
    int status = this._requestValidator.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(ControllerManager.CONTINUE, status);
    Lang lang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
    assertNotNull(page);
    assertNotNull(lang);
    assertEquals("it", lang.getCode());
    assertEquals("homepage", page.getCode());
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 50 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class PageManagerCacheWrapper method moveUpDown.

@Override
public void moveUpDown(String pageDown, String pageUp) {
    IPage draftToMoveUp = this.getDraftPage(pageUp);
    IPage draftToMoveDown = this.getDraftPage(pageDown);
    if (null != draftToMoveDown && null != draftToMoveUp && draftToMoveDown.getParentCode().equals(draftToMoveUp.getParentCode())) {
        Cache cache = this.getCache();
        draftToMoveUp.setPosition(draftToMoveUp.getPosition() - 1);
        cache.put(DRAFT_PAGE_CACHE_NAME_PREFIX + draftToMoveUp.getCode(), draftToMoveUp);
        draftToMoveDown.setPosition(draftToMoveDown.getPosition() + 1);
        cache.put(DRAFT_PAGE_CACHE_NAME_PREFIX + draftToMoveDown.getCode(), draftToMoveDown);
        this.upgradePositionOnOnlineVersion(pageUp, draftToMoveUp.getPosition(), cache);
        this.upgradePositionOnOnlineVersion(pageDown, draftToMoveDown.getPosition(), cache);
        if (draftToMoveUp.getPosition() < draftToMoveDown.getPosition()) {
            this.switchSisterOnParent(draftToMoveUp.getParentCode(), pageUp, pageDown, cache, false);
            this.switchSisterOnParent(draftToMoveUp.getParentCode(), pageUp, pageDown, cache, true);
        }
    } else {
        _logger.error("Movement impossible - page to move up {} - page to move down {}", pageUp, pageDown);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Cache(org.springframework.cache.Cache)

Aggregations

IPage (com.agiletec.aps.system.services.page.IPage)253 Widget (com.agiletec.aps.system.services.page.Widget)55 ArrayList (java.util.ArrayList)41 Page (com.agiletec.aps.system.services.page.Page)37 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)30 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)25 HashMap (java.util.HashMap)23 ApsProperties (com.agiletec.aps.util.ApsProperties)20 List (java.util.List)20 RestServerError (org.entando.entando.aps.system.exception.RestServerError)18 IPageManager (com.agiletec.aps.system.services.page.IPageManager)16 UserDetails (com.agiletec.aps.system.services.user.UserDetails)16 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)16 RequestContext (com.agiletec.aps.system.RequestContext)15 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)15 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)15 Test (org.junit.Test)14 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)13 Lang (com.agiletec.aps.system.services.lang.Lang)12 ResultActions (org.springframework.test.web.servlet.ResultActions)12