on 10-10-2007 2:52 PM
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
Hi Kevin,
I don't have a working example at hand and no time to create one. But: Debug the implementation. There are not many places from where you could, if possible at all, access the request (as far as I remember, it's not accessible, but it was a colleague who implemented it and also this is 1.5 years ago).
When debugging, you can set a break point into getObjectInstance and check out all passed parameters within your debugging NWDS.
Hope it helps
Detlev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Detlev,
thanks for the response. I have used the NW Developer Studio's debugging. Unfortunately request doesn't seem to be available.
I have found some code where they retrieve the IP address based on the CallbackHandler. Don' think that would be an option here, is it? There doesn't seem to be a way of retrieving the handler.
<a href="http://help.sap.com/saphelp_nw04/helpdata/en/d0/5954e9f2aa47e6b91fc3ebf18d5de5/frameset.htm">Advanced Authentication Example</a>
Thanks again for the help,
Kevin
You should be able to use a standard java api for this --- InetAdress.getLocalHost();
One example is here:
import java.net.*;
import java.io.*;
import java.applet.*;
public class GetClientIP extends Applet {
public void init() {
try {
InetAddress thisIp =
InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress());
}
catch(Exception e) {
e.printStackTrace();
}
}
}
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.