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