hansva commented on code in PR #9571:
URL: https://github.com/apache/hop/pull/9571#discussion_r4614975146
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -128,6 +128,19 @@ public class UIGit extends VCS {
CONST_AUTHENTICATION_IS_REQUIRED_BUT_NO_CREDENTIALS_PROVIDER_HAS_BEEN_REGISTERED
=
"Authentication is required but no CredentialsProvider has been
registered";
public static final String CONST_NOT_AUTHORIZED = "not authorized";
+
+ /**
+ * The end of what JGit reports for an HTTP 403. Some servers answer 403
rather than 401 to
+ * credentials they refuse, GitLab after a few failed attempts for example.
+ */
+ public static final String CONST_NOT_PERMITTED = " not permitted on ";
Review Comment:
**Not every 403 means the credentials were refused.** I see the GitLab case
in the javadoc, but a 403 is also what valid credentials get when they lack the
permission: a read-only user, or a GitHub token without push scope. With this
change those good credentials are forgotten and the user is asked again with no
error. Every correct password gets the same 403, so the user is stuck in a
prompt loop until they cancel, the real cause (no write access) is never shown,
and fetch/pull lose their working credentials too. Before this PR the 403 came
up as a `git push` error. Could a 403 show the server's message (and maybe
offer to re-enter credentials) instead of being treated the same as a 401?
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -1179,11 +1177,8 @@ private boolean push(String remote, List<RefSpec>
refSpecs, boolean reportSucces
Iterable<PushResult> resultIterable = cmd.call();
return processPushResult(resultIterable, reportSuccess);
} catch (TransportException e) {
- if (e.getMessage()
- .contains(
-
CONST_AUTHENTICATION_IS_REQUIRED_BUT_NO_CREDENTIALS_PROVIDER_HAS_BEEN_REGISTERED)
- || e.getMessage()
- .contains(CONST_NOT_AUTHORIZED)) { // when the cached credential
does not work
+ if (isAuthenticationFailure(e)) {
+ forgetCredentials();
Review Comment:
**Push handles a refused password differently from fetch and pull.** Two
issues here:
1. Fetch and pull call `showAuthenticationError(e)`, push doesn't. A user
whose password was refused just sees the same dialog reopen with no
explanation, and if they cancel, `push` returns `false` without any message at
all.
2. Push only sends `credentialsProvider` when the remote URL is http(s) (see
above), but it forgets the credentials on any auth-style failure. On an SSH or
other remote, this clears the HTTPS credentials that fetch/pull use, and the
new password from the prompt is never sent by push either, so the prompt can't
help. Only forget and prompt when credentials were actually sent.
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -845,20 +858,13 @@ public boolean fetch(boolean promptForCredentials) throws
HopException {
try {
git.fetch().setCredentialsProvider(credentialsProvider).setCheckFetchedObjects(true).call();
} catch (TransportException e) {
- if (e.getMessage()
- .contains(
-
CONST_AUTHENTICATION_IS_REQUIRED_BUT_NO_CREDENTIALS_PROVIDER_HAS_BEEN_REGISTERED)
- || e.getMessage()
- .contains(CONST_NOT_AUTHORIZED)) { // when the cached credential
does not work
+ if (isAuthenticationFailure(e)) {
+ boolean refused = forgetCredentials();
Review Comment:
**The background fetch can clear credentials the user just entered.** The
automatic fetch runs `fetch(false)` on the `TimerTask` thread, and it now calls
`forgetCredentials()`, which writes the shared, non-volatile
`credentialsProvider` field. The UI thread reads and writes that same field
without synchronization. If the user has just entered a new, good password in a
push/pull prompt and the timer's fetch then gets its 401/403 with the old
credentials, the new password is cleared, and the next operation prompts again.
A short-lived 401/403 seen only by the background fetch (proxy, rate limit)
also clears the credentials, with only a log line. I'd suggest not forgetting
credentials from the non-interactive fetch at all, or only clearing them if
they are still the ones that were refused (compare-and-set), and making the
field volatile or guarded.
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -1957,6 +1950,43 @@ public void setCredential(String username, String
password) {
credentialsProvider = new UsernamePasswordCredentialsProvider(username,
password);
}
+ /**
+ * Whether a transport failure is the remote asking for credentials or
refusing the ones it got.
+ *
+ * <p>A 401 without a challenge only counts when credentials were sent.
Without credentials it is
+ * a server JGit can't authenticate to, and asking for a username and
password would not help.
+ */
+ boolean isAuthenticationFailure(TransportException e) {
Review Comment:
**Clone still has the #9534 bug.** `cloneRepo` wasn't changed: it still uses
the old inline message check instead of `isAuthenticationFailure()`, and never
forgets refused credentials. When `this.credentialsProvider` holds credentials
the server refused earlier, `provider` is non-null, so `provider == null &&
promptUsernamePassword()` is false, the user is never prompted, and every later
clone resends the same refused credentials until Hop restarts. The new 403 and
"authentication not supported" cases aren't matched there either. Please route
clone through the same `isAuthenticationFailure` / `forgetCredentials` / prompt
logic.
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -1957,6 +1950,43 @@ public void setCredential(String username, String
password) {
credentialsProvider = new UsernamePasswordCredentialsProvider(username,
password);
}
+ /**
+ * Whether a transport failure is the remote asking for credentials or
refusing the ones it got.
+ *
+ * <p>A 401 without a challenge only counts when credentials were sent.
Without credentials it is
+ * a server JGit can't authenticate to, and asking for a username and
password would not help.
+ */
+ boolean isAuthenticationFailure(TransportException e) {
Review Comment:
**Matching JGit's English messages is fragile.** This adds two more
substrings (` not permitted on `, `authentication not supported`). If a JGit
upgrade or a localized `JGitText` changes the wording, refused credentials
silently stop being detected and #9534 comes back without any error. A sturdier
option: wrap the `CredentialsProvider` so it records whether JGit asked it for
credentials, and treat a `TransportException` after that as a refusal. That
covers 401, 403 and no-challenge cases without depending on the message text.
Not necessarily for this PR, but worth considering.
##########
ui/src/main/java/org/apache/hop/ui/core/dialog/EnterUsernamePasswordDialog.java:
##########
@@ -107,22 +108,20 @@ public String[] open() {
wlPassword.setLayoutData(fdlPassword);
wPassword = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER |
SWT.PASSWORD);
PropsUi.setLook(wPassword);
- lastControl = wPassword;
FormData fdPassword = new FormData();
- fdPassword.left = new FormAttachment(wlPassword, 0);
+ fdPassword.left = new FormAttachment(wlPassword, margin);
fdPassword.top = new FormAttachment(wlUsername, margin * 2);
- fdPassword.right = new FormAttachment(100, -margin);
+ fdPassword.right = new FormAttachment(100, 0);
wPassword.setLayoutData(fdPassword);
// Some buttons
- wOk = new Button(shell, SWT.PUSH);
+ Button wOk = new Button(shell, SWT.PUSH);
wOk.setText(BaseMessages.getString(PKG, "System.Button.OK"));
Button wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
- BaseTransformDialog.positionBottomButtons(
- shell, new Button[] {wOk, wCancel}, margin, lastControl);
+ BaseTransformDialog.positionBottomButtons(shell, new Button[] {wOk,
wCancel}, margin, null);
Review Comment:
**OK/Cancel are no longer kept below the password field.** With `null` as
the last control, `positionBottomButtons` attaches the buttons to the bottom of
the shell instead of below `wPassword`. Nothing keeps them under the password
row anymore, and the shell's computed height no longer includes the gap. With
large fonts or HiDPI scaling, once the 650x250 minimum doesn't cover the
content, the buttons can overlap the password field. Was this change needed for
the fix? If not, I'd keep `wPassword` as the last control.
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -282,7 +295,7 @@ public String getRemote() {
try {
StoredConfig config = git.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config,
Constants.DEFAULT_REMOTE_NAME);
- return remoteConfig.getURIs().iterator().next().toString();
+ return remoteConfig.getURIs().getFirst().toString();
Review Comment:
**Unrelated refactors in a bug fix.** This and other changes (`getFirst()`,
switch expressions, string concatenation clean-ups, comment edits) are
unrelated to #9534. They make the credentials fix harder to review and to
backport. Could they go in a separate PR?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]