access user attributes in styles_rules - Websphere

This is a discussion on access user attributes in styles_rules - Websphere ; Hi, Is it possible to access user attributes from styles_rules.jspf? I've tried the following without success: <portal-logic:if loggedIn="yes"> <c:set var="userId" scope="request"><portal-fmt:user attribute="uid"/></c:set> <c-rt:if test="${userId=='wpsadmin'}"> ... </c-rt:if> </portal-logic:if> Thanks in advance...

+ Reply to Thread
Results 1 to 3 of 3

Thread: access user attributes in styles_rules

  1. access user attributes in styles_rules

    Hi,



    Is it possible to access user attributes from styles_rules.jspf?



    I've tried the following without success:



    <portal-logic:if loggedIn="yes">

    <c:set var="userId" scope="request"><portal-fmt:user attribute="uid"/></c:set>

    <c-rt:if test="${userId=='wpsadmin'}">

    ...

    </c-rt:if>

    </portal-logic:if>



    Thanks in advance

  2. Re: access user attributes in styles_rules

    From my understanding these requests are not made in the context of the logged in user. Being that the results are cached in a servlet, and userid is not one of the keys that is used,



    A url for the style sheet looks like this



    /wps/CacheProxyServlet/colorPalette/default/browserVendor/Mozilla+Foundation/browserName/Firefox/browserVersion/2.0/locale/en/forwardurl/wps/themes/html/IBM/./ styles.jsp



    Thus it is an unauthenticated request.



    IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0

    IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0



    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

  3. Re: access user attributes in styles_rules

    You have to pass your information on the URL to the stylesheet. (You
    would want to do that for proper cache partitioning anyway.)

    Unfortunately, the cache proxy tag doesn't take parameters. So what you
    have to do is get the url output of that tag in a variable and split the
    string manually on some known key like /forwardurl/ and insert new
    key/value pairs in the URL. The following code would go in head.jspf:



    forwardurl="<%=stylesJspUrl.toString()%>" />
    <%
    // The tag does not support adding
    // new parameters to the URL. So split the cache proxy url at
    // the /forwardurl/ parameter to add more parameters.
    // NOTE: It normally is not safe to assume the format of
    // URLs returned by portal.
    String cssUrl = (String)request.getAttribute("cssUrl");

    int cssUrlForwardUrlIndex = cssUrl.indexOf("/forwardurl/");
    request.setAttribute("cssUrl_part1",
    cssUrl.substring(0, cssUrlForwardUrlIndex));
    request.setAttribute("cssUrl_part2",
    cssUrl.substring(cssUrlForwardUrlIndex));
    %>
    %>${cssUrl_part1}/mykey1/<%=myvalue1%>/mykey2/<%=myvalue2%>${cssUrl_part2}
    rel="styleSheet" type="text/css" />


    Also, unfortunately, the servlet this URL calls does not know about your
    parameters and won't pull them out of the URL and put them in the
    request as attributes for you. So, you have to do that manually. The
    following code would go in styles_rules.jspf:

    // Parse parameters out of PathInfo... The CacheProxyServlet does
    // this for attributes it knows about. So, since the servlet does
    // not parse all of the parameters we need into the request,
    // we have to re-parse the information here. This means that some
    // parameters are parsed twice, but that is the only way to get
    // all attributes.
    //
    // Since Styles.jsp is called as a result of a
    // RequestDispatcher.forward(),
    // the request.getPathInfo() method returns null and not the pathInfo
    // passed to the CacheProxyServlet. We have to get that information
    // out of a special request atribute named
    // javax.servlet.forward.path_info.
    boolean foundForwardURL = false;
    String pathInfo =
    (String)request.getAttribute("javax.servlet.forward.path_info");
    if ( null != pathInfo )
    {
    java.util.StringTokenizer piTokenizer = new
    java.util.StringTokenizer( pathInfo, "/" );
    while ( piTokenizer.hasMoreTokens() && !foundForwardURL ) {
    String param = null;
    String value = null;

    param = piTokenizer.nextToken();
    if ( piTokenizer.hasMoreTokens() ) {
    value = piTokenizer.nextToken();
    } else {
    // If we have a parameter without a value, the URL
    // is malformed
    throw new java.net.MalformedURLException( "parameter "
    + param + " did not have a value");
    }

    // Check for a forwardurl parameter. If this is one, the
    // remainder of the path info is a URL so we need to stop
    // tokenizing. Since the CacheProxyServlet already
    // parsed this value and put it in the request, we can
    // ignore the remainder of the path info.
    if ( "forwardurl".equals( param ) ) {
    foundForwardURL = true;
    } else {
    request.setAttribute( param, value );
    }
    }
    }



+ Reply to Thread