cancel
Showing results for 
Search instead for 
Did you mean: 

How do i get current domain user name who had logged on?

Former Member
0 Kudos

Hi experts,

I am developing a portal component using java(jspDynpage). Now i am in need to get the current system user who had logged on. I used System.getProperty("user.name"); But it gives SAP server user account. Please tell me, How do i retrieve current system domain user account.

Thanks and regards,

Krishnan

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

hi ,

To get Current user account logged in

Try:

{

// get the currently logged in user

IWDClientUser wdUser = WDClientUser.getCurrentUser();

//get the com.sap.security.api.Iuser; It is null in case wdUser represents an anonymous user

IUser user = wdUser.getSAPUser();

//check whether the user is anonymous

if (user != null)

{

//access logon ID by iterating through the IUserAccount array

IUserAccount[] acct = user.getUserAccounts();

if(acct[0] != null)

{

String strUserid = acct[0].getLogonUid();

//pass the value obtained from the portal to value attribute

wdContext.currentNode().setAttribute(new String(strUserid));

}

}

}

Regards ,

Venkat

Former Member
0 Kudos

Hi,

This will return the current SAP user. But i need to get current domain user who lodded on.

For example,

My SAP portal user ID is USR01. But my Domain user name is DMNUSR01. I need to get DMNUSR01.

Thanks.

Former Member
0 Kudos

Hi ,

Try This code ,

This is for Current user logged ...........

FriendsterClient fc = new FriendsterClient(<sessionKey>, <apiKey>, <secretKey>);

XPath xpath = XPathFactory.newInstance().newXPath();

try

{

Document doc = fc.getUser(9120940);

String firstName = xpath.evaluate("/user_response/user/first_name", doc);

String lastName = xpath.evaluate("/user_response/user/last_name", doc);

System.out.println(firstName + " " + lastName);

List<Integer> friends = fc.getFriends(9120940);

Document doc = fc.getUsers(friends);

NodeList nl = (NodeList) xpath.evaluate("/user_response/user", doc, XPathConstants.NODESET);

for (int i = 0;i < nl.getLength();i++)

{

System.out.println("profile url [" + i + "]: " + xpath.evaluate("url", nl.item(i)));

}

}

catch (Exception e)

{

System.err.println(e);

}

This is for Current user logged as an administrator .

function IsAdmin: Boolean;

var

hAccessToken: THandle;

ptgGroups: PTokenGroups;

dwInfoBufferSize: DWORD;

psidAdministrators: PSID;

x: Integer;

bSuccess: BOOL;

begin

Result := False;

bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,

hAccessToken);

if not bSuccess then

begin

if GetLastError = ERROR_NO_TOKEN then

bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,

hAccessToken);

end;

if bSuccess then

begin

GetMem(ptgGroups, 1024);

bSuccess := GetTokenInformation(hAccessToken, TokenGroups,

ptgGroups, 1024, dwInfoBufferSize);

CloseHandle(hAccessToken);

if bSuccess then

begin

AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,

SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,

0, 0, 0, 0, 0, 0, psidAdministrators);

{$R-}

for x := 0 to ptgGroups.GroupCount - 1 do

if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then

begin

Result := True;

Break;

end;

{$R+}

FreeSid(psidAdministrators);

end;

FreeMem(ptgGroups);

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

if isAdmin then

begin

ShowMessage('Logged in as Administrator');

end;

end;

check above code as per ur requirement .

Regards ,

venkat