webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Get User requesting service URL(ODATA)

    Posted Tue April 05, 2022 08:02 AM

    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.


    #Integration-Server-and-ESB
    #API-Management
    #API-Gateway
    #webMethods
    #webМethods-cloud
    #Service-Designer
    #webMethods-io-Integration


  • 2.  RE: Get User requesting service URL(ODATA)

    Posted Tue April 05, 2022 02:22 PM

    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


    #webMethods-io-Integration
    #webMethods
    #API-Gateway
    #Service-Designer
    #Integration-Server-and-ESB
    #API-Management
    #webМethods-cloud


  • 3.  RE: Get User requesting service URL(ODATA)

    Posted Tue April 05, 2022 03:32 PM


  • 4.  RE: Get User requesting service URL(ODATA)

    Posted Wed May 11, 2022 11:23 AM

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


    #API-Management
    #webMethods-io-Integration
    #Integration-Server-and-ESB
    #webМethods-cloud
    #API-Gateway
    #Service-Designer
    #webMethods


  • 5.  RE: Get User requesting service URL(ODATA)

    Posted Wed May 11, 2022 12:57 PM

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

    ?


    #Integration-Server-and-ESB
    #API-Gateway
    #API-Management
    #webMethods
    #Service-Designer
    #webМethods-cloud
    #webMethods-io-Integration


  • 6.  RE: Get User requesting service URL(ODATA)

    Posted Thu May 12, 2022 05:30 PM


  • 7.  RE: Get User requesting service URL(ODATA)

    Posted Fri May 13, 2022 02:34 AM

    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.


    #webMethods-io-Integration
    #API-Management
    #webМethods-cloud
    #Service-Designer
    #Integration-Server-and-ESB
    #API-Gateway
    #webMethods


  • 8.  RE: Get User requesting service URL(ODATA)

    Posted Wed May 18, 2022 11:50 PM

    @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);
    

    #Service-Designer
    #webMethods
    #API-Management
    #webМethods-cloud
    #API-Gateway
    #webMethods-io-Integration
    #Integration-Server-and-ESB