Note that there are some explanatory texts on larger screens.

plurals
  1. POget current user name inside called webscript
    text
    copied!<p>Is there any way in alfresco to get the current user name inside web script ?? I am calling a web script and want to access current user name and password by which he logged in inside it. Here is my descriptor:</p> <pre><code>&lt;webscript&gt; &lt;shortname&gt;Save Document &lt;/shortname&gt; &lt;description&gt;Save description&lt;/description&gt; &lt;url&gt;/alfresco/save&lt;/url&gt; &lt;format default=""&gt;argument&lt;/format&gt; &lt;family&gt;Active document&lt;/family&gt; &lt;/webscript&gt; </code></pre> <p>My web script code :</p> <pre><code>public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { String nodeRefString = null; try { nodeRefString = req.getParameter("nodeRef"); if(nodeRefString != null &amp;&amp; !nodeRefString.isEmpty()) { AuthenticationUtil.runAs(new RunAsWork&lt;String&gt;() { public String doWork() throws Exception { String userName = AuthenticationUtil.getFullyAuthenticatedUser(); System.out.println("user name =" + userName); if(personService != null) { System.out.println("personService initialized successfully"); NodeRef personNode = personService.getPerson("mahesh"); System.out.println("password =" + nodeService.getProperty(personNode, ContentModel.PROP_PASSWORD)); } else { System.out.println("person service is null"); } NodeRef nodeRef = new NodeRef(nodeRefString); setNodeRef(nodeRef); setFileName((String) nodeService.getProperty(nodeRef,ContentModel.PROP_NAME)); return null; } }, AuthenticationUtil.getSystemUserName()); } } catch (Exception e) { e.printStackTrace(); } } </code></pre> <p>Do I supposed to add Authentication tag into my web script descriptor ?? I tried both AuthenticationUtil.getFullyAuthenticatedUser(); and AuthenticationUtil.getRunAsUser(). Both are returning "system" as user name.</p> <p>Any help is appreciated.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload