<field id="serverCredentials" value="userId:password"/>
((CSClientService)wksContext.getService("CSClient")).setServerCredentials("userId:password");
This information enables the proxy security infrastructure to generate the security cookie to identify the user. The CSClient service performs the base64 encode internally.
try{ if (!createNewSession){ ((CSClientService)wksContext.getService("CSClient")).establishSession(false); } else ((CSClientService)wksContext.getService("CSClient")).establishSession(); }catch (DSECSException exc){ String httpError = exc.getHttpErrorCode(); if(httpError.equals("401")){ //Security Challenge //Do it here or in the dse.ini client configuration file. ((CSClientService)wksContext.getService("CSClient")).setServerCredentials("userID:password"); if ((!createNewSession){ ((CSClientService)wksContext.getService("CSClient")).establishSession(false); } else ((CSClientService)wksContext.getService("CSClient")).establishSession(); } }
If the user ID or password are not valid or the use did not provide them, the security proxy sends HTTP 401 Security Error. The application should catch the exception again and set the right user and password values using the setServerCredentials() method as shown in step 1. The application should then try to re-establish the session. A possible implementation is to loop the reconnections a number of times before aborting.
((CSClientService)wksContext.getService("CSClient")).setServerCredentials(null);