1
0
-1

I have tried to get the username via the URL '/jw/web/json/workflow/currentUsername' since this is done via client script might overwritten via browser console.

kindly assits me to get the logged username from server side

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi, you can try to use the current user hash variable Hash Variable#CurrentUserHashVariable. Hash variables are processed server side.

      1. sankar

        Thank you, Anders I am trying in a external application to use #variables should i import the jars related to joget services. if possible kindly share an example of the same.

      2. Anders

        if you are doing from an external application then you would need to call the JSON API like previously. For security you can make the call from the server side instead of using client side javascript.

      3. sankar

        Thanks for the response I am trying the same below is the code for the same, but its returning roleAnonymous public static String getSessionUsername() { String userName = "roleAnonymous"; String url = "/jw/web/json/workflow/currentUsername"; try { URL obj = new URL(url); System.out.println("before Setting Connection Properties"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestProperty("Host", "localhost:8880"); con.setRequestProperty("Referer", "http://localhost:8880/themeinsight/";); // con.setRequestProperty("Cookie","helpGuide=false; JSESSIONID=C84DA81369DB5FE7498E8654F9F8628C"); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); System.out.println("\nSending 'GET' request to URL : " + url); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); // printin System.out.println("Response ---------------> " + response); JSONObject myresponse = new JSONObject(response.toString()); System.out.println("base -" + myresponse.getString("username")); } catch (Exception e) { System.out.println(e.getMessage()); } return userName; }

      CommentAdd your comment...