Skip to Content
avatar image
Former Member

Retrieving the logged on user and layout set from a filter

Hello everyone,

I'm trying to retrieve the currently logged on user from a namespace filter, is there any way to do that? I tried some things I read in documents and forums without success. Here's part of my code :

public class TestFilter3 extends AbstractPortalComponent implements INamespaceFilter {

private final INamespaceFilter predecessorFilter;

private IUser user;

TestFilter3(INamespaceFilter predecessorFilter) {

this.predecessorFilter = predecessorFilter;

}

public void doContent(IPortalComponentRequest request,IPortalComponentResponse response) {

System.out.println("doContent");

//user = request.getUser();

}

...

The method doContent is not called at all, as my message doesn't print in the console. I also tried this :

IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();

That doesn't work, but I don't think I'm using it correctly.

Update : It looks like I can get the user by using the getContext() function for my resources, but the getUser() function returns an object of type "com.sapportals.portal.security.usermanagement.IUser". This class doesn't seem to exist anymore, I think it was replaced by the class "com.sap.security.api.IUser".

Also, is there a way for my program to know by which layout set or collection renderer a repository is accessed? What I'm trying to do is filter content differently depending on which layout set is used.

Thanks and best regards.

Message was edited by: Olivier Tremblay-Ross

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    Jun 07, 2004 at 12:15 PM

    Hi Oliver,

    it seems that there is a logical mistake in this implementation. An implementation of a NamespaceFilter is called by the repository framework, while an extension of an AbstractPortalComponent is called by teh PortalRuntime. Both parts a unlinked from each other and do not exchange data. This means your request object coming from the doContent() method of the AbstractPortalComponent is never filled or even initialized. Therefor your implementation won't work.

    But to provide a solution, just try this 😊)

    Get the resource context from the currently processed resource in the namespace filter and grap the context object out of it:

    IResourceContext ctx = this.predecessorFilter.getCollection().getContext();

    com.sapportals.portal.security.usermanagement.IUser user = ctx.getUser();

    This com.sapportals.portal.security.usermanagement.IUser class is deprecated but mandatory for usage if you handle CM content objects (resources or collections).

    Concerning the layout set, you cannot access this parameter out of a filter implementation. I recommend to do a collection renderer implementation for this purpose, better extend the abstract class LightCollectionRenderer:

    See http://media.sdn.sap.com/html/submitted_docs/60_sp2_javadocs/km/com/sapportals/wcm/rendering/collection/LightCollectionRenderer.html

    Configuration and runtime will be the FlexibleUI environment.

    Further information: https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/documents/a1-8-4/sap ep 6.0 flexible ui in knowledge management.ppt

    Best regards,

    Thilo Brandt

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Thilo,

      Thank you very much for your help! Everything works now. Also, I've found a way to know which Collection Renderer is used to access the resource, which is close enough to what I needed. Here's the code :

      int n = 0;

      while(!ctx.getValues().values().toArray()[n].getClass().getName().endsWith("CustomizingController")) {

      n++;

      }

      ICustomizingController ctrlCustom = (ICustomizingController) ctx.getValues().values().toArray()[n];

      String collRenderer = ctrlCustom.parameters().getParameter(IFlavorConst.FLAVOR_NULL,IParameterNameConst.COLLECTION_RENDERER_SETTINGS);

      By modifying the IParameterNameConst, it's possible to know the resource renderer, the layout controller, and other properties.

      Thanks again and best regards.

      Message was edited by: Olivier Tremblay-Ross