Search in sources :

Example 1 with AuditParameterMissingException

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

the class PageListController method displayPageList.

/**
     *
     * @param request
     * @param response
     * @param model
     * @return
     * @throws java.lang.Exception
     */
@RequestMapping(value = TgolKeyStore.PAGE_LIST_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayPageList(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
    String auditId = ServletRequestUtils.getStringParameter(request, TgolKeyStore.AUDIT_ID_KEY);
    if (auditId == null) {
        throw new AuditParameterMissingException();
    }
    Audit audit;
    try {
        audit = getAuditDataService().read(Long.valueOf(auditId));
    } catch (NumberFormatException e) {
        throw new ForbiddenPageException(e);
    }
    if (isUserAllowedToDisplayResult(audit)) {
        return pageLinkDispatcher(request, audit, model);
    } else {
        // method returns true or throws an exception
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
}
Also used : Audit(org.asqatasun.entity.audit.Audit) AuditParameterMissingException(org.asqatasun.webapp.exception.AuditParameterMissingException) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AuditParameterMissingException

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

the class PageListControllerTest method testDisplayPageListWithoutAuditId.

/**
     * The servlet is supposed to embed the audit id the page is 
     * about. If not, the ForbiddenPageException is caught.
     * @throws Exception 
     */
public void testDisplayPageListWithoutAuditId() throws Exception {
    System.out.println("testDisplayPageListWithoutAuditId");
    // about. If not, the access denied page is returned
    try {
        instance.displayPageList(new MockHttpServletRequest(), new MockHttpServletResponse(), new ExtendedModelMap());
        assertTrue(false);
    } catch (AuditParameterMissingException fbe) {
        assertTrue(true);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuditParameterMissingException(org.asqatasun.webapp.exception.AuditParameterMissingException)

Aggregations

AuditParameterMissingException (org.asqatasun.webapp.exception.AuditParameterMissingException)2 Audit (org.asqatasun.entity.audit.Audit)1 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 Secured (org.springframework.security.access.annotation.Secured)1 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1