com.cloudbees.plugins.credentials.domains.SchemeRequirement Java Examples

The following examples show how to use com.cloudbees.plugins.credentials.domains.SchemeRequirement. 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: GitURIRequirementsBuilder.java    From git-client-plugin with MIT License 5 votes vote down vote up
/**
 * Removes any scheme requirements.
 *
 * @return {@code this}.
 */
@NonNull
public GitURIRequirementsBuilder withoutScheme() {
    for (Iterator<DomainRequirement> iterator = requirements.iterator(); iterator.hasNext(); ) {
        DomainRequirement r = iterator.next();
        if (r instanceof SchemeRequirement) {
            iterator.remove();
        }
    }
    return this;
}
 
Example #2
Source File: GitURIRequirementsBuilder.java    From git-client-plugin with MIT License 5 votes vote down vote up
/**
 * Replace any scheme requirements with the supplied scheme.
 *
 * @param scheme the scheme to use as a requirement
 * @return {@code this}.
 */
@NonNull
public GitURIRequirementsBuilder withScheme(@CheckForNull String scheme) {
    withoutScheme();
    if (scheme != null) {
        requirements.add(new SchemeRequirement(scheme));
    }
    return this;
}
 
Example #3
Source File: BlueOceanCredentialsProviderTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
@Issue("JENKINS-53188")
public void getCredentialsWhenUserExistedButNotAccessible() {
    PowerMockito.mockStatic(Jenkins.class);
    PowerMockito.when(Jenkins.get()).thenReturn(jenkins);
    PowerMockito.when(Jenkins.getInstance()).thenReturn(jenkins);
    PowerMockito.when(Jenkins.getActiveInstance()).thenReturn(jenkins);
    when(jenkins.getSecurityRealm()).thenReturn(SecurityRealm.NO_AUTHENTICATION);

    PowerMockito.mockStatic(User.class);
    // Make sure we return a user, cause it did once exist
    PowerMockito.when(User.get(anyString(), anyBoolean(), any())).thenReturn(user);

    Domain domain = BlueOceanCredentialsProvider.createDomain("api.github.com");
    BlueOceanCredentialsProvider blueOceanCredentialsProvider = new BlueOceanCredentialsProvider();
    BlueOceanCredentialsProvider.FolderPropertyImpl prop = new BlueOceanCredentialsProvider.FolderPropertyImpl(
        "halkeye",
        "halkeye",
        domain
    );
    when(folder.getProperties()).thenReturn(describableList);
    when(describableList.get(BlueOceanCredentialsProvider.FolderPropertyImpl.class)).thenReturn(prop);

    // Should be empty when trying to impersonate and grab credentials though
    List<StandardUsernameCredentials> credentials = blueOceanCredentialsProvider.getCredentials(
        StandardUsernameCredentials.class,
        (ItemGroup) folder,
        ACL.SYSTEM,
        new ArrayList<DomainRequirement>(Arrays.asList(
            new SchemeRequirement("https"),
            new HostnameRequirement("api.github.com"),
            new PathRequirement("/")
        ))
    );
    assertEquals(Collections.emptyList(), credentials);

    List<Credentials> storeCredentials = prop.getStore().getCredentials(domain);
    assertEquals(Collections.emptyList(), storeCredentials);


}