private Map<String, Object> getASOMap() {
    Map<String, Object> result = (Map<String, Object>) request.getAttribute(ASO_MAP_ATTRIBUTE);

    if (result == null) {
      result = CollectionFactory.newMap();
      request.setAttribute(ASO_MAP_ATTRIBUTE, result);
    }

    return result;
  }
  /**
   * Initialize the SSO Service, prepare a login if required
   *
   * @param session The server session data
   * @throws Exception if any errors occur
   */
  @Override
  public String ssoInit(JsonSessionState session) throws Exception {
    // Keep track of the user switching portals for
    // link building in other methods
    String portalId = (String) session.get("portalId", defaultPortal);
    ssoLoginUrl = serverUrlBase + portalId + SSO_LOGIN_PAGE;

    // Find out what page we are on
    String path = request.getAttribute("RequestURI").toString();
    String currentAddress = serverUrlBase + path;

    // Store the portal URL, might be required by implementers to build
    //  an interface (images etc).
    session.set("ssoPortalUrl", serverUrlBase + portalId);

    // Makes sure all SSO plugins get initialised
    for (String ssoId : sso.keySet()) {
      sso.get(ssoId).ssoInit(session, rg.getHTTPServletRequest());
    }

    // Are we logging in right now?
    String ssoId = request.getParameter("ssoId");

    // If this isn't the login page...
    if (!currentAddress.contains(SSO_LOGIN_PAGE)) {
      // Store the current address for use later
      session.set("returnAddress", currentAddress);
      // We might still be logging in from a deep link
      if (ssoId == null) {
        // No we're not, finished now
        return null;
      } else {
        // Yes it's a deep link, store any extra query params
        // since they probably won't survive the round-trip
        // through SSO.
        for (String param : request.getParameterNames()) {
          if (!param.equals("ssoId")) {
            // Store all the other parameters
            session.set(SSO_STORAGE_PREFIX + param, request.getParameter(param));
          }
        }
      }
    }

    // Get the last address to return the user to
    String returnAddress = (String) session.get("returnAddress");
    if (returnAddress == null) {
      // Or use the home page
      returnAddress = serverUrlBase + portalId + "/home";
    }

    // Which SSO provider did the user request?
    if (ssoId == null) {
      log.error("==== SSO: SSO ID not found!");
      return null;
    }
    if (!sso.containsKey(ssoId)) {
      log.error("==== SSO: SSO ID invalid: '{}'!", ssoId);
      return null;
    }

    // The main event... finally
    sso.get(ssoId).ssoPrepareLogin(session, returnAddress, serverUrlBase);
    return ssoId;
  }
Ejemplo n.º 3
0
  void beginRender(MarkupWriter writer) {

    String clientId = getClientId();

    writer.element("table", "id", clientId);
    writer.end();
    writer.element("div", "id", "pager" + clientId);
    writer.end();

    JSONObject setup = new JSONObject();
    setup.put("field", clientId);

    /*url:'server.php?q=2',
    datatype: "json",*/

    JSONObject jqgridParams = new JSONObject();
    jqgridParams.put("url", resources.createEventLink("data").toAbsoluteURI());
    jqgridParams.put("datatype", "json");

    // colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    JSONArray colNames = new JSONArray();
    List<String> names = getDataModel().getPropertyNames();
    for (String name : names) colNames.put(name);
    jqgridParams.put("colNames", colNames);

    /*colModel:[
    	{name:'id',index:'id', width:55},
    	{name:'invdate',index:'invdate', width:90},
    	{name:'name',index:'name', width:100},
    	{name:'amount',index:'amount', width:80, align:"right"},
    	{name:'tax',index:'tax', width:80, align:"right"},
    	{name:'total',index:'total', width:80,align:"right"},
    	{name:'note',index:'note', width:150, sortable:false}
    ],*/

    JSONArray colModel = new JSONArray();
    for (String name : names) {
      JSONObject model = new JSONObject();
      model.put("name", name);

      model.put("index", name);
      model.put("width", 100);
      colModel.put(model);
      // is this column sorted?
      if (sortAscending != null) {
        ColumnSort colSort = getSortModel().getColumnSort(name);
        if (colSort != ColumnSort.UNSORTED) {
          // sortname: 'id',
          jqgridParams.put("sortname", name);
          // sortorder: "desc",
          if (colSort == ColumnSort.ASCENDING) jqgridParams.put("sortorder", "asc");
          else jqgridParams.put("sortorder", "dsc");
        }
      }
    }
    jqgridParams.put("colModel", colModel);

    // rowNum:10,
    jqgridParams.put("rowNum", rowsPerPage);

    // rowList:[10,20,30],

    // pager: '#pager5',
    jqgridParams.put("pager", "#pager" + clientId);

    // viewrecords: true,

    // caption:"Simple data manipulation",
    jqgridParams.put("caption", "Simple data manipulation");

    // editurl:"someurl.php"
    jqgridParams.put("editurl", resources.createEventLink("edit").toAbsoluteURI());

    jqgridParams
        .put("sortable", true)
        .put("viewrecords", true)
        .put("rowList", new JSONLiteral("[5,10,15]"));

    JQueryUtils.merge(jqgridParams, additionalParams);

    setup.put("params", jqgridParams);

    if (request.getAttribute(LOCALIZATION_CONFIGURED_FLAG) == null) {
      JSONObject spec = new JSONObject();
      request.setAttribute(LOCALIZATION_CONFIGURED_FLAG, true);
    }

    support.addInitializerCall("jqGrid", setup);
  }