Get User requesting service URL(ODATA)

Hi Guys!

Im creating some odata services so ours users can consume it with excel and work with some data and it is working!

The problem now is: some services need to filter the data by user.

How do i get the user (windows authentication) who is requesting the odata and pass it as a parameter for my odbcAdapter, wich is executing a storedprocedure?

im using IS 10.5, on-premisse installation.

Hi Fabio,

did you check if the user is present somewhere in the ODATA request data, i.e. some sort of header line like it is used in HTTP headers?

Regards,
Holger

that the point. How do i check this inside the integration service?

Have you tried using pub.flow:getTransportInfo to get Session information. It should have user info in it.

no luck. pub.flow:getTransportInfo give me information about de http request, but only protocol, url, and the caller IP but not the username.

?

Hi fabio,

Nope…not anything related to user id it will not extract.

HTH,
RMG

You won’t get it from the getTransportInfo service, however you can do it with a java service.

You can use my package here

and the service is

pub.flow.session: getSessionID

the output also includes the userID associated with current call.

the java code is

public static final void getSessionID (IData pipeline)
        throws ServiceException
{
	// --- <<IS-START(getSessionID)>> ---
	// @sigtype java 3.5
	// [o] field:0:required sessionID
	// [o] field:0:required userID
	// [o] field:0:required uniqueID
   
   String sessionId = null;
   String name = null;
 
    if (Service.getSession() != null) 
    {
        try {
            sessionId = Service.getSession().getSessionID();
            name = Service.getSession().getUser().getName();
        } catch (Exception e) {
            throw new RuntimeException("Unable to retrieve the session ID : " + e);
        }
    }

    IDataCursor c = pipeline.getCursor();
    IDataUtil.put(c, "sessionID", sessionId);
    
    if (name != null && !name.equals("Default") && !name.equals("webTaskUser"))
    		IDataUtil.put(c, "userID", name);
    
   IDataUtil.put(c, "uniqueID", sessionId + getNextCount());
    c.destroy();
   
   // --- <<IS-END>> ---
}

enjoy
John.

@John_Carter4 answered the question. But just adding … you may want to authorize based on the group instead of username (say, you have Single-signon setup and use Active Directory group to class your users).

Code:

//Returns details of the user controlling the currently executing session.
		
		//Get the current session
		Session currentSession = Service.getSession();
		
		//Get current user
		User user = currentSession.getUser();
		
		//Assign the username value to strUsername
		String strUsername = user.getName();
		
		Vector<String> vectorMembershipNames = user.membershipNames();
		String [] membershipNames = vectorMembershipNames.toArray(new String [vectorMembershipNames.size()]);
		
		//insert the username and other details into the pipeline
		IDataCursor idcPipeline = pipeline.getCursor();
		idcPipeline.insertAfter("username", strUsername);
		idcPipeline.insertAfter("membershipNames", membershipNames);
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.