As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
Boolean rtn = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Boolean>() { @Override public Boolean doWork() throws Exception { // executes the following code as user who had the document previously checked out CheckOutCheckInService checkOutCheckInService = serviceRegistry.getCheckOutCheckInService(); //this line is debug code to check who the current user is according to the AuthenticationService //AuthenticationService authService = serviceRegistry.getAuthenticationService(); //if (log.isDebugEnabled()) log.debug("Current UserName in AuthenticationService is '" + authService.getCurrentUserName() + "'."); NodeRef checkedOutCopy = checkOutCheckInService.checkout(nodeRef); ContentWriter writer = fileFolderService.getWriter(checkedOutCopy); writer.putContent(workingCopyContentAndMetadata.getContentFile()); if (log.isDebugEnabled()) log.debug("Have uploaded working copy document as user '" + String.valueOf(workingCopyOwner) + "'."); return true; } }, String.valueOf(workingCopyOwner));
final String currentUser = AuthenticationUtil.getFullyAuthenticatedUser(); NodeRef checkedOutCopy = null; AuthenticationUtil.setFullyAuthenticatedUser(String.valueOf(workingCopyOwner)); if (log.isDebugEnabled()) log.debug("set fully authenticated user to '" + String.valueOf(workingCopyOwner) + "'"); final CheckOutCheckInService cociService = serviceRegistry.getCheckOutCheckInService(); try { checkedOutCopy = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>() { public NodeRef doWork() throws Exception { return cociService.checkout(nodeRef); } }, String.valueOf(workingCopyOwner)); ContentWriter writer = fileFolderService.getWriter(checkedOutCopy); writer.putContent(workingCopyContentAndMetadata.getContentFile()); if (log.isDebugEnabled()) log.debug("uploaded working copy content "); } finally { if (log.isDebugEnabled()) log.debug("set fully authenticated user back to '" + currentUser + "'"); AuthenticationUtil.setFullyAuthenticatedUser(currentUser); }