cancel
Showing results for 
Search instead for 
Did you mean: 

how to get current logon user's role within portal

Former Member
0 Kudos

hi,

I can get logon user's role by coding directly against IPortalComponentRequest request, but when I move all the codes into our own par file, I don't have reference to request anymore, we do have access IResourceContext, which can be casted to IUSER, but it does not work. I can not get user's role from it. any idea how to get user's role NOT from portal component doContent? Thanks!

T.J.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Why don't you do the following.

IUser user = ctxt.getUser();
Iterator role = user.getRoles(true);
while ( role.hasNext()) {
  String rolestr = (String) role.next();
  IRole r = UMFactory.getRoleFactory().getRole(rolestr);
  response.write(r.getDisplayName());
}

Former Member
0 Kudos

Prakash,

Thanks for the response, what is CTXT? how to instantiate this object?

T.J.

Former Member
0 Kudos

Hi T.J,

What exactly are your writing? A JSPDynpage, Dynpage or a KM component. Can you be specifc about what type of portal component are you writing? If you let me know then i can suggest how to accomplish what you have asked.

Prakash.

Former Member
0 Kudos

Prakash,

I am writting a KM component, when I retrieve the user directly from request, it works, but after I move the codes into my KM component and tried to use IResourceContext, I got some problem to mess two IUSER type, I tried to conver it, does not work. here is the code:

###################################################

import java.util.Iterator;

import com.sap.security.api.IRole;

import com.sap.security.api.IUser;

import com.sap.security.api.UMException;

import com.sap.security.api.UMFactory;

import com.sapportals.wcm.repository.*;

public class RoleRetrieve

{

static public void main(String[] args){

}

public String getRoleContent(IResourceContext context)

{

boolean isManager= false;

boolean isHR = false;

try {

IUser user = (IUser) context.getUser();

IRole role =null;

Iterator userRoles = user.getRoles(true);

while (userRoles.hasNext()) {

String userstr = (String)userRoles.next();

try {

role = IUMFactory.getRoleFactory().getRole(userstr);

if (role.getDisplayName().equals("role_na_manager"))

isManager =true;

else if (role.getDisplayName().equals("role_na_hrAdmin"))

isHR =true;

} catch (UMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

break;

}

}

} catch(Exception e){

e.printStackTrace();

}

Former Member
0 Kudos

can you show me how you are implementing the KM component.

Former Member
0 Kudos

Prakash,

actually, I created a KM global service to integrate Stellent CM verity search engine into KM. this codes is part of that service to retrieve logon user role, then I can match it with Stellent user credential. in this global server, I can get reference to IResourceContext. here is the error message I got from that codes.

#1.5#0008028CA50F007B00000000000011C00003FBC7AAC3C198#1121259912157#System.err#sap.com/irj#System.err#portal002#17011####bf27a8d0f39e11d9aa1a0008028ca50f#Thread[Thread-362,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error##Plain###java.lang.ClassCastException#

#1.5#0008028CA50F007B00000001000011C00003FBC7AAC3C5AA#1121259912157#System.err#sap.com/irj#System.err#portal002#17011####bf27a8d0f39e11d9aa1a0008028ca50f#Thread[Thread-362,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error##Plain### at com.cokecce.search.RoleRetrieve.getRoleContent(RoleRetrieve.java:24)#

#1.5#0008028CA50F007B00000002000011C00003FBC7AAC3C6FA#1121259912157#System.err#sap.com/irj#System.err#portal002#17011####bf27a8d0f39e11d9aa1a0008028ca50f#Thread[Thread-362,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error##Plain### at com.cokecce.search.StellentSearch.sendRequest(StellentSearch.java:98)#

#1.5#0008028CA50F007B00000003000011C00003FBC7AAC3C81F#1121259912157#System.err#sap.com/irj#System.err#portal002#17011####bf27a8d0f39e11d9aa1a0008028ca50f#Thread[Thread-362,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error##Plain### at com.cokecce.search.StellentSearch.doSearch(StellentSearch.java:48)#

#1.5#0008028CA50F007B00000004000011C00003FBC7AAC3C949#1121259912157#System.err#sap.com/irj#System.err#portal002#17011####bf27a8d0f39e11d9aa1a0008028ca50f#Thread[Thread-362,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error##Plain### at com.cokecce.search.StellentSearchIndexCollection.executeQueryWithSession(StellentSearchIndexCollection.java:216)#

#1.5#0008028CA50F007B00000005000011C00003FBC7AAC3CA6A#1121259912157#System.err#sap.com/irj#System.err#portal002#17011####bf27a8d0f39e11d9aa1a0008028ca50f#Thread[Thread-362,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error##Plain### at com.sapportals.wcm.service.indexmanagement.retrieval.search.FederatedSearch$ParallelSearcher

thanks!

T.J.

Former Member
0 Kudos

Hi T.J,

I understand now. You don't need the cast IUser from IResourceContext. Change the following line

IUser user = (IUser) context.getUser();

to

IUser user = context.getUser();

Also your user import is incorrect. KM uses it's own user.

import com.sapportals.portal.security.usermanagement.IUser;

Message was edited by: Prakash Singh

Former Member
0 Kudos

You could also do this. The reason why you have to do it is because KM returns a different IUser.

com.sapportals.portal.security.usermanagement.IUser  kmuser = context.getUser();
com.sap.security.api.IUser user = UMFactory.getUserFactory().getUserByLogonID(user.getDisplayId());

Former Member
0 Kudos

I tried that, but complier would not compile by giving the following error message;

****

cannot convert from com.sapportals.portal.security.usermanagement.IUser to com.sap.security.api.IUser ****

I think somehow system pass IUser from usermanagement into IResourcecontext instead of the IUser from security.api.

T.J.

Former Member
0 Kudos

T.J.

do the following.

com.sapportals.portal.security.usermanagement.IUser  kmuser = context.getUser();
com.sap.security.api.IUser user = UMFactory.getUserFactory().getUserByLogonID(user.getDisplayId());

This will definitely solve your problem. Don't forget to reward points if it works out. thank you.

Message was edited by: Prakash Singh

Answers (0)