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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations