use of org.asqatasun.webapp.exception.ForbiddenScopeException in project Asqatasun by Asqatasun.
the class PageListController method pageLinkDispatcher.
/**
* This method dispatches the result depending on the parameters passed to
* the request. Only multi-pages audit are considered here.
*
* @param request
* @param webResource
* @param model
* @return
* @throws Exception
*/
private String pageLinkDispatcher(HttpServletRequest request, Audit audit, Model model) throws Exception {
if (audit.getSubject() instanceof Page) {
throw new ForbiddenPageException();
}
String status = ServletRequestUtils.getStringParameter(request, TgolKeyStore.STATUS_KEY);
HttpStatusCodeFamily httpStatusCode = getHttpStatusCodeFamily(status);
// the repartion of the pages regarding the httpStatusCode
if (httpStatusCode == null) {
if (!isAuthorizedScopeForPageList(audit)) {
throw new ForbiddenScopeException();
}
try {
Contract currentContract = retrieveContractFromAudit(audit);
model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, currentContract.getLabel());
model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, currentContract.getId());
String testLabel = ServletRequestUtils.getStringParameter(request, TgolKeyStore.TEST_KEY);
if (StringUtils.isNotBlank(testLabel)) {
model.addAttribute(TgolKeyStore.TEST_CODE_KEY, getTestDataService().getTestFromAuditAndLabel(audit, testLabel));
}
return this.preparePageListData(audit, model);
} catch (ServletRequestBindingException e) {
return TgolKeyStore.OUPS_VIEW_REDIRECT_NAME;
}
} else {
boolean isAuthorizedScopeForPageList = isAuthorizedScopeForPageList(audit);
Contract currentContract = retrieveContractFromAudit(audit);
model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, currentContract.getLabel());
model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, currentContract.getId());
// used in the jsp
if (!isAuthorizedScopeForPageList) {
model.addAttribute(TgolKeyStore.AUDIT_NUMBER_KEY, true);
}
String testLabel = ServletRequestUtils.getStringParameter(request, TgolKeyStore.TEST_KEY);
if (StringUtils.isNotBlank(testLabel)) {
model.addAttribute(TgolKeyStore.TEST_CODE_KEY, getTestDataService().getTestFromAuditAndLabel(audit, testLabel));
}
return this.preparePageListStatsByHttpStatusCode(audit, model, httpStatusCode, request, false);
}
}
use of org.asqatasun.webapp.exception.ForbiddenScopeException in project Asqatasun by Asqatasun.
the class PageListControllerTest method testDisplayPageListWithUnauthorizedActScope.
/**
* The PageList is displayed when the webResource is a Site instance.
* A mechanism is implemented into that controller that enables to display
* the page only when the scope of the act related with the webResource
* belongs to a list of authorized scope. In this case the list only contains
* DOMAIN as authorized scope, whereas the scope of the audit is
* GROUP_OF_PAGE, so the page cannot be displayed.
*
* @throws Exception
*/
public void testDisplayPageListWithUnauthorizedActScope() throws Exception {
System.out.println("testDisplayPageListWithUnauthorizedActScope");
setUpMockAuditDataService(UNAUTHORIZED_SCOPE_AUDIT_ID);
setUpMockUserDataService();
setUpActDataService(false);
setUpMockAuthenticationContext();
HttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(TgolKeyStore.AUDIT_ID_KEY, String.valueOf(UNAUTHORIZED_SCOPE_AUDIT_ID));
List<String> authorizedScopeForPageList = new ArrayList();
authorizedScopeForPageList.add("DOMAIN");
instance.setAuthorizedScopeForPageList(authorizedScopeForPageList);
try {
instance.displayPageList(request, response, new ExtendedModelMap());
assertTrue(false);
} catch (ForbiddenScopeException fbe) {
assertTrue(true);
}
}
Aggregations