Java Code Examples for org.eclipse.jgit.transport.CredentialItem#YesNoType
The following examples show how to use
org.eclipse.jgit.transport.CredentialItem#YesNoType .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitSkipSslValidationCredentialsProviderTest.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Test public void testSupportsSslValidationYesNoTypes() { CredentialItem yesNoType = new CredentialItem.YesNoType( JGitText.get().sslTrustNow); assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as( "GitSkipSslValidationCredentialsProvider should always support the trust now YesNoType item") .isTrue(); yesNoType = new CredentialItem.YesNoType( MessageFormat.format(JGitText.get().sslTrustForRepo, "/a/path.git")); assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as( "GitSkipSslValidationCredentialsProvider should always support the trust repo YesNoType item") .isTrue(); yesNoType = new CredentialItem.YesNoType(JGitText.get().sslTrustAlways); assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as( "GitSkipSslValidationCredentialsProvider should always support the trust always YesNoType item") .isTrue(); yesNoType = new CredentialItem.YesNoType("unrelated"); assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as( "GitSkipSslValidationCredentialsProvider should not support unrelated YesNoType items") .isFalse(); }
Example 2
Source File: GitSkipSslValidationCredentialsProviderTest.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Test public void testGetSslTrustItems() throws URISyntaxException { URIish uri = new URIish("https://example.com/repo.git"); CredentialItem message = new CredentialItem.InformationalMessage( JGitText.get().sslFailureTrustExplanation); CredentialItem.YesNoType trustNow = new CredentialItem.YesNoType( JGitText.get().sslTrustNow); CredentialItem.YesNoType trustAlways = new CredentialItem.YesNoType( JGitText.get().sslTrustAlways); boolean getSuccessful = this.skipSslValidationCredentialsProvider.get(uri, message, trustNow, trustAlways); assertThat(getSuccessful).as( "SkipSSlValidationCredentialsProvider must successfully get the types required for SSL validation skipping") .isTrue(); assertThat(trustNow.getValue()).as( "SkipSSlValidationCredentialsProvider should trust the current repo operation") .isTrue(); assertThat(trustAlways.getValue()) .as("We should not globally skip all SSL validation").isFalse(); }
Example 3
Source File: JGitCredentialsProvider.java From mOrgAnd with GNU General Public License v2.0 | 6 votes |
@Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { for (CredentialItem item : items) { if (item instanceof CredentialItem.Username) { ((CredentialItem.Username) item).setValue(username); } else if (item instanceof CredentialItem.Password) { ((CredentialItem.Password) item).setValue(password.toCharArray()); } else if (item instanceof CredentialItem.StringType) { ((CredentialItem.StringType) item).setValue(password); } else if (item instanceof CredentialItem.InformationalMessage) { throw new UnsupportedCredentialItem(uri, "Not supported"); } else if (item instanceof CredentialItem.YesNoType) { // TODO handle strict host key checking here throw new UnsupportedCredentialItem(uri, "Not supported"); } else { throw new UnsupportedCredentialItem(uri, "Not supported"); } } return true; }
Example 4
Source File: AllowHostsCredentialsProvider.java From Notebook with Apache License 2.0 | 5 votes |
@Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { for(CredentialItem item : items){ if(item instanceof CredentialItem.YesNoType){ ((CredentialItem.YesNoType) item).setValue(true); return true; } } return false; }
Example 5
Source File: AllowHostsCredentialsProvider.java From Notebook with Apache License 2.0 | 5 votes |
@Override public boolean supports(CredentialItem... items) { for(CredentialItem item : items){ if(item instanceof CredentialItem.YesNoType){ return true; } } return false; }
Example 6
Source File: GitSkipSslValidationCredentialsProvider.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Override public boolean supports(CredentialItem... items) { List<CredentialItem> unprocessedItems = new ArrayList<>(); for (CredentialItem item : items) { if (item instanceof CredentialItem.InformationalMessage && item.getPromptText() != null && item.getPromptText() .contains(JGitText.get().sslFailureTrustExplanation)) { continue; } if (item instanceof CredentialItem.YesNoType && item.getPromptText() != null && (item.getPromptText().equals(JGitText.get().sslTrustNow) || item.getPromptText() .startsWith(stripFormattingPlaceholders( JGitText.get().sslTrustForRepo)) || item.getPromptText() .equals(JGitText.get().sslTrustAlways))) { continue; } unprocessedItems.add(item); } return unprocessedItems.isEmpty() || (this.delegate != null && this.delegate .supports(unprocessedItems.toArray(new CredentialItem[0]))); }
Example 7
Source File: GitSkipSslValidationCredentialsProvider.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { List<CredentialItem> unprocessedItems = new ArrayList<>(); for (CredentialItem item : items) { if (item instanceof CredentialItem.YesNoType) { CredentialItem.YesNoType yesNoItem = (CredentialItem.YesNoType) item; String prompt = yesNoItem.getPromptText(); if (prompt == null) { unprocessedItems.add(item); } else if (prompt.equals(JGitText.get().sslTrustNow) || prompt.startsWith( stripFormattingPlaceholders(JGitText.get().sslTrustForRepo))) { yesNoItem.setValue(true); } else if (prompt.equals(JGitText.get().sslTrustAlways)) { yesNoItem.setValue(false); } else { unprocessedItems.add(item); } } else if (!item.getPromptText() .contains(JGitText.get().sslFailureTrustExplanation)) { unprocessedItems.add(item); } } if (unprocessedItems.isEmpty()) { return true; } if (this.delegate != null) { return this.delegate.get(uri, unprocessedItems.toArray(new CredentialItem[0])); } throw new UnsupportedCredentialItem(uri, unprocessedItems.size() + " credential items not supported"); }
Example 8
Source File: GitSkipSslValidationCredentialsProviderTest.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void testGetSslTrustItemsWithLocalRepo() throws URISyntaxException { URIish uri = new URIish("https://example.com/repo.git"); CredentialItem message = new CredentialItem.InformationalMessage( JGitText.get().sslFailureTrustExplanation); CredentialItem.YesNoType trustNow = new CredentialItem.YesNoType( JGitText.get().sslTrustNow); CredentialItem.YesNoType trustForRepo = new CredentialItem.YesNoType( JGitText.get().sslTrustForRepo); CredentialItem.YesNoType trustAlways = new CredentialItem.YesNoType( JGitText.get().sslTrustAlways); boolean getSuccessful = this.skipSslValidationCredentialsProvider.get(uri, message, trustNow, trustForRepo, trustAlways); assertThat(getSuccessful).as( "SkipSSlValidationCredentialsProvider must successfully get the types required for SSL validation skipping") .isTrue(); assertThat(trustNow.getValue()).as( "SkipSSlValidationCredentialsProvider should trust the current repo operation") .isTrue(); assertThat(trustForRepo.getValue()) .as("Future operations on this repository should also be trusted") .isTrue(); assertThat(trustAlways.getValue()) .as("We should not globally skip all SSL validation").isFalse(); }
Example 9
Source File: AwsCodeCommitCredentialsProviderTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void testThrowsUnsupportedCredentialException() throws URISyntaxException { CredentialItem[] goodCredentialItems = makeCredentialItems(); CredentialItem[] badCredentialItems = new CredentialItem[] { goodCredentialItems[0], goodCredentialItems[1], new CredentialItem.YesNoType("OK?") }; try { this.provider.get(new URIish(AWS_REPO), badCredentialItems); fail("Expected UnsupportedCredentialItem exception"); } catch (UnsupportedCredentialItem e) { assertThat(e.getMessage()).isNotNull(); } }