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);
}
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);
}
}
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;
}
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;
}
}
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();
}
}
Aggregations