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