mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 10:35:56 +01:00 
			
		
		
		
	Set author for svn modify commits
This commit is contained in:
		| @@ -1,10 +1,12 @@ | ||||
| package sonia.scm.repository.spi; | ||||
|  | ||||
| import org.apache.shiro.SecurityUtils; | ||||
| import org.tmatesoft.svn.core.SVNCommitInfo; | ||||
| import org.tmatesoft.svn.core.SVNDepth; | ||||
| import org.tmatesoft.svn.core.SVNException; | ||||
| import org.tmatesoft.svn.core.wc.SVNClientManager; | ||||
| import org.tmatesoft.svn.core.wc.SVNWCClient; | ||||
| import org.tmatesoft.svn.core.wc.SVNWCUtil; | ||||
| import sonia.scm.repository.InternalRepositoryException; | ||||
| import sonia.scm.repository.Repository; | ||||
| import sonia.scm.repository.SvnWorkDirFactory; | ||||
| @@ -38,6 +40,7 @@ public class SvnModifyCommand implements ModifyCommand { | ||||
|  | ||||
|   private String commitChanges(SVNClientManager clientManager, File workingDirectory, String commitMessage) { | ||||
|     try { | ||||
|       clientManager.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager(getCurrentUserName(), new char[0])); | ||||
|       SVNCommitInfo svnCommitInfo = clientManager.getCommitClient().doCommit( | ||||
|         new File[]{workingDirectory}, | ||||
|         false, | ||||
| @@ -54,6 +57,14 @@ public class SvnModifyCommand implements ModifyCommand { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private String getCurrentUserName() { | ||||
|     if (SecurityUtils.getSubject() != null && SecurityUtils.getSubject().getPrincipal() != null) { | ||||
|       return SecurityUtils.getSubject().getPrincipal().toString(); | ||||
|     } else { | ||||
|       return "SCM-Manager"; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private void modifyWorkingDirectory(ModifyCommandRequest request, SVNClientManager clientManager, File workingDirectory) { | ||||
|     for (ModifyCommandRequest.PartialRequest partialRequest : request.getRequests()) { | ||||
|       try { | ||||
|   | ||||
| @@ -1,5 +1,8 @@ | ||||
| package sonia.scm.repository.spi; | ||||
|  | ||||
| import org.apache.shiro.subject.Subject; | ||||
| import org.apache.shiro.util.ThreadContext; | ||||
| import org.junit.After; | ||||
| import org.junit.Before; | ||||
| import org.junit.Rule; | ||||
| import org.junit.Test; | ||||
| @@ -14,6 +17,8 @@ import java.io.IOException; | ||||
|  | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||||
| import static org.mockito.Mockito.mock; | ||||
| import static org.mockito.Mockito.when; | ||||
|  | ||||
| public class SvnModifyCommandTest extends AbstractSvnCommandTestBase { | ||||
|  | ||||
| @@ -31,6 +36,18 @@ public class SvnModifyCommandTest extends AbstractSvnCommandTestBase { | ||||
|     svnModifyCommand = new SvnModifyCommand(context, createRepository(), workDirFactory); | ||||
|   } | ||||
|  | ||||
|   @Before | ||||
|   public void initSecurityManager() { | ||||
|     Subject subject = mock(Subject.class); | ||||
|     when(subject.getPrincipal()).thenReturn("alThor"); | ||||
|     ThreadContext.bind(subject); | ||||
|   } | ||||
|  | ||||
|   @After | ||||
|   public void cleanUpSecurityManager() { | ||||
|     ThreadContext.unbindSubject(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void shouldRemoveFiles() { | ||||
|     ModifyCommandRequest request = new ModifyCommandRequest(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user