当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationTokens类代码示例

本文整理汇总了Java中jenkins.authentication.tokens.api.AuthenticationTokens的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationTokens类的具体用法?Java AuthenticationTokens怎么用?Java AuthenticationTokens使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationTokens类属于jenkins.authentication.tokens.api包,在下文中一共展示了AuthenticationTokens类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFillCredentialsIdItems

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
/**
 * Stapler form completion.
 *
 * @param serverUrl the server URL.
 * @return the available credentials.
 */
@Restricted(NoExternalUse.class) // stapler
@SuppressWarnings("unused")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) {
    Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
    StandardListBoxModel result = new StandardListBoxModel();
    serverUrl = GiteaServers.normalizeServerUrl(serverUrl);
    result.includeMatchingAs(
            ACL.SYSTEM,
            Jenkins.getActiveInstance(),
            StandardCredentials.class,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            AuthenticationTokens.matcher(GiteaAuth.class)
    );
    return result;
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:22,代码来源:GiteaServer.java

示例2: getToken

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
/**
 * Plugins that want to refer to a {@link IdCredentials} should do so via ID string,
 * and use this method to resolve it and convert to {@link DockerRegistryToken}.
 *
 * @param context
 *       If you are a build step trying to access DockerHub in the context of a build/job,
 *       specify that job. Otherwise null. If you are scoped to something else, you might
 *       have to interact with {@link CredentialsProvider} directly.
 */
public @CheckForNull
DockerRegistryToken getToken(Item context) {
    if (credentialsId == null) {
        return null;
    }

    // as a build step, your access to credentials are constrained by what the build
    // can access, hence Jenkins.getAuthentication()

    List<DomainRequirement> requirements = Collections.emptyList();
    try {
        requirements = Collections.<DomainRequirement>singletonList(new HostnameRequirement(getEffectiveUrl().getHost()));
    } catch (IOException e) {
        // shrug off this error and move on. We are matching with ID anyway.
    }

    // look for subtypes that know how to create a token, such as Google Container Registry
    return AuthenticationTokens.convert(DockerRegistryToken.class, firstOrNull(CredentialsProvider.lookupCredentials(
            IdCredentials.class, context, Jenkins.getAuthentication(),requirements),
            allOf(AuthenticationTokens.matcher(DockerRegistryToken.class), withId(credentialsId))));
}
 
开发者ID:jenkinsci,项目名称:docker-commons-plugin,代码行数:31,代码来源:DockerRegistryEndpoint.java

示例3: doFillCredentialsIdItems

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item) {
    if (item == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
        item != null && !item.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel();
    }
    // TODO may also need to specify a specific authentication and domain requirements
    return new StandardListBoxModel()
            .withEmptySelection()
            .withMatching(AuthenticationTokens.matcher(DockerRegistryToken.class),
                    CredentialsProvider.lookupCredentials(
                            StandardCredentials.class,
                            item,
                            null,
                            Collections.<DomainRequirement>emptyList()
                    )
            );
}
 
开发者ID:jenkinsci,项目名称:docker-commons-plugin,代码行数:18,代码来源:DockerRegistryEndpoint.java

示例4: gitea

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
private Gitea gitea(SCMSourceOwner owner) throws AbortException {
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        throw new AbortException("Unknown server: " + serverUrl);
    }
    StandardCredentials credentials = credentials(owner);
    CredentialsProvider.track(owner, credentials);
    return Gitea.server(serverUrl)
            .as(AuthenticationTokens.convert(GiteaAuth.class, credentials));
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:11,代码来源:GiteaSCMNavigator.java

示例5: credentials

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
public StandardCredentials credentials(SCMSourceOwner owner) {
    return CredentialsMatchers.firstOrNull(
            CredentialsProvider.lookupCredentials(
                    StandardCredentials.class,
                    owner,
                    Jenkins.getAuthentication(),
                    URIRequirementBuilder.fromUri(serverUrl).build()
            ),
            CredentialsMatchers.allOf(
                    AuthenticationTokens.matcher(GiteaAuth.class),
                    CredentialsMatchers.withId(credentialsId)
            )
    );
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:15,代码来源:GiteaSCMNavigator.java

示例6: doFillCredentialsIdItems

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
                                             @QueryParameter String serverUrl,
                                             @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
            context instanceof Queue.Task ?
                    Tasks.getDefaultAuthenticationOf((Queue.Task) context)
                    : ACL.SYSTEM,
            context,
            StandardCredentials.class,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            AuthenticationTokens.matcher(GiteaAuth.class)
    );
    return result;
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:31,代码来源:GiteaSCMNavigator.java

示例7: doCheckCredentialsId

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
public FormValidation doCheckCredentialsId(@AncestorInPath SCMSourceOwner context,
                                           @QueryParameter String serverUrl,
                                           @QueryParameter String value)
        throws IOException, InterruptedException {
    if (context == null) {
        if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) {
            return FormValidation.ok();
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            return FormValidation.ok();
        }
    }
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        return FormValidation.ok();
    }
    if (StringUtils.isBlank(value)) {
        return FormValidation.ok();
    }
    if (CredentialsProvider.listCredentials(
            StandardCredentials.class,
            context,
            context instanceof Queue.Task ?
                    Tasks.getDefaultAuthenticationOf((Queue.Task) context)
                    : ACL.SYSTEM,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            CredentialsMatchers.allOf(
                    CredentialsMatchers.withId(value),
                    AuthenticationTokens.matcher(GiteaAuth.class)

            )).isEmpty()) {
        return FormValidation.error(Messages.GiteaSCMNavigator_selectedCredentialsMissing());
    }
    return FormValidation.ok();
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:38,代码来源:GiteaSCMNavigator.java

示例8: gitea

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
Gitea gitea() throws AbortException {
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        throw new AbortException("Unknown server: " + serverUrl);
    }
    StandardCredentials credentials = credentials();
    SCMSourceOwner owner = getOwner();
    if (owner != null) {
        CredentialsProvider.track(owner, credentials);
    }
    return Gitea.server(serverUrl)
            .as(AuthenticationTokens.convert(GiteaAuth.class, credentials));
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:14,代码来源:GiteaSCMSource.java

示例9: credentials

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
public StandardCredentials credentials() {
    return CredentialsMatchers.firstOrNull(
            CredentialsProvider.lookupCredentials(
                    StandardCredentials.class,
                    getOwner(),
                    Jenkins.getAuthentication(),
                    URIRequirementBuilder.fromUri(serverUrl).build()
            ),
            CredentialsMatchers.allOf(
                    AuthenticationTokens.matcher(GiteaAuth.class),
                    CredentialsMatchers.withId(credentialsId)
            )
    );
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:15,代码来源:GiteaSCMSource.java

示例10: doCheckCredentialsId

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
public FormValidation doCheckCredentialsId(@AncestorInPath SCMSourceOwner context,
                                           @QueryParameter String serverUrl,
                                           @QueryParameter String value)
        throws IOException, InterruptedException{
    if (context == null) {
        if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) {
            return FormValidation.ok();
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            return FormValidation.ok();
        }
    }
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        return FormValidation.ok();
    }
    if (StringUtils.isBlank(value)) {
        return FormValidation.ok();
    }
    if (CredentialsProvider.listCredentials(
            StandardCredentials.class,
            context,
            context instanceof Queue.Task ?
                    Tasks.getDefaultAuthenticationOf((Queue.Task) context)
                    : ACL.SYSTEM,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            CredentialsMatchers.allOf(
                    CredentialsMatchers.withId(value),
                    AuthenticationTokens.matcher(GiteaAuth.class)

            )).isEmpty()) {
        return FormValidation.error(Messages.GiteaSCMSource_selectedCredentialsMissing());
    }
    return FormValidation.ok();
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:38,代码来源:GiteaSCMSource.java

示例11: credentials

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
/**
 * Looks up the {@link StandardCredentials} to use for auto-management of hooks.
 *
 * @return the credentials or {@code null}.
 */
@CheckForNull
public StandardCredentials credentials() {
    return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull(
            CredentialsProvider.lookupCredentials(
                    StandardCredentials.class,
                    Jenkins.getActiveInstance(),
                    ACL.SYSTEM,
                    URIRequirementBuilder.fromUri(serverUrl).build()
            ),
            CredentialsMatchers.allOf(
                    AuthenticationTokens.matcher(GiteaAuth.class),
                    CredentialsMatchers.withId(credentialsId)
            )
    );
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:21,代码来源:GiteaServer.java

示例12: given__tokenCredential__when__convert__then__tokenAuth

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
@Test
public void given__tokenCredential__when__convert__then__tokenAuth() throws Exception {
    // we use a mock to ensure that java.lang.reflect.Proxy implementations of the credential interface work
    PersonalAccessToken credential = Mockito.mock(PersonalAccessToken.class);
    Mockito.when(credential.getToken()).thenReturn(Secret.fromString("b5bc10f13665362bd61de931c731e3c74187acc4"));
    GiteaAuth auth = AuthenticationTokens.convert(GiteaAuth.class, credential);
    assertThat(auth, instanceOf(GiteaAuthToken.class));
    assertThat(((GiteaAuthToken)auth).getToken(), is("b5bc10f13665362bd61de931c731e3c74187acc4"));
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:10,代码来源:GiteaAuthSourceTest.java

示例13: given__userPassCredential__when__convert__then__tokenAuth

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
@Test
public void given__userPassCredential__when__convert__then__tokenAuth() throws Exception {
    // we use a mock to ensure that java.lang.reflect.Proxy implementations of the credential interface work
    UsernamePasswordCredentials credential = Mockito.mock(UsernamePasswordCredentials.class);
    Mockito.when(credential.getUsername()).thenReturn("bob");
    Mockito.when(credential.getPassword()).thenReturn(Secret.fromString("secret"));
    GiteaAuth auth = AuthenticationTokens.convert(GiteaAuth.class, credential);
    assertThat(auth, instanceOf(GiteaAuthUser.class));
    assertThat(((GiteaAuthUser)auth).getUsername(), is("bob"));
    assertThat(((GiteaAuthUser)auth).getPassword(), is("secret"));
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:12,代码来源:GiteaAuthSourceTest.java

示例14: doFillCredentialsIdItems

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String uri) {
    if (item == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
        item != null && !item.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel();
    }
    List<DomainRequirement> domainRequirements = URIRequirementBuilder.fromUri(uri).build();
    domainRequirements.add(new DockerServerDomainRequirement());
    return new StandardListBoxModel()
            .withEmptySelection()
            .withMatching(
                    AuthenticationTokens.matcher(KeyMaterialFactory.class),
                    CredentialsProvider
                            .lookupCredentials(BASE_CREDENTIAL_TYPE, item, null, domainRequirements)
            );
}
 
开发者ID:jenkinsci,项目名称:docker-commons-plugin,代码行数:16,代码来源:DockerServerEndpoint.java

示例15: getAuthConfig

import jenkins.authentication.tokens.api.AuthenticationTokens; //导入依赖的package包/类
@Restricted(NoExternalUse.class)
public static AuthConfig getAuthConfig(DockerRegistryEndpoint registry, ItemGroup context) throws IOException {
    AuthConfig auth = new AuthConfig();

    // we can't use DockerRegistryEndpoint#getToken as this one do check domainRequirement based on registry URL
    // but in some context (typically, passing registry auth for `docker build`) we just can't guess this one.

    Credentials c = firstOrNull(CredentialsProvider.lookupCredentials(
            IdCredentials.class, context, ACL.SYSTEM, Collections.EMPTY_LIST),
            withId(registry.getCredentialsId()));

    if (c == null) {
        throw new IllegalArgumentException("Invalid Credential ID " + registry.getCredentialsId());
    }

    final DockerRegistryToken t = AuthenticationTokens.convert(DockerRegistryToken.class, c);
    final String token = t.getToken();
    // What docker-commons claim to be a "token" is actually configuration storage
    // see https://github.com/docker/docker-ce/blob/v17.09.0-ce/components/cli/cli/config/configfile/file.go#L214
    // i.e base64 encoded username : password
    final String decode = new String(Base64.decodeBase64(token));
    int i = decode.indexOf(':');
    if (i > 0) {
        String username = decode.substring(0, i);
        auth.withUsername(username);
    }
    auth.withPassword(decode.substring(i+1));
    if (registry.getUrl() != null) {
        auth.withRegistryAddress(registry.getUrl());
    }
    return auth;
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:33,代码来源:DockerCloud.java


注:本文中的jenkins.authentication.tokens.api.AuthenticationTokens类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。