Search in sources :

Example 6 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException in project Asqatasun by Asqatasun.

the class ContractControllerTest method testDisplayContractPage_4args.

/**
     * Test of displayContractPage method, of class HomeController.
     */
public void testDisplayContractPage_4args() {
    System.out.println("displayContractPage");
    setUpUserDataService(false);
    setUpContractDataService(1);
    setUpActDataService(1, 1, 2, 1, 1);
    setUpLocaleResolver();
    setUpActionHandler(1);
    setUpMockAuthenticationContext();
    // contractId cannot be converted as a long, the ForbiddenUserException 
    // is caught
    String contractId = "wrongId";
    HttpServletRequest request = null;
    HttpServletResponse response = null;
    Model model = new ExtendedModelMap();
    try {
        instance.displayContractPage(contractId, request, response, model);
        // if the exception is not caught, the test is on error
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
    contractId = "1";
    String result = instance.displayContractPage(contractId, request, response, model);
    String expResult = TgolKeyStore.CONTRACT_VIEW_NAME;
    assertEquals(expResult, result);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) HttpServletResponse(javax.servlet.http.HttpServletResponse) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 7 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException in project Asqatasun by Asqatasun.

the class AuditSetUpControllerTest method testDisplayPageAuditSiteSetUpWithUnauthorisedFunctionality.

public void testDisplayPageAuditSiteSetUpWithUnauthorisedFunctionality() {
    System.out.println("testDisplayPageAuditSiteSetUpWithUnauthorisedFunctionality");
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(2, "Contract1");
    setUpEmptyViewFunctionalityBindingMap();
    // regarding the viewFunctionalityBindingMap. An exception is caught
    try {
        instance.displaySiteAuditSetUp("2", null, null, new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 8 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException in project Asqatasun by Asqatasun.

the class AbstractAuditDataHandlerController method preparePageListStatsByHttpStatusCode.

/**
     * 
     * @param audit
     * @param model
     * @param httpStatusCode
     * @param request
     * @param returnRedirectView
     * @return
     * @throws ServletRequestBindingException 
     */
protected String preparePageListStatsByHttpStatusCode(Audit audit, Model model, HttpStatusCodeFamily httpStatusCode, HttpServletRequest request, boolean returnRedirectView) throws ServletRequestBindingException {
    String invalidTest = ServletRequestUtils.getStringParameter(request, TgolPaginatedListFactory.INVALID_TEST_PARAM);
    if (invalidTest != null && !this.invalidTestValueCheckerPattern.matcher(invalidTest).matches()) {
        throw new ForbiddenPageException();
    }
    PaginatedList paginatedList = TgolPaginatedListFactory.getInstance().getPaginatedList(httpStatusCode, ServletRequestUtils.getStringParameter(request, TgolPaginatedListFactory.PAGE_SIZE_PARAM), ServletRequestUtils.getStringParameter(request, TgolPaginatedListFactory.SORT_DIRECTION_PARAM), ServletRequestUtils.getStringParameter(request, TgolPaginatedListFactory.SORT_CRITERION_PARAM), ServletRequestUtils.getStringParameter(request, TgolPaginatedListFactory.PAGE_PARAM), ServletRequestUtils.getStringParameter(request, TgolPaginatedListFactory.SORT_CONTAINING_URL_PARAM), invalidTest, authorizedPageSize, authorizedSortCriterion, audit.getId());
    model.addAttribute(TgolKeyStore.PAGE_LIST_KEY, paginatedList);
    model.addAttribute(TgolKeyStore.AUTHORIZED_PAGE_SIZE_KEY, authorizedPageSize);
    model.addAttribute(TgolKeyStore.AUTHORIZED_SORT_CRITERION_KEY, authorizedSortCriterion);
    setFromToValues(paginatedList, model);
    //        addAuditStatisticsToModel(audit, model, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE);
    return (returnRedirectView) ? TgolKeyStore.PAGE_LIST_XXX_VIEW_REDIRECT_NAME : TgolKeyStore.PAGE_LIST_XXX_VIEW_NAME;
}
Also used : PaginatedList(org.displaytag.pagination.PaginatedList) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 9 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException in project Asqatasun by Asqatasun.

the class AbstractAuditSetUpController method displayAuditSetUpView.

/**
     * 
     * @param viewName
     * @param contractId
     * @param scenarioId
     * @param optionFormFieldBuilderMap
     * @param scope
     * @param model
     * @return 
     */
protected String displayAuditSetUpView(String viewName, String contractId, String scenarioId, Map<String, List<AuditSetUpFormFieldBuilderImpl>> optionFormFieldBuilderMap, ScopeEnum scope, Model model) {
    Long contractIdValue;
    try {
        contractIdValue = Long.valueOf(contractId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException(getCurrentUser());
    }
    Contract contract = getContractDataService().read(contractIdValue);
    if (isUserAllowedToDisplaySetUpPage(contract, viewName)) {
        Collection<String> authorisedReferentialList = getAuthorisedReferentialCodeFromContract(contract);
        // Get a fresh list of the auditSetUpFormField that handles the choice
        // of the referential and its level
        List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
        String defaultRef = getDefaultReferential(authorisedReferentialList);
        AuditSetUpFormFieldHelper.selectDefaultLevelFromRefValue(refAndLevelFormFieldList, defaultRef);
        // Get a fresh map of auditSetUpFormField. The value of the field is
        // them set by Parameter mapping handled by the AuditSetUpCommandObject
        Map<String, List<AuditSetUpFormField>> optionFormFieldMap = this.getFreshAuditSetUpFormFieldMap(contract, optionFormFieldBuilderMap);
        AuditSetUpCommand asuc;
        // instance of AuditSetUpCommand
        switch(scope) {
            case DOMAIN:
                asuc = AuditSetUpCommandFactory.getInstance().getSiteAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case FILE:
            case GROUPOFFILES:
                asuc = AuditSetUpCommandFactory.getInstance().getUploadAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case SCENARIO:
                asuc = AuditSetUpCommandFactory.getInstance().getScenarioAuditSetUpCommand(contract, scenarioId, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case PAGE:
            case GROUPOFPAGES:
            default:
                asuc = AuditSetUpCommandFactory.getInstance().getPageAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
        }
        model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, asuc);
        model.addAttribute(TgolKeyStore.DEFAULT_PARAM_SET_KEY, asuc.isDefaultParamSet());
        this.prepareFormModel(model, contract, refAndLevelFormFieldList, optionFormFieldMap);
        return viewName;
    } else {
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
}
Also used : AuditSetUpCommand(org.asqatasun.webapp.command.AuditSetUpCommand) Contract(org.asqatasun.webapp.entity.contract.Contract) SelectFormField(org.asqatasun.webapp.form.SelectFormField) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 10 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException in project Asqatasun by Asqatasun.

the class AuditSynthesisController method displayAuditTestSynthesisFromContract.

/**
     *
     * @param auditId
     * @param request
     * @param response
     * @param model
     * @return
     */
@RequestMapping(value = TgolKeyStore.FAILED_TEST_LIST_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayAuditTestSynthesisFromContract(@RequestParam(TgolKeyStore.AUDIT_ID_KEY) String auditId, HttpServletRequest request, HttpServletResponse response, Model model) {
    Long aId;
    try {
        aId = Long.valueOf(auditId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditDataService().read(aId);
    if (isUserAllowedToDisplayResult(audit)) {
        if (isAuthorizedScopeForSynthesis(audit)) {
            Contract contract = retrieveContractFromAudit(audit);
            model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
            model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
            model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, auditId);
            model.addAttribute(TgolKeyStore.REFERENTIAL_CD_KEY, getParameterDataService().getReferentialKeyFromAudit(audit));
            model.addAttribute(TgolKeyStore.WEBRESOURCE_ID_KEY, audit.getSubject().getId());
            Site site = (Site) audit.getSubject();
            //TODO cas manual
            addAuditStatisticsToModel(site, model, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE);
            model.addAttribute(TgolKeyStore.FAILED_TEST_INFO_BY_OCCURRENCE_SET_KEY, getStatisticsDataService().getFailedTestByOccurrence(site, audit, -1));
            model.addAttribute(TgolKeyStore.HAS_SITE_SCOPE_TEST_KEY, processResultDataService.hasAuditSiteScopeResult(site, getSiteScope()));
            model.addAttribute(TgolKeyStore.STATUS_KEY, computeAuditStatus(site.getAudit()));
            return TgolKeyStore.FAILED_TEST_LIST_VIEW_NAME;
        } else {
            throw new ForbiddenPageException();
        }
    } else {
        throw new ForbiddenUserException();
    }
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) Contract(org.asqatasun.webapp.entity.contract.Contract) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)35 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 Secured (org.springframework.security.access.annotation.Secured)13 Contract (org.asqatasun.webapp.entity.contract.Contract)12 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)11 Audit (org.asqatasun.entity.audit.Audit)10 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)8 WebResource (org.asqatasun.entity.subject.WebResource)6 User (org.asqatasun.webapp.entity.user.User)5 Site (org.asqatasun.entity.subject.Site)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Page (org.asqatasun.entity.subject.Page)2 Act (org.asqatasun.webapp.entity.contract.Act)2 Scenario (org.asqatasun.webapp.entity.scenario.Scenario)2 Model (org.springframework.ui.Model)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1