Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Commit

Permalink
git commits should use the authenticated user's username
Browse files Browse the repository at this point in the history
  • Loading branch information
Erick Tryzelaar committed Mar 26, 2014
1 parent 2d2254e commit 7ff88c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -355,6 +357,8 @@ public ResponseEntity<Map<String, Object>> getCurrentBranch(@PathVariable String

@RequestMapping(value = "/projects/{projectId}/current-branch/commit", method = RequestMethod.POST)
public ResponseEntity<Map<String, Object>> commitBranch(@PathVariable String projectId) throws GitAPIException, IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

Map<String, Object> response = new HashMap<>();

MetaGraphTx tx = metaGraphService.newTransaction();
Expand All @@ -381,7 +385,7 @@ public ResponseEntity<Map<String, Object>> commitBranch(@PathVariable String pro
Git git = historyService.projectGitRepository(projectMetadata);
try {
git.commit()
.setAuthor("user", "[email protected]")
.setAuthor(authentication.getName(), "")
.setMessage("commit")
.call();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -118,6 +120,7 @@ public ResponseEntity<byte[]> export(@PathVariable String graphId,
public ResponseEntity<Map<String, Object>> save(@PathVariable String graphId,
@Valid GraphExportBean item,
BindingResult result) throws IOException, GitAPIException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

Map<String, Object> response = new HashMap<>();

Expand Down Expand Up @@ -180,7 +183,7 @@ public ResponseEntity<Map<String, Object>> save(@PathVariable String graphId,
.call();

git.commit()
.setAuthor("user", "[email protected]")
.setAuthor(authentication.getName(), "")
.setMessage("commit")
.call();
} finally {
Expand Down

0 comments on commit 7ff88c6

Please sign in to comment.