You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/07/08 07:57:33 UTC

[GitHub] [maven-scm] michael-o commented on a diff in pull request #153: [SCM-945] Update to JGit 5.13.1 leveraging Apache Mina SSHD

michael-o commented on code in PR #153:
URL: https://github.com/apache/maven-scm/pull/153#discussion_r916561146


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java:
##########
@@ -72,60 +64,56 @@ public void configure( Transport transport )
         }
     }
 
-    private static class SimpleSessionFactory extends JschConfigSessionFactory
-    {
-        @Override
-        protected void configure( OpenSshConfig.Host host, Session session )
-        {
-        }
-    }
-
-    private abstract static class PrivateKeySessionFactory extends SimpleSessionFactory
+    private static final class ScmProviderAwareSshdSessionFactory extends SshdSessionFactory
     {
         private final GitScmProviderRepository repo;
+        private final Logger logger;
 
-        GitScmProviderRepository getRepo()
-        {
-            return repo;
-        }
-
-        PrivateKeySessionFactory( GitScmProviderRepository repo )
+        ScmProviderAwareSshdSessionFactory( GitScmProviderRepository repo, Logger logger )
         {
             this.repo = repo;
-        }
-    }
-
-    private static class UnprotectedPrivateKeySessionFactory extends PrivateKeySessionFactory
-    {
-
-        UnprotectedPrivateKeySessionFactory( GitScmProviderRepository repo )
-        {
-            super( repo );
+            this.logger = logger;
         }
 
         @Override
-        protected JSch createDefaultJSch( FS fs ) throws JSchException
-        {
-            JSch defaultJSch = super.createDefaultJSch( fs );
-            defaultJSch.addIdentity( getRepo().getPrivateKey() );
-            return defaultJSch;
-        }
-    }
-
-    private static class ProtectedPrivateKeyFileSessionFactory extends PrivateKeySessionFactory
-    {
-
-        ProtectedPrivateKeyFileSessionFactory( GitScmProviderRepository repo )
+        protected List<Path> getDefaultIdentities( File sshDir )
         {
-            super( repo );
+            if ( !StringUtils.isEmptyOrNull( repo.getPrivateKey() ) )
+            {
+                logger.debug( "using private key: {}", repo.getPrivateKey() );
+                return Collections.singletonList( Paths.get( repo.getPrivateKey() ) );
+            }
+            else 
+            {
+                return super.getDefaultIdentities( sshDir );
+            }
         }
 
         @Override
-        protected JSch createDefaultJSch( FS fs ) throws JSchException
+        protected KeyPasswordProvider createKeyPasswordProvider( CredentialsProvider provider )
         {
-            JSch defaultJSch = super.createDefaultJSch( fs );
-            defaultJSch.addIdentity( getRepo().getPrivateKey(), getRepo().getPassphrase() );
-            return defaultJSch;
+            if ( repo.getPassphrase() != null )
+            {
+                return new IdentityPasswordProvider( provider )
+                {
+                    @Override
+                    public char[] getPassphrase( URIish uri, int attempt ) throws IOException

Review Comment:
   I can't believe that someone has created a class called `URIish`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org