在露天有什么方法可以在 web 脚本中获取当前用户名吗??我正在调用一个 Web 脚本,并希望访问他在其中登录的当前用户名和密码。
这是我的描述符:
<webscript>
<shortname>Save Document </shortname>
<description>Save description</description>
<url>/alfresco/save</url>
<format default="">argument</format>
<family>Active document</family>
</webscript>
我的网络脚本代码:
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException {
String nodeRefString = null;
try {
nodeRefString = req.getParameter("nodeRef");
if(nodeRefString != null && !nodeRefString.isEmpty()) {
AuthenticationUtil.runAs(new RunAsWork<String>() {
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();
}
}
我应该将 Authentication 标签添加到我的 web 脚本描述符中吗??我尝试了 AuthenticationUtil.getFullyAuthenticatedUser();和 AuthenticationUtil.getRunAsUser()。两者都返回“系统”作为用户名。
任何帮助表示赞赏。
谢谢
最佳答案
如果您使用的是 Javascript Controller 或在 Freemarker模板:
person.properties["user:username"]
如果您在 Java Controller 中:
/**
* Get the user that is currently in effect for purposes of authentication. This includes
* any overlays introduced by {@link #setRunAsUser(String) runAs}.
*
* @return Returns the name of the user
* @throws AuthenticationException
*/
org.alfresco.repo.security.authentication.AuthenticationUtil.getRunAsUser()
编辑:根据您的评论,您正在使用
AuthenticationUtil.runAs
家庭。在这种情况下,您应该使用以下忽略对当前身份验证上下文的任何暂时更改的以下内容:/**
* Get the fully authenticated user.
* It returns the name of the user that last authenticated and excludes any overlay authentication set
* by {@link #runAs(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork, String) runAs}.
*
* @return Returns the name of the authenticated user
* @throws AuthenticationException
*/
org.alfresco.repo.security.authentication.AuthenticationUtil.getFullyAuthenticatedUser()
关于alfresco - 在名为 webscript 的内部获取当前用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11156671/