コード例 #1
0
  public void testServiceFailure() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();

    Role role = new Role();
    role.setName("testRole");
    User user = new User();
    user.addAutority(role);
    reqCtx.getRequest().getSession().setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, user);

    Page page = new Page();
    page.setCode("login");
    page.setGroup("free");
    page.setModel(new PageModel());

    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, page);

    Lang lang = new Lang();
    lang.setCode("it");
    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG, lang);

    MockHttpServletRequest request = (MockHttpServletRequest) reqCtx.getRequest();
    request.setRemoteAddr("255.255.255.255");
    request.addHeader("Referer", "homeTest");
    request.addHeader("User-Agent", "Mio Test Browser");
    request.addHeader("accept-language", "sardo");

    int status = _statMonitor.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(status, ControllerManager.CONTINUE);
    this.deleteStatsRecord();
  }
 @Override
 public int service(RequestContext reqCtx, int status) {
   if (_log.isLoggable(Level.FINEST)) {
     _log.finest("Invoked " + this.getClass().getName());
   }
   int retStatus = ControllerManager.INVALID_STATUS;
   if (status == ControllerManager.ERROR) {
     return status;
   }
   try {
     String isActive =
         this.getConfigManager()
             .getParam(CasClientPluginSystemCostants.JPCASCLIENT_EXTENDED_ISACTIVE);
     if (!isActive.equals("true")) {
       // if cas client is disactivate normal Authorization on request
       return super.service(reqCtx, retStatus);
     } else {
       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);
       boolean authorized = this.getAuthManager().isAuth(currentUser, currentPage);
       if (authorized) {
         retStatus = ControllerManager.CONTINUE;
       } else if (SystemConstants.GUEST_USER_NAME.equals(currentUser.getUsername())) {
         _log.info("CAS - user not authorized and guest");
         CasClientUtils casClientUtils = new CasClientUtils();
         String loginBaseUrl =
             this.getConfigManager().getParam(CasClientPluginSystemCostants.JPCASCLIENT_LOGIN_URL);
         StringBuffer loginUrl = new StringBuffer(loginBaseUrl);
         loginUrl.append("?service=");
         PageURL pageUrl = this.getUrlManager().createURL(reqCtx);
         String serviceUrl = casClientUtils.getURLStringWithoutTicketParam(pageUrl, reqCtx);
         loginUrl.append(serviceUrl);
         reqCtx.addExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL, loginUrl.toString());
         retStatus = ControllerManager.REDIRECT;
       } else {
         _log.info("CAS - user authenticated but not authorized");
         Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
         String notAuthPageCode =
             this.getConfigManager()
                 .getParam(CasClientPluginSystemCostants.JPCASCLIENT_NO_AUTH_PAGE);
         IPage page = this.getPageManager().getPage(notAuthPageCode);
         String url =
             this.getUrlManager().createUrl(page, currentLang, new HashMap<String, String>());
         reqCtx.addExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL, url);
         retStatus = ControllerManager.REDIRECT;
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "service", "Error in processing the request");
     retStatus = ControllerManager.ERROR;
   }
   return retStatus;
 }
コード例 #3
0
 /**
  * Imposta i parametri di una redirezione.
  *
  * @param redirDestPage Il codice della pagina su cui si vuole redirezionare.
  * @param reqCtx Il contesto di richiesta.
  * @return L'indicativo del tipo di redirezione in uscita del controlService. Può essere una delle
  *     costanti definite in ControllerManager.
  */
 protected int redirect(String redirDestPage, RequestContext reqCtx) {
   int retStatus;
   try {
     String redirPar = this.getParameter(RequestContext.PAR_REDIRECT_FLAG, reqCtx);
     if (redirPar == null || "".equals(redirPar)) {
       PageURL url = this.getUrlManager().createURL(reqCtx);
       url.setPageCode(redirDestPage);
       url.addParam(RequestContext.PAR_REDIRECT_FLAG, "1");
       String redirUrl = url.getURL();
       if (_log.isLoggable(Level.FINEST)) {
         _log.finest("Redirecting to " + redirUrl);
       }
       reqCtx.clearError();
       reqCtx.addExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL, redirUrl);
       retStatus = ControllerManager.REDIRECT;
     } else {
       reqCtx.setHTTPError(HttpServletResponse.SC_BAD_REQUEST);
       retStatus = ControllerManager.ERROR;
     }
   } catch (Throwable t) {
     retStatus = ControllerManager.SYS_ERROR;
     reqCtx.setHTTPError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
     ApsSystemUtils.logThrowable(
         t, this, "redirect", "Error on creation redirect to page " + redirDestPage);
   }
   return retStatus;
 }
コード例 #4
0
 public void testServiceFailure_2() throws Throwable {
   RequestContext reqCtx = this.getRequestContext();
   reqCtx.getRequest().getSession().removeAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
   IPage root = this._pageManager.getRoot();
   reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, root);
   int status = _authorizator.service(reqCtx, ControllerManager.CONTINUE);
   assertEquals(status, ControllerManager.SYS_ERROR);
 }
コード例 #5
0
 public void testServiceFailure_1() throws Throwable {
   RequestContext reqCtx = this.getRequestContext();
   this.setUserOnSession(SystemConstants.GUEST_USER_NAME);
   IPage requiredPage = this._pageManager.getPage("customers_page");
   reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, requiredPage);
   int status = _authorizator.service(reqCtx, ControllerManager.CONTINUE);
   assertEquals(status, ControllerManager.REDIRECT);
   String redirectUrl = (String) reqCtx.getExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL);
   assertEquals("/japs/it/login.page?redirectflag=1", redirectUrl);
 }
コード例 #6
0
 public void testService_2() throws Throwable {
   RequestContext reqCtx = this.getRequestContext();
   this.setUserOnSession("admin");
   IPage root = this._pageManager.getRoot();
   reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, root);
   int status = this._authorizator.service(reqCtx, ControllerManager.CONTINUE);
   assertEquals(status, ControllerManager.CONTINUE);
   String redirectUrl = (String) reqCtx.getExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL);
   assertNull(redirectUrl);
 }