You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/07/19 12:26:00 UTC
[jira] [Commented] (SCM-994) Add JGit CredentialsProvider based on Plexus Interactivity API
[ https://issues.apache.org/jira/browse/SCM-994?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17568516#comment-17568516 ]
ASF GitHub Bot commented on SCM-994:
------------------------------------
michael-o commented on code in PR #154:
URL: https://github.com/apache/maven-scm/pull/154#discussion_r924430038
##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java:
##########
@@ -54,6 +58,21 @@
public class JGitScmProvider
extends AbstractGitScmProvider
{
+ private final PlexusInteractivityCredentialsProvider credentialsProvider;
+
+ @Inject
+ public JGitScmProvider( Prompter prompter )
+ {
+ credentialsProvider = new PlexusInteractivityCredentialsProvider( prompter );
+ CredentialsProvider.setDefault( credentialsProvider );
+ }
+
+ @Override
+ public void setInteractive( boolean isInteractive )
Review Comment:
`boolean interactive`
##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml:
##########
@@ -44,6 +44,17 @@
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-git-commons</artifactId>
</dependency>
+ <dependency>
+ <artifactId>plexus-interactivity-api</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
Review Comment:
swap groupId and artifactId
##########
maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java:
##########
@@ -71,6 +71,15 @@ ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char del
ScmProviderRepository makeProviderScmRepository( File path )
throws ScmRepositoryException, UnknownRepositoryStructure;
+ /**
+ * Sets the interactive mode.
+ * @param isInteractive either {@code true} in case user may be prompted for information, otherwise {@code false}
+ * @since 2.0.0-M2
+ */
+ default void setInteractive( boolean isInteractive )
Review Comment:
`boolean interactive`
##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/PlexusInteractivityCredentialsProvider.java:
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.Arrays;
+
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.eclipse.jgit.errors.UnsupportedCredentialItem;
+import org.eclipse.jgit.transport.CredentialItem;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+
+/**
+ * {@link CredentialsProvider} leveraging the {@link Prompter} component.
+ *
+ */
+public class PlexusInteractivityCredentialsProvider extends CredentialsProvider
+{
+ private boolean isInteractive;
+ private final Prompter prompter;
+
+ public PlexusInteractivityCredentialsProvider( Prompter prompter )
+ {
+ this.isInteractive = true;
+ this.prompter = prompter;
+ }
+
+ @Override
+ public boolean get( URIish uri, CredentialItem... items ) throws UnsupportedCredentialItem
+ {
+ for ( CredentialItem item : items )
+ {
+ try
+ {
+ if ( item instanceof CredentialItem.YesNoType )
+ {
+ CredentialItem.YesNoType yesNoItem = ( CredentialItem.YesNoType ) item;
+ String value = prompter.prompt( item.getPromptText(), Arrays.asList( "yes", "no" ) );
+ yesNoItem.setValue( value.equals( "yes" ) );
+ }
+ else if ( item instanceof CredentialItem.Password )
+ {
+ CredentialItem.Password passwordItem = ( CredentialItem.Password ) item;
+ String password = prompter.promptForPassword( passwordItem.getPromptText() );
+ passwordItem.setValue( password.toCharArray() );
+ }
+ else if ( item instanceof CredentialItem.Username )
+ {
+ CredentialItem.Username usernameItem = ( CredentialItem.Username ) item;
+ String username = prompter.prompt( usernameItem.getPromptText() );
+ usernameItem.setValue( username );
+ }
+ else if ( item instanceof CredentialItem.InformationalMessage )
+ {
+ prompter.showMessage( item.getPromptText() );
+ }
+ else
+ {
+ throw new UnsupportedCredentialItem( uri, item.getClass().toString() );
+ }
+ }
+ catch ( PrompterException e )
+ {
+ throw new IllegalStateException( "Can not prompt user " + e.getMessage() , e );
+ }
+ }
+ return true;
+ }
+
+ public void setInteractive( boolean isInteractive )
Review Comment:
same here
##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/PlexusInteractivityCredentialsProvider.java:
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.Arrays;
+
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.eclipse.jgit.errors.UnsupportedCredentialItem;
+import org.eclipse.jgit.transport.CredentialItem;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+
+/**
+ * {@link CredentialsProvider} leveraging the {@link Prompter} component.
+ *
+ */
+public class PlexusInteractivityCredentialsProvider extends CredentialsProvider
+{
+ private boolean isInteractive;
Review Comment:
same here
##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/PlexusInteractivityCredentialsProvider.java:
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.Arrays;
+
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.eclipse.jgit.errors.UnsupportedCredentialItem;
+import org.eclipse.jgit.transport.CredentialItem;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+
+/**
+ * {@link CredentialsProvider} leveraging the {@link Prompter} component.
+ *
+ */
+public class PlexusInteractivityCredentialsProvider extends CredentialsProvider
+{
+ private boolean isInteractive;
+ private final Prompter prompter;
+
+ public PlexusInteractivityCredentialsProvider( Prompter prompter )
+ {
+ this.isInteractive = true;
+ this.prompter = prompter;
+ }
+
+ @Override
+ public boolean get( URIish uri, CredentialItem... items ) throws UnsupportedCredentialItem
+ {
+ for ( CredentialItem item : items )
+ {
+ try
+ {
+ if ( item instanceof CredentialItem.YesNoType )
+ {
+ CredentialItem.YesNoType yesNoItem = ( CredentialItem.YesNoType ) item;
+ String value = prompter.prompt( item.getPromptText(), Arrays.asList( "yes", "no" ) );
+ yesNoItem.setValue( value.equals( "yes" ) );
+ }
+ else if ( item instanceof CredentialItem.Password )
+ {
+ CredentialItem.Password passwordItem = ( CredentialItem.Password ) item;
+ String password = prompter.promptForPassword( passwordItem.getPromptText() );
+ passwordItem.setValue( password.toCharArray() );
+ }
+ else if ( item instanceof CredentialItem.Username )
+ {
+ CredentialItem.Username usernameItem = ( CredentialItem.Username ) item;
+ String username = prompter.prompt( usernameItem.getPromptText() );
+ usernameItem.setValue( username );
+ }
+ else if ( item instanceof CredentialItem.InformationalMessage )
+ {
+ prompter.showMessage( item.getPromptText() );
+ }
+ else
+ {
+ throw new UnsupportedCredentialItem( uri, item.getClass().toString() );
+ }
+ }
+ catch ( PrompterException e )
Review Comment:
This cascade ignores the `interactive` flag.
> Add JGit CredentialsProvider based on Plexus Interactivity API
> --------------------------------------------------------------
>
> Key: SCM-994
> URL: https://issues.apache.org/jira/browse/SCM-994
> Project: Maven SCM
> Issue Type: Improvement
> Components: maven-scm-provider-jgit
> Reporter: Konrad Windszus
> Priority: Major
>
> Currently the JGit provider does not provide interactive communication means, e.g. for asking for a password or adding a new server to the known hosts. There should be an implementation for https://javadoc.io/static/org.eclipse.jgit/org.eclipse.jgit/5.13.1.202206130422-r/org/eclipse/jgit/transport/CredentialsProvider.html backed by Plexus's Prompter component (https://codehaus-plexus.github.io/plexus-interactivity/plexus-interactivity-api/apidocs/org/codehaus/plexus/components/interactivity/Prompter.html).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)