Search in sources :

Example 96 with User

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

the class UserImpl method getFavorites.

@Override
public BlueFavoriteContainer getFavorites() {
    /*
         * Get the user id using authenticated user. User.current() returns authenticated user using security realm and
         * associated IdStrategy to get a consistent id.
         *
         * @see IdStrategy#keyFor(String)
         * @see IdStrategy.CaseInsensitive#keyFor(String)
         *
         */
    User u = User.current();
    String expectedUserId = u != null ? u.getId() : Jenkins.ANONYMOUS.getName();
    if (!user.getId().equals(expectedUserId)) {
        throw new ForbiddenException("This user '" + expectedUserId + "' cannot access resource owned by '" + user.getId() + "'");
    }
    return new FavoriteContainerImpl(this, this);
}
Also used : ForbiddenException(io.jenkins.blueocean.commons.ServiceException.ForbiddenException) BlueUser(io.jenkins.blueocean.rest.model.BlueUser) User(hudson.model.User)

Example 97 with User

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

the class BaseTest method login.

protected User login(String userId, String fullName, String email) throws IOException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User bob = User.get(userId);
    bob.setFullName(fullName);
    bob.addProperty(new Mailer.UserProperty(email));
    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 98 with User

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

the class FavoritesApiTest method deleteUserFavoritesUnauthenticatedTest.

@Test
public void deleteUserFavoritesUnauthenticatedTest() {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    new RequestBuilder(baseUrl).delete("/users/" + user.getId() + "/favorites/").status(403).build(Map.class);
}
Also used : User(hudson.model.User) Test(org.junit.Test)

Example 99 with User

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

the class FavoritesApiTest method deleteUserFavoritesUnauthorizedTest.

@Test
public void deleteUserFavoritesUnauthorizedTest() {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    new RequestBuilder(baseUrl).delete("/users/" + user.getId() + "/favorites/").auth("bob", "bob").status(403).build(Map.class);
}
Also used : User(hudson.model.User) Test(org.junit.Test)

Example 100 with User

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

the class PipelineApiTest method PipelineSecureWithLoggedInUserPermissionTest.

@Test
public void PipelineSecureWithLoggedInUserPermissionTest() throws IOException, UnirestException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    user.setFullName("Alice Cooper");
    MockFolder folder = j.createFolder("folder1");
    Project p = folder.createProject(FreeStyleProject.class, "test1");
    String token = getJwtToken(j.jenkins, "alice", "alice");
    assertNotNull(token);
    Map response = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/folder1/pipelines/test1").jwtToken(token).build(Map.class);
    validatePipeline(p, response);
    Map<String, Boolean> permissions = (Map<String, Boolean>) response.get("permissions");
    assertTrue(permissions.get("create"));
    assertTrue(permissions.get("start"));
    assertTrue(permissions.get("stop"));
    assertTrue(permissions.get("read"));
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) User(hudson.model.User) MockFolder(org.jvnet.hudson.test.MockFolder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) 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