Search in sources :

Example 61 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class PipelineBaseTest method login.

protected User login() throws IOException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User bob = j.jenkins.getUser("bob");
    bob.setFullName("Bob Smith");
    bob.addProperty(new Mailer.UserProperty("bob@jenkins-ci.org"));
    UserDetails d = Jenkins.getInstance().getSecurityRealm().loadUserByUsername(bob.getId());
    SecurityContextHolder.getContext().setAuthentication(new PrincipalAcegiUserToken(bob.getId(), bob.getId(), bob.getId(), d.getAuthorities(), bob.getId()));
    return bob;
}
Also used : UserDetails(org.acegisecurity.userdetails.UserDetails) Mailer(hudson.tasks.Mailer) User(hudson.model.User) PrincipalAcegiUserToken(org.acegisecurity.adapters.PrincipalAcegiUserToken)

Example 62 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class UserImpl method getEmail.

@Override
public String getEmail() {
    String name = Jenkins.getAuthentication().getName();
    if (isAnonymous(name)) {
        return null;
    } else {
        User user = User.get(name, false, Collections.EMPTY_MAP);
        if (user == null) {
            return null;
        }
        if (!user.hasPermission(Jenkins.ADMINISTER))
            return null;
    }
    Mailer.UserProperty p = user.getProperty(Mailer.UserProperty.class);
    return p != null ? p.getAddress() : null;
}
Also used : BlueUser(io.jenkins.blueocean.rest.model.BlueUser) User(hudson.model.User) Mailer(hudson.tasks.Mailer)

Example 63 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnUpdate2.

@Test
public void shouldGetForbiddenForBadCredentialIdOnUpdate2() throws IOException, UnirestException {
    User user = login();
    String mbp = createMbp(user);
    SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
    CredentialsStore systemStore = system.getStore(j.getInstance());
    systemStore.addDomain(new Domain("domain1", null, null));
    Map<String, Object> resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("password", "abcd").put("stapler-class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "joe desc").put("$class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("username", "joe").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    put("/organizations/jenkins/pipelines/" + mbp + "/", ImmutableMap.of("name", mbp, "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineUpdateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
Also used : User(hudson.model.User) SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) CredentialsStore(com.cloudbees.plugins.credentials.CredentialsStore) SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) CredentialsProvider(com.cloudbees.plugins.credentials.CredentialsProvider) Domain(com.cloudbees.plugins.credentials.domains.Domain) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 64 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetBadRequestForBadGitUriOnUpdate.

@Test
public void shouldGetBadRequestForBadGitUriOnUpdate() throws IOException, UnirestException {
    User user = login();
    String mbp = createMbp(user);
    new RequestBuilder(baseUrl).status(400).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).put("/organizations/jenkins/pipelines/" + mbp + "/").data(ImmutableMap.of("name", mbp, "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineUpdateRequest", "scmConfig", ImmutableMap.of("uri", "/sdsd/sdsd/sdsd"))).build(Map.class);
}
Also used : User(hudson.model.User) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 65 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnUpdate1.

@Test
public void shouldGetForbiddenForBadCredentialIdOnUpdate1() throws IOException, UnirestException {
    User user = login();
    String mbp = createMbp(user);
    SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
    CredentialsStore systemStore = system.getStore(j.getInstance());
    systemStore.addDomain(new Domain("domain1", null, null));
    Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("privateKeySource", ImmutableMap.of("privateKey", "abcabc1212", "stapler-class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource")).put("passphrase", "ssh2").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "ssh2 desc").put("$class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey").put("username", "ssh2").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    put("/organizations/jenkins/pipelines/" + mbp + "/", ImmutableMap.of("name", mbp, "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineUpdateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
Also used : User(hudson.model.User) SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) CredentialsStore(com.cloudbees.plugins.credentials.CredentialsStore) SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) CredentialsProvider(com.cloudbees.plugins.credentials.CredentialsProvider) Domain(com.cloudbees.plugins.credentials.domains.Domain) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

User (hudson.model.User)105 Test (org.junit.Test)71 Map (java.util.Map)42 ImmutableMap (com.google.common.collect.ImmutableMap)38 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)26 Mailer (hudson.tasks.Mailer)24 ServiceException (io.jenkins.blueocean.commons.ServiceException)21 StaplerRequest (org.kohsuke.stapler.StaplerRequest)14 MultiBranchProject (jenkins.branch.MultiBranchProject)13 List (java.util.List)12 JSONObject (net.sf.json.JSONObject)12 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)8 IOException (java.io.IOException)8 Domain (com.cloudbees.plugins.credentials.domains.Domain)7 BlueOceanDomainRequirement (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement)7 Authentication (org.acegisecurity.Authentication)7 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)6 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)6 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6