|
Home > Archive > WebSphere Portal Server > September 2006 > How to create/modify a user outside of a portlet ? (WPS 5.1)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to create/modify a user outside of a portlet ? (WPS 5.1)
|
|
|
| Hi all.
I want to use the PUMA API (WPS 5.1) to create/modify users from a stateless session bean, but the PUMA SPI javadoc indicates that the getController() method of PumaHome needs to be passed a ServletRequest. Apparently this API is meant to be used only fro
m within a portlet or servlet.
Can anyone help ?
| |
|
|
|
|
|
| Yes and no.
We had to use a workaround, by calling the getController from a servlet instead of from a POJO or Session bean like we wanted.
This means that we send our user data as POST HTTP request to the servlet, and call PUMA from the doPost.
It's not very satisfying as far as architecture goes, but it seems to work.
IBM support tells that they fixed that issue in Portal 6.0, where they added a getController method that doesn't require a ServletRequest as a parameter.
| |
|
|
|
| The easiest way is invoquing the MemberService EJB. You can do this like that:
public void createUserInGroup(String userName, Map attributes)
throws IOException, WMMException {
Member user = MemberFactory.getInstance(Member.MEMBER_TYPE_PERSON);
String memberDN = "uid=" + userName + "," + BASE_DN;
String memberUniqueId = userName;
MemberIdentifier mi = MemberIdentifierFactory.getInstance(memberDN,
memberUniqueId);
user.setMemberIdentifier(mi);
String pMemberDN = BASE_DN;
String pMemberUniqueId = "";
MemberIdentifier pmi = MemberIdentifierFactory.getInstance(pMemberDN,
pMemberUniqueId);
user.setParentMemberIdentifier(pmi);
Attribute uid = AttributeFactory.getInstance("uid", userName);
user.addAttribute(uid);
Set set = attributes.entrySet();
for (Iterator iter = set.iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
Attribute att = AttributeFactory.getInstance(entry.getKey()
.toString(), entry.getValue());
user.addAttribute(att);
}
mm.createMember(user);
}
where mm is contains a reference of an instance of com.ibm.websphere.wmm.objects.MemberService
which can be obtained as
String jndiPath = "ejb/MemberServiceHome";
String contextFactory = "com.ibm.websphere.naming.WsnInitialContextFactory";;
String host = "host.name";
String port = "2811";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
env.put(Context.PROVIDER_URL, "iiop://" + host + ":" + port);
Context initial = new InitialContext(env);
Object objref = initial.lookup(jndiPath);
MemberServiceHome home = (MemberServiceHome) PortableRemoteObject
.narrow(objref, MemberServiceHome.class);
mm = home.create();
You have to include in the classpath
<portal>/AppServer/lib/namingclient.jar
<portal>/AppServer/lib/naming.jar
<portal>/AppServer/lib/wmm.ejb.jar
<portal>/AppServer/lib/wmm.jar
<portal>/AppServer/lib/j2ee.jar
| |
|
| I'm sure what you suggests works, but my main goal is to use only PUBLIC APIs, not undocumented inner APIs that customers are not supposed to call.
We've been using the UserManager object for years to manipulate WMM, but our customer wants us to be as standard as possible.
| |
|
| Thanks. and could you specify what parameters required for user creation?
| |
|
| Hi everyone,
I am currently using Puma in WebSphere 5.1 and I try do a create user with the
following code:
"
Name myjndiname = new CompositeName(PumaHome.JNDI_NAME);
PumaHome myHome = (PumaHome) ctx.lookup(myjndiname);
pumaController = myHome.getController(servletRequest);
pumaController.createUser("shortname","ou=People,dc=Organisation,dc=com",attributes);
"
where attribute is an HashMap.
This code is called from a servlet deployed on the WebSphere_Portal server instance.
When I am trying to execute the servlet, I am getting the following error:
"java.lang.NullPointerException
at com.ibm.wps.services.puma.PumaServiceWrapperImpl. checkACPermission(PumaServiceWrapperImpl
java:205)"
I don't know what is wrong only with the current error message.
Could some one help me with this problem?
Thanks in advance.
Best Regards, Arnaud.
|
|
|
|
|