cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

Run IE task trough API with current logged user

smartel
6-Contributor

Run IE task trough API with current logged user

Hello,

I'm trying to run an IE task trough a java method. But Windchill ran the task as WCadmin .

The task run fine but it retrieves info that user shouldn't have access.

If I run the IE task in the browser with the user it run fine too.

here is the code:

public static String ieTaskRun(String Task1, String Name1, String Group1, String userNa) throws WTException, IOException, IEException {

String obid1 = "";

String obType = "";

try{

IeService ieService = new IeService();

Task objtask = new Task(Task1);

objtask.setService(ieService);

//>>>> Here is where I'm trying to set username who will run the task <<<

objtask.setUsername(userNa);

String groupOutName = Group1;

objtask.setParam("name", Name1);

objtask.setParam("GROUP_OUT", Group1);

System.out.println("**** ieTaskRun Check entering task **** " + userNa);

objtask.invoke();

Group prlnks = ieService.getGroup(groupOutName);

System.out.println("ieTaskRun element: " + prlnks.getElementCount());

if (prlnks.getElementCount() > 0){

for (int p = 0; p < prlnks.getElementCount(); p++)

{

obid1 = (String) prlnks.getAttributeValue(p, "number");

obType = (String) prlnks.getAttributeValue(p, "type");

if (obType.equalsIgnoreCase("CAD Document")){

obid1 = obid1 + ":" + (String) prlnks.getAttributeValue(p, "version");

}else{

obid1 = obid1 + ":" + (String) prlnks.getAttributeValue(p, "revision");

}

System.out.println("ieTaskRun obid Task: " + obid1 + " Object Type: " + obType);

if(obType.equalsIgnoreCase("CAD Document"))

{

return obid1;

}

}

}

} catch(Exception e) {

   //e.printStackTrace(System.err);

   return obid1;

  }

return obid1;

}//end of method ieTaskRun

1 ACCEPTED SOLUTION

Accepted Solutions
smartel
6-Contributor
(To:BineshKumar1)

Thanks this has lead me to the solution.

I modified my info engine task by adding this:

Group s = getGroup ("@SERVER");

s.toXML(new java.io.PrintWriter(System.out),true);

s.setAttributeValue (0, "auth-user", userNa.getName());

s.toXML(new java.io.PrintWriter(System.out),true);

userNa is a variable that is set during the info engine call.

Since that it retrieve exactly what the user is supposed to see.

View solution in original post

2 REPLIES 2

wt.org.WTPrincipal user = wt.session.SessionHelper.manager.getPrincipal();

You can use sessionhelper to get the current user

Thank you

Binesh Kumar

smartel
6-Contributor
(To:BineshKumar1)

Thanks this has lead me to the solution.

I modified my info engine task by adding this:

Group s = getGroup ("@SERVER");

s.toXML(new java.io.PrintWriter(System.out),true);

s.setAttributeValue (0, "auth-user", userNa.getName());

s.toXML(new java.io.PrintWriter(System.out),true);

userNa is a variable that is set during the info engine call.

Since that it retrieve exactly what the user is supposed to see.

Top Tags