alfresco - 在名为 webscript 的内部获取当前用户名

标签 alfresco

在露天有什么方法可以在 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/

相关文章:

java - 如何在露天查找文件夹然后子文件夹然后打印文件名

java - CMIS session.queryObjects 不返回方面

ssl - Alfresco & Solr SSL 证书握手超时

java - 下载为具有自定义文件夹类型的 Zip 文件夹

java - 在 Alfresco 中删除特定版本的文档

java - 使用 JCR 与 J2EE 客户端服务器环境中的各种内容存储库进行交互的标准接口(interface)

java - 触发 Activiti 工作流程以执行 ReceiveTask 循环中的任务

java - 如何让下面的代码在alfresco中正常工作?

postgresql - 露天 : Cannot find Alfresco Repository

java - 在 Eclipse 上创建 Alfresco maven 原型(prototype)时​​出错