Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

PCD Filter - get IP Address of client

Hi there,

we are implementing a PCD Filter like described <a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/ep/code-samples/Filtering%20Role%20and%20Workset%20Content.htm">here</a>

What we would like to do is make an iView available depending on the IP Address of the user.

Following code is used for the filter in the example of the link above. How can we retrieve the user's IP address? Can the request be accessed?

package com.acme.portal.demo;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.spi.ObjectFactory;

import com.sap.portal.directory.Constants;
import com.sap.security.api.IUser;
import com.sapportals.portal.pcd.gl.IPcdContext;


/**
 * Filter factory that filters returns a filter string filtering for the
 * attribute "com.sap.portal.demo.Country"
 */
public class CountryFilterFactory implements ObjectFactory
{

	/**
	 * @see javax.naming.spi.ObjectFactory#getObjectInstance(Object, Name, Context, Hashtable)
	 */
	public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable env)
	throws Exception
	{
        // do not filter by default
        String filterExpression = "";  
        
        // only filter for the navigation aspect
        if (Constants.ASPECT_NAVIGATION.equals(env.get(Constants.REQUESTED_ASPECT)))
        {         
            IUser user = (IUser) env.get(IPcdContext.SECURITY_PRINCIPAL);
            if (user != null)
            {
                String country = user.getCountry();    
                                   
                if ((country != null) && (!country.equals("")))
                {        
                    filterExpression = "(" + CountryFilterService.COUNTRY_ATTRIBUTE_KEY + "=" + country + ")";                   		
                }
            }
        }
        return filterExpression;
	}

}

Many thanks,

Kevin

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question