04-15-2011 05:47 AM
String currentUser = AuthenticationUtil.getRunAsUser();
…
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getAdminUserName());
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
…
// Create some directories
…
AuthenticationUtil.setRunAsUser(currentUser );
AuthenticationUtil.setFullyAuthenticatedUser(currentUser);
// or AuthenticationUtil.clearCurrentSecurityContext();?
04-15-2011 05:55 AM
04-15-2011 08:03 AM
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");
}
}
}
04-15-2011 08:29 AM
04-15-2011 08:55 AM
That code looks on the right sort of lines. What's the problem?The directories and the files that the method creates have properties "creator" and "modifier" by the user. He has all rights on theses directories/files and I want he can not have access.
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?I used this before but I got problems… I have never found but using another method (with UserTransaction) and all was working…
04-15-2011 09:23 AM
04-15-2011 09:37 AM
05-03-2011 02:39 AM
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());
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.