04-18-2012 09:51 AM
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));
04-19-2012 06:52 AM
04-19-2012 07:36 AM
04-19-2012 07:40 AM
04-19-2012 11:15 AM
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);
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.