branch feature/GIT updated (3ad1bbc -> 659ea7b)
This is an automated email from the git hooks/post-receive script. New change to branch feature/GIT in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git from 3ad1bbc Added DTOs for the commit new 659ea7b Added DTOs for the upload action The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 659ea7b9f406f7d71874e2fb5d8b9e7ada676e34 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Mon May 4 17:00:00 2015 +0200 Added DTOs for the upload action Summary of changes: .../org/nuiton/scmwebeditor/GitConnection.java | 134 +++++++++---------- .../org/nuiton/scmwebeditor/ScmConnection.java | 17 +-- .../org/nuiton/scmwebeditor/SvnConnection.java | 142 +++++++++------------ .../nuiton/scmwebeditor/actions/BrowseAction.java | 58 ++++++++- .../nuiton/scmwebeditor/actions/EditAction.java | 2 +- .../actions/ScmWebEditorCommitAction.java | 4 +- .../nuiton/scmwebeditor/actions/UploadAction.java | 80 +++++++++++- .../org/nuiton/scmwebeditor/dto/UploadDto.java | 84 ++++++++++++ .../nuiton/scmwebeditor/dto/UploadResultDto.java | 46 +++++++ 9 files changed, 396 insertions(+), 171 deletions(-) create mode 100644 src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java create mode 100644 src/main/java/org/nuiton/scmwebeditor/dto/UploadResultDto.java -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/GIT in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git commit 659ea7b9f406f7d71874e2fb5d8b9e7ada676e34 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Mon May 4 17:00:00 2015 +0200 Added DTOs for the upload action --- .../org/nuiton/scmwebeditor/GitConnection.java | 134 +++++++++---------- .../org/nuiton/scmwebeditor/ScmConnection.java | 17 +-- .../org/nuiton/scmwebeditor/SvnConnection.java | 142 +++++++++------------ .../nuiton/scmwebeditor/actions/BrowseAction.java | 58 ++++++++- .../nuiton/scmwebeditor/actions/EditAction.java | 2 +- .../actions/ScmWebEditorCommitAction.java | 4 +- .../nuiton/scmwebeditor/actions/UploadAction.java | 80 +++++++++++- .../org/nuiton/scmwebeditor/dto/UploadDto.java | 84 ++++++++++++ .../nuiton/scmwebeditor/dto/UploadResultDto.java | 46 +++++++ 9 files changed, 396 insertions(+), 171 deletions(-) diff --git a/src/main/java/org/nuiton/scmwebeditor/GitConnection.java b/src/main/java/org/nuiton/scmwebeditor/GitConnection.java index 19d66d3..bc85e1d 100644 --- a/src/main/java/org/nuiton/scmwebeditor/GitConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/GitConnection.java @@ -40,14 +40,7 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.treewalk.TreeWalk; -import org.nuiton.scmwebeditor.actions.BrowseAction; -import org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction; -import org.nuiton.scmwebeditor.actions.UploadAction; -import org.nuiton.scmwebeditor.dto.BrowseDto; -import org.nuiton.scmwebeditor.dto.BrowseResultDto; -import org.nuiton.scmwebeditor.dto.CommitDto; -import org.nuiton.scmwebeditor.dto.CommitResultDto; -import sun.security.x509.CRLDistributionPointsExtension; +import org.nuiton.scmwebeditor.dto.*; import javax.naming.AuthenticationException; import java.io.File; @@ -145,7 +138,7 @@ public class GitConnection implements ScmConnection { String url; - String headBranchName = null; + String headBranchName; try { headBranchName = gitRepo.getBranch(); } catch (IOException e) { @@ -160,7 +153,7 @@ public class GitConnection implements ScmConnection { resultDto.setFiles(new LinkedList<String>()); resultDto.setDirectories(new HashMap<String, String>()); - ObjectId commitId = null; + ObjectId commitId; // getting the requested branch, or the last commit if none was requested try { @@ -218,7 +211,7 @@ public class GitConnection implements ScmConnection { return resultDto; } - RevCommit commit = null; + RevCommit commit; RevWalk revWalk = new RevWalk(gitRepo); if (commitId != null) { @@ -277,31 +270,6 @@ public class GitConnection implements ScmConnection { resultDto.setError(null); - // building the tree - if (resultDto.getFiles() != null) { - for (String file : resultDto.getFiles()) { - TreeNode node = new TreeNode(); - node.setId(file); - node.setTitle(file.substring(file.lastIndexOf("/") + 1)); - node.setState(TreeNode.NODE_STATE_LEAF); - node.setIcon("ui-icon-document"); - resultDto.getNodes().add(node); - } - } - - if (resultDto.getDirectories() != null) { - for (Map.Entry<String, String> entry : resultDto.getDirectories().entrySet()) { - - String value = entry.getValue(); - - TreeNode node = new TreeNode(); - node.setId(value); - - node.setTitle(value.substring(value.lastIndexOf("/"))); - resultDto.getNodes().add(node); - } - } - return resultDto; } @@ -474,74 +442,86 @@ public class GitConnection implements ScmConnection { } @Override - public String uploadFile(UploadAction action) { + public UploadResultDto uploadFile(UploadDto dto) { + + UploadResultDto resultDto = new UploadResultDto(); try { - cloneRepository(action.getUsername(), action.getPw()); + cloneRepository(dto.getUsername(), dto.getPassword()); } catch (ScmNotFoundException e) { if (log.isErrorEnabled()) { log.error("Error while cloning the repository", e); } - return action.SUCCESS; + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Error while cloning the repository", e); } - return action.SUCCESS; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (AuthenticationException e) { if (log.isErrorEnabled()) { log.error("Error while cloning the repository", e); } - return action.SUCCESS; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } - action.setFileRoot(addressGit); - action.setScmRoot(addressGit); + resultDto.setFileRoot(addressGit); + resultDto.setScmRoot(addressGit); // if there is no file to upload, we get back to the upload form - if (action.getUpload() == null) { - return UploadAction.REDIRECT; + if (dto.getUpload() == null) { + resultDto.setError(UploadResultDto.REDIRECT); + return resultDto; } - action.setBadLogin(false); - action.setError(false); - if (log.isDebugEnabled()) { - log.debug("FileName : " + action.getUploadFileName()); - log.debug("ContentType : " + action.getUploadContentType()); + log.debug("FileName : " + dto.getUploadFileName()); + log.debug("ContentType : " + dto.getUploadContentType()); } // Writing the file to the local directory - String pathOnRepo = action.getScmPath(); + String pathOnRepo = dto.getScmPath(); String path; if (pathOnRepo.length() > addressGit.length()) { pathOnRepo = pathOnRepo.substring(addressGit.length() + 1); - path = pathOnRepo + "/" + action.getUploadFileName(); + path = pathOnRepo + "/" + dto.getUploadFileName(); } else { - pathOnRepo = ""; - path = action.getUploadFileName(); + path = dto.getUploadFileName(); } File file = new File(localDirectory.getAbsolutePath() + "/" + path); try { - FileUtils.copyFile(action.getUpload(), file); + FileUtils.copyFile(dto.getUpload(), file); } catch (IOException e) { - action.setError(true); if (log.isErrorEnabled()) { log.error("Can't copy the file to the local directory", e); } - return UploadAction.ERROR; + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } // authentication - CredentialsProvider credentials = new UsernamePasswordCredentialsProvider(action.getUsername(), action.getPw()); + if (dto.getUsername() == null) { + dto.setUsername("anonymous"); + } + + if (dto.getPassword() == null) { + dto.setPassword("anonymous"); + } + + CredentialsProvider credentials = new UsernamePasswordCredentialsProvider(dto.getUsername(), dto.getPassword()); try { Git git = Git.open(localDirectory); @@ -565,8 +545,8 @@ public class GitConnection implements ScmConnection { CommitCommand commit = git.commit(); commit.setAll(true); - commit.setAuthor(action.getUsername(), "unknown"); - commit.setMessage("From scmwebeditor -- add the file : " + action.getUploadFileName()); + commit.setAuthor(dto.getUsername(), "unknown"); + commit.setMessage("From scmwebeditor -- add the file : " + dto.getUploadFileName()); try { commit.call(); @@ -575,7 +555,8 @@ public class GitConnection implements ScmConnection { log.error("Can not commit", e); } - return action.ERROR; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } if (log.isDebugEnabled()) { @@ -594,47 +575,54 @@ public class GitConnection implements ScmConnection { log.error("Can not push : the Git repository has no HEAD reference", e); } - return action.ERROR; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (UnmergedPathsException e) { if (log.isErrorEnabled()) { log.error("Can not push : conflicts found (unmerged paths)", e); } - return action.ERROR; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (ConcurrentRefUpdateException e) { if (log.isErrorEnabled()) { log.error("Can not push : someone else is updating the HEAD or the branch", e); } - return action.ERROR; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (WrongRepositoryStateException e) { if (log.isErrorEnabled()) { log.error("Can not push : the repository is not in the right state", e); } - return action.ERROR; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (RejectCommitException e) { if (log.isErrorEnabled()) { log.error("Can not push : commit rejected", e); } - return action.ERROR; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (GitAPIException e) { if (log.isErrorEnabled()) { log.error("Can not push", e); } - return action.ERROR; + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Can not open git local repository : " + localDirectory.getAbsolutePath(), e); - - return action.ERROR; } + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } - return action.SUCCESS; + return resultDto; } @@ -809,9 +797,9 @@ public class GitConnection implements ScmConnection { md.update(addressGit.getBytes()); byte byteData[] = md.digest(); - StringBuffer sb = new StringBuffer(); - for (int i = 0 ; i < byteData.length ; i++) { - String hexByte = Integer.toString((byteData[i] & 0xff) + 0x100, 16); + StringBuilder sb = new StringBuilder(); + for (byte aByteData : byteData) { + String hexByte = Integer.toString((aByteData & 0xff) + 0x100, 16); hexByte = hexByte.substring(1); sb.append(hexByte); } diff --git a/src/main/java/org/nuiton/scmwebeditor/ScmConnection.java b/src/main/java/org/nuiton/scmwebeditor/ScmConnection.java index 505c817..54b5c09 100644 --- a/src/main/java/org/nuiton/scmwebeditor/ScmConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/ScmConnection.java @@ -1,12 +1,6 @@ package org.nuiton.scmwebeditor; -import org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction; -import org.nuiton.scmwebeditor.actions.BrowseAction; -import org.nuiton.scmwebeditor.actions.UploadAction; -import org.nuiton.scmwebeditor.dto.BrowseDto; -import org.nuiton.scmwebeditor.dto.BrowseResultDto; -import org.nuiton.scmwebeditor.dto.CommitDto; -import org.nuiton.scmwebeditor.dto.CommitResultDto; +import org.nuiton.scmwebeditor.dto.*; import javax.naming.AuthenticationException; @@ -33,13 +27,10 @@ public interface ScmConnection { /** * Uploads a file to the repository as a new file - * @param action the UploadAction which contains the parameters (repository's address, file to upload...) - * @return UploadAction.ERROR if an error occurred - * UploadAction.REDIRECT if there is no file to upload - * UploadAction.LOGIN if the authentication failed - * UploadAction.SUCCESS if the upload has been done without any problem + * @param dto the DTO which contains all the parameters + * @return a DTO which contains all the results */ - public String uploadFile(UploadAction action); + public UploadResultDto uploadFile(UploadDto dto); /** diff --git a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java index c9fd7b3..6efc624 100644 --- a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java @@ -28,10 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.scmwebeditor.actions.BrowseAction; import org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction; import org.nuiton.scmwebeditor.actions.UploadAction; -import org.nuiton.scmwebeditor.dto.BrowseDto; -import org.nuiton.scmwebeditor.dto.BrowseResultDto; -import org.nuiton.scmwebeditor.dto.CommitDto; -import org.nuiton.scmwebeditor.dto.CommitResultDto; +import org.nuiton.scmwebeditor.dto.*; import org.nuiton.util.FileUtil; import org.tmatesoft.svn.core.*; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; @@ -212,30 +209,6 @@ public class SvnConnection implements ScmConnection { resultDto.setError(null); - if (resultDto.getFiles() != null) { - for (String file : resultDto.getFiles()) { - TreeNode node = new TreeNode(); - node.setId(file); - node.setTitle(file.substring(file.lastIndexOf("/") + 1)); - node.setState(TreeNode.NODE_STATE_LEAF); - node.setIcon("ui-icon-document"); - resultDto.getNodes().add(node); - } - } - - - if (resultDto.getDirectories() != null) { - for (Map.Entry<String, String> entry : resultDto.getDirectories().entrySet()) { - - String value = entry.getValue(); - - TreeNode node = new TreeNode(); - node.setId(value); - node.setTitle(value.substring(value.lastIndexOf("/"))); - resultDto.getNodes().add(node); - } - } - return resultDto; } @@ -434,19 +407,31 @@ public class SvnConnection implements ScmConnection { @Override - public String uploadFile(UploadAction action) { + public UploadResultDto uploadFile(UploadDto dto) { + + UploadResultDto resultDto = new UploadResultDto(); + + if (dto.getUsername() == null) { + dto.setUsername("anonymous"); + } - action.setScmRoot(getSvnRoot()); - action.setFileRoot(svnPath); + if (dto.getPassword() == null) { + dto.setPassword("anonymous"); + } + resultDto.setScmRoot(getSvnRoot(dto.getUsername(), dto.getPassword())); + resultDto.setFileRoot(addressSvn); - if (action.getScmRoot() == null) { - action.setScmRoot(action.getFileRoot()); + if (resultDto.getScmRoot() == null) { + resultDto.setScmRoot(resultDto.getFileRoot()); } - String repositoryUUID = getRepositoryId(); - updateAuthentication(action.getUsername(), action.getPw()); + if (resultDto.getScmRoot() == null) { + resultDto.setScmRoot(resultDto.getFileRoot()); + } + + updateAuthentication(dto.getUsername(), dto.getPassword()); try { testConnection(); @@ -454,23 +439,22 @@ public class SvnConnection implements ScmConnection { if (log.isDebugEnabled()) { log.debug("Test connection fail", e); } - action.getScmSession().delScmUser(repositoryUUID); - action.setUsername(null); - action.setPw(null); + + resultDto.setError(UploadResultDto.CONNECTION_FAILED); + return resultDto; } // if there is no file to upload we get back to the upload form - if (action.getUpload() == null) { - return UploadAction.REDIRECT; - } + if (dto.getUpload() == null) { - action.setBadLogin(false); - action.setError(false); + resultDto.setError(UploadResultDto.REDIRECT); + return resultDto; + } if (log.isDebugEnabled()) { - log.debug("FileName : " + action.getUploadFileName()); - log.debug("ContentType : " + action.getUploadContentType()); + log.debug("FileName : " + dto.getUploadFileName()); + log.debug("ContentType : " + dto.getUploadContentType()); } /* @@ -485,16 +469,17 @@ public class SvnConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Can't create checkoutDir", e1); } - action.setError(true); - return UploadAction.ERROR; + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } try { if (log.isDebugEnabled()) { - log.debug("Do Checkout of " + action.getScmRoot()); + log.debug("Do Checkout of " + dto.getScmRoot()); } - upclient.doCheckout(SVNURL.parseURIEncoded(action.getScmRoot()), checkoutDir, + upclient.doCheckout(SVNURL.parseURIEncoded(dto.getScmRoot()), checkoutDir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false); } catch (SVNAuthenticationException authexep) { @@ -505,14 +490,16 @@ public class SvnConnection implements ScmConnection { // deleting the temporary directory delTempDirectory(checkoutDir); //redirect to a login page - action.setError(true); - return UploadAction.ERROR; + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } catch (SVNException e) { // deleting the temporary directory delTempDirectory(checkoutDir); - action.setError(true); - return UploadAction.ERROR; + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } @@ -526,16 +513,17 @@ public class SvnConnection implements ScmConnection { String checkoutPath = checkoutDir.getAbsolutePath(); - File file = new File(checkoutPath + svnPath.replace(action.getScmRoot(), ""), action.getUploadFileName()); + File file = new File(checkoutPath + svnPath.replace(dto.getScmRoot(), ""), dto.getUploadFileName()); try { - FileUtils.copyFile(action.getUpload(), file); + FileUtils.copyFile(dto.getUpload(), file); } catch (IOException e) { - action.setError(true); if (log.isErrorEnabled()) { log.error("Can't copy the file to the checkout directory", e); } - return UploadAction.ERROR; + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } @@ -559,10 +547,11 @@ public class SvnConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Erreur SVN Add", e); } - action.setError(true); // deleting the temporary directory delTempDirectory(checkoutDir); - return UploadAction.ERROR; + + resultDto.setError(UploadResultDto.CONNECTION_FAILED); + return resultDto; } File[] checkoutDirTab = new File[1]; @@ -570,7 +559,7 @@ public class SvnConnection implements ScmConnection { try { manager.getCommitClient().doCommit(checkoutDirTab, false, "From scmwebeditor -- add the file : " + - action.getUploadFileName(), null, null, false, true, SVNDepth.INFINITY); + dto.getUploadFileName(), null, null, false, true, SVNDepth.INFINITY); if (log.isDebugEnabled()) { log.debug("Commit success !"); @@ -580,19 +569,20 @@ public class SvnConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("authentification fail"); } - action.setBadLogin(true); // deleting the temporary directory delTempDirectory(checkoutDir); - action.getScmSession().delScmUser(repositoryUUID); - return UploadAction.LOGIN; + + resultDto.setError(UploadResultDto.CONNECTION_FAILED); + return resultDto; } catch (SVNException e) { if (log.isErrorEnabled()) { log.error("Erreur SVN commit", e); } - action.setError(true); // deleting the temporary directory delTempDirectory(checkoutDir); - return UploadAction.ERROR; + + resultDto.setError(UploadResultDto.ERROR); + return resultDto; } @@ -604,10 +594,9 @@ public class SvnConnection implements ScmConnection { } if (log.isInfoEnabled()) { - log.info(action.getUsername() + " with IP " + action.getRequest().getRemoteAddr() + " add the file " + - action.getUploadFileName() + " on the repository."); + log.info(dto.getUsername() + " add the file " + dto.getUploadFileName() + " on the repository."); } - return UploadAction.SUCCESS; + return resultDto; } @@ -620,7 +609,7 @@ public class SvnConnection implements ScmConnection { updateAuthentication(username, password); String lastRevision = null; - SVNRepository repository = null; + SVNRepository repository; try { repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url)); @@ -729,11 +718,11 @@ public class SvnConnection implements ScmConnection { } - public String getSvnRoot() { + public String getSvnRoot(String username, String password) { String repositoryRoot; try { SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(addressSvn)); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(); + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); repository.setAuthenticationManager(authManager); repositoryRoot = repository.getRepositoryRoot(true).toString(); @@ -758,10 +747,7 @@ public class SvnConnection implements ScmConnection { SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(addressSvn)); repository.setAuthenticationManager(authManager); - repository.testConnection(); - - } @@ -899,19 +885,17 @@ public class SvnConnection implements ScmConnection { public void listEntries(SVNRepository repository, String path, String address, BrowseResultDto resultDto) { - Collection<?> entries = null; + Collection<SVNDirEntry> entries = null; try { - entries = repository.getDir(path, -1, null, (Collection<?>) null); + entries = repository.getDir(path, -1, null, (Collection<SVNDirEntry>) null); } catch (SVNException e) { if (log.isErrorEnabled()) { log.error("Can not reach the repository", e); } } - Iterator<?> iterator = entries.iterator(); - while (iterator.hasNext()) { - SVNDirEntry entry = (SVNDirEntry) iterator.next(); + for (SVNDirEntry entry : entries) { if (log.isDebugEnabled()) { log.debug("/" + (path.equals("") ? "" : path + "/") + entry.getName() + "\n"); } diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/BrowseAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/BrowseAction.java index 3351f5c..02a5cd8 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/BrowseAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/BrowseAction.java @@ -24,17 +24,22 @@ package org.nuiton.scmwebeditor.actions; import com.jgeppert.struts2.jquery.tree.result.TreeNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.shiro.codec.Base64; +import org.apache.shiro.crypto.BlowfishCipherService; +import org.apache.struts2.interceptor.ServletResponseAware; import org.nuiton.scmwebeditor.*; import org.nuiton.scmwebeditor.dto.BrowseDto; import org.nuiton.scmwebeditor.dto.BrowseResultDto; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.List; import java.util.Map; -public class BrowseAction extends AbstractScmWebEditorAction { +public class BrowseAction extends AbstractScmWebEditorAction implements ServletResponseAware { private static final long serialVersionUID = 4432027215087932750L; @@ -70,6 +75,8 @@ public class BrowseAction extends AbstractScmWebEditorAction { protected String headBranchName; + protected transient HttpServletResponse response; + public boolean getError() { return error; } public void setError(boolean error) { this.error = error; } @@ -197,6 +204,49 @@ public class BrowseAction extends AbstractScmWebEditorAction { } } + + // building the tree + if (resultDto.getFiles() != null) { + for (String file : resultDto.getFiles()) { + TreeNode node = new TreeNode(); + node.setId(file); + node.setTitle(file.substring(file.lastIndexOf("/") + 1)); + node.setState(TreeNode.NODE_STATE_LEAF); + node.setIcon("ui-icon-document"); + resultDto.getNodes().add(node); + } + } + + if (resultDto.getDirectories() != null) { + for (Map.Entry<String, String> entry : resultDto.getDirectories().entrySet()) { + + String value = entry.getValue(); + + TreeNode node = new TreeNode(); + node.setId(value); + node.setTitle(value.substring(value.lastIndexOf("/"))); + resultDto.getNodes().add(node); + } + } + + + // if the repository is not protected for writing, we get its UUID + String repositoryUUID = scmConn.getRepositoryId(); + if (repositoryUUID == null) { + repositoryUUID = address; + } + + if (username != null && pw != null) { + BlowfishCipherService bf = new BlowfishCipherService(); + byte[] privateKey = Base64.decode(ScmWebEditorConfig.getKey()); + + Cookie authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes(), privateKey).toBase64()); + authCookie.setMaxAge(60 * 60 * 24 * 365); + response.addCookie(authCookie); + + getScmSession().addScmUser(repositoryUUID, username, pw); + } + return SUCCESS; } @@ -257,4 +307,10 @@ public class BrowseAction extends AbstractScmWebEditorAction { } + @Override + public void setServletResponse(HttpServletResponse response) { + this.response = response; + } + + } diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/EditAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/EditAction.java index 8959d53..a83c0a6 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/EditAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/EditAction.java @@ -95,7 +95,7 @@ public class EditAction extends ScmWebEditorMainAction { */ if (username == null && pw == null) { if (getScmSession().getUsername(repositoryUUID) != null && getScmSession().getPassword(repositoryUUID) != null) { - //On recupère les identifiants en session + // getting the authentication information from the session username = getScmSession().getUsername(repositoryUUID); pw = getScmSession().getPassword(repositoryUUID); } else { diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java index 795bd0b..f517121 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java @@ -271,10 +271,10 @@ public class ScmWebEditorCommitAction extends AbstractScmWebEditorAction impleme /* - * Lecture du cookie + * reading the cookie */ String usernamepwCookie = null; - // lire cookies + // read the cookies BlowfishCipherService bf = new BlowfishCipherService(); diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java index ad8f889..033af28 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java @@ -23,12 +23,19 @@ package org.nuiton.scmwebeditor.actions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.shiro.codec.Base64; +import org.apache.shiro.crypto.BlowfishCipherService; import org.apache.struts2.interceptor.ServletRequestAware; import org.nuiton.scmwebeditor.ScmConnection; import org.nuiton.scmwebeditor.ScmConnectionFactory; import org.nuiton.scmwebeditor.ScmNotFoundException; +import org.nuiton.scmwebeditor.ScmWebEditorConfig; +import org.nuiton.scmwebeditor.dto.UploadDto; +import org.nuiton.scmwebeditor.dto.UploadResultDto; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.File; @@ -156,9 +163,78 @@ public class UploadAction extends AbstractScmWebEditorAction implements ServletR } } - String returnCode = scmConn.uploadFile(this); - return returnCode; + // if the repository is not protected for writing, we get its UUID + String repositoryUUID = scmConn.getRepositoryId(); + if (repositoryUUID == null) { + repositoryUUID = address; + } + + + if (username == null && pw == null) { + if (getScmSession().getUsername(repositoryUUID) != null && getScmSession().getPassword(repositoryUUID) != null) { + // getting the authentication information in session + username = getScmSession().getUsername(repositoryUUID); + pw = getScmSession().getPassword(repositoryUUID); + } else { + username = null; + pw = null; + } + } else { + getScmSession().addScmUser(repositoryUUID, username, pw); + } + + + UploadDto dto = new UploadDto(); + dto.setUsername(username); + dto.setPassword(pw); + dto.setUpload(upload); + dto.setUploadFileName(uploadFileName); + dto.setUploadContentType(uploadContentType); + dto.setScmPath(scmPath); + dto.setScmRoot(scmRoot); + + UploadResultDto resultDto = scmConn.uploadFile(dto); + + if (resultDto.getFileRoot() != null) { + fileRoot = resultDto.getFileRoot(); + } + if (resultDto.getScmRoot() != null) { + scmRoot = resultDto.getScmRoot(); + } + + if (resultDto.getError() != null) { + + String errorMessage = resultDto.getError(); + error = true; + + if (errorMessage.equals(UploadResultDto.CONNECTION_FAILED)) { + + getScmSession().delScmUser(scmConn.getRepositoryId()); + username = null; + pw = null; + + return ERROR; + + } else if (errorMessage.equals(UploadResultDto.AUTH_ERROR)) { + + badLogin = true; + getScmSession().delScmUser(scmConn.getRepositoryId()); + + return LOGIN; + + } else if (errorMessage.equals(UploadResultDto.REDIRECT)) { + + error = false; + + return REDIRECT; + } else { + + return ERROR; + } + } + + return SUCCESS; } @Override diff --git a/src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java b/src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java new file mode 100644 index 0000000..1f142a6 --- /dev/null +++ b/src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java @@ -0,0 +1,84 @@ +package org.nuiton.scmwebeditor.dto; + +import java.io.File; + +public class UploadDto { + + /** the username used to connect to the SCM */ + protected String username; + + /** the password used to connect to the SCM */ + protected String password; + + /** the file to upload */ + protected File upload; + + /** the name of the file to upload */ + protected String uploadFileName; + + /** the type of the file to upload's content */ + protected String uploadContentType; + + /** path to the SCM */ + protected String scmPath; + + /** the root directory of the SCM */ + protected String scmRoot; + + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public File getUpload() { + return upload; + } + + public void setUpload(File upload) { + this.upload = upload; + } + + public String getUploadFileName() { + return uploadFileName; + } + + public void setUploadFileName(String uploadFileName) { + this.uploadFileName = uploadFileName; + } + + public String getUploadContentType() { + return uploadContentType; + } + + public void setUploadContentType(String uploadContentType) { + this.uploadContentType = uploadContentType; + } + + public String getScmPath() { + return scmPath; + } + + public void setScmPath(String scmPath) { + this.scmPath = scmPath; + } + + public String getScmRoot() { + return scmRoot; + } + + public void setScmRoot(String scmRoot) { + this.scmRoot = scmRoot; + } +} diff --git a/src/main/java/org/nuiton/scmwebeditor/dto/UploadResultDto.java b/src/main/java/org/nuiton/scmwebeditor/dto/UploadResultDto.java new file mode 100644 index 0000000..aa03bb1 --- /dev/null +++ b/src/main/java/org/nuiton/scmwebeditor/dto/UploadResultDto.java @@ -0,0 +1,46 @@ +package org.nuiton.scmwebeditor.dto; + +public class UploadResultDto { + + public static String ERROR = "error"; + + public static String REDIRECT = "redirect"; + + public static String CONNECTION_FAILED = "connection failed"; + + public static String AUTH_ERROR = "auth error"; + + /** gives a message about the error if one occured */ + protected String error; + + /** the directory which contains the file */ + protected String fileRoot; + + /** the root direcory of the SCM */ + protected String scmRoot; + + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } + + public String getFileRoot() { + return fileRoot; + } + + public void setFileRoot(String fileRoot) { + this.fileRoot = fileRoot; + } + + public String getScmRoot() { + return scmRoot; + } + + public void setScmRoot(String scmRoot) { + this.scmRoot = scmRoot; + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm