As developers we sometimes need to login using the API. Sometimes this is to avoid retyping the login during testing, or if we are doing some bulk loading or if we have no Window session available.
Here is the code you can use
RemoteMethodServer.getDefault().setUserName("wcadmin");
RemoteMethodServer.getDefault().setPassword("wcadmin");
Note a potential security risks of putting a password into the code, but it is still a valid techinque for developers to use.
It will work client and server side.