AnsweredAssumed Answered

Why is the modifier of a content a random user from the list of logged in users?

Question asked by darkstar1 on Mar 1, 2017
Latest reply on Mar 10, 2017 by darkstar1

I have a webscript:

desc.xml - 

    <shortname>LibreOffice Online PutFile</shortname>
    <family>LibreOffice Online</family>
    <format default="json"></format>

java controller (shortened slightly for brevity):

public class LOPutFileWebScript extends AbstractWebScript {
    private static final Log logger = LogFactory.getLog(LOPutFileWebScript.class);
    private WOPITokenService wopiTokenService;
    private NodeService nodeService;
    private ContentService contentService;

    public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
        try {
            final WOPIAccessTokenInfo tokenInfo = wopiTokenService.getTokenInfo(req);
            final NodeRef nodeRef = wopiTokenService.getFileNodeRef(tokenInfo);
            //Verifying that the user actually exists
            final PersonInfo person = wopiTokenService.getUserInfoOfToken(tokenInfo);
            if (StringUtils.isBlank(person.getUserName()) && !person.getUserName().equals(tokenInfo.getUserName()) )
                throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Invalid user id in token.");

            if(tokenInfo != null) {
                AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
                    public Object doWork() throws Exception {
                        ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
                        writer.guessMimetype((String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME));

                        //Output is correct 100% of the time
                        logger.debug("\n****** Debug testing ********\nToken: " + tokenInfo.getAccessToken()
                                + "FileId: " + tokenInfo.getFileId() + "\nUserName: " + tokenInfo.getUserName() + "\n");
                        return null;
                }, tokenInfo.getUserName());
            //The output here results in a random user name. Seemingly from the pool of logged in users.
            logger.debug("Modifier for the above nodeRef [" + nodeRef.toString() + "] is: " + nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER));
        catch(ContentIOException | WebScriptException we){
            //throw a bunch of errors
//Setters for services...

It so happens that after editing a document, the ContentModel.PROP_MODIFIER property of the document node is a seemingly random user from the pool of logged in users. I was under the understanding that the expected behaviour would be that when the default onUpdateBehaviour kicked, in it would update with the details found in the context, and since the thread is run as the user, I figured the information passed to the behaviour would come from this thread.

I'd appreciate some insight into this.