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.
String currentUser = AuthenticationUtil.getRunAsUser(); … AuthenticationUtil.setRunAsUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); … // Create some directories … AuthenticationUtil.setRunAsUser(currentUser ); AuthenticationUtil.setFullyAuthenticatedUser(currentUser); // or AuthenticationUtil.clearCurrentSecurityContext();?
public void executeImpl(final Action actionF, final NodeRef actionedUponNodeRefF) { if (logger.isDebugEnabled()) { logger.debug("Action : OrganizeFileInDirectory"); } // Check that the node still exists if (this.nodeService.exists(actionedUponNodeRefF) == true) { try { AuthenticationUtil.runAs( new AuthenticationUtil.RunAsWork<Object>() { public Object doWork() throws Exception { UserTransaction trx_A = serviceRegistry.getTransactionService() .getUserTransaction(); try { trx_A.begin(); // Move files moveFile(…); trx_A.commit(); } catch (Throwable e) { try { if (trx_A.getStatus() == Status.STATUS_ACTIVE) { trx_A.rollback(); } } catch (Throwable ee) { // Handle double exception in whatever way is // appropriate eg. log it logger.error("", e); } logger.error("", e); } return null; }},"admin"); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.error("", e); } } if (logger.isDebugEnabled()) { logger.debug("End"); } } }
That code looks on the right sort of lines. What's the problem?
And while you are at it you should be using the same pattern with the RetryingTransactionHelper rather than attempting to manage the transactions yourself. In fact do you need the transaction handling at all?
AuthenticationUtil.runAs( new AuthenticationUtil.RunAsWork<Object>() { public Object doWork() throws Exception { UserTransaction trx_A = serviceRegistry.getTransactionService() .getUserTransaction(); try { trx_A.begin(); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); // Move files moveFile(…); trx_A.commit(); } catch (Throwable e) { try { if (trx_A.getStatus() == Status.STATUS_ACTIVE) { trx_A.rollback(); } } catch (Throwable ee) { // Handle double exception in whatever way is // appropriate eg. log it logger.error("", e); } logger.error("", e); } return null; }},AuthenticationUtil.getSystemUserName());