use of io.jenkins.blueocean.service.embedded.rest.UserImpl in project blueocean-plugin by jenkinsci.
the class ProfileApiTest method testPermissionOfOtherUser.
@Test
public void testPermissionOfOtherUser() throws IOException {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
hudson.model.User alice = User.get("alice");
alice.setFullName("Alice Cooper");
alice.addProperty(new Mailer.UserProperty("alice@jenkins-ci.org"));
hudson.model.User bob = User.get("bob");
bob.setFullName("Bob Cooper");
bob.addProperty(new Mailer.UserProperty("bob@jenkins-ci.org"));
UserDetails d = Jenkins.get().getSecurityRealm().loadUserByUsername(bob.getId());
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(bob.getId(), bob.getId(), d.getAuthorities()));
Assert.assertNull(new UserImpl(IterableUtils.getFirst(OrganizationFactory.getInstance().list(), null), alice).getPermission());
}
use of io.jenkins.blueocean.service.embedded.rest.UserImpl in project blueocean-plugin by jenkinsci.
the class FavoritesStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
User jenkinsUser = User.current();
if (jenkinsUser != null) {
BlueOrganization organization = IterableUtils.getFirst(OrganizationFactory.getInstance().list(), null);
if (organization != null) {
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
// don't need this list when at pipeline pages
if (pipelineFullName != null) {
return null;
}
UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers());
BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();
if (favoritesContainer != null) {
JSONArray favorites = new JSONArray();
// Limit the number of favorites to return to a sane amount
Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT);
while (favoritesIterator.hasNext()) {
Reachable favorite = favoritesIterator.next();
try {
favorites.add(JSONObject.fromObject(Export.toJson(favorite)));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e);
return null;
}
}
return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString());
}
}
}
// Don't preload any data on the page.
return null;
}
Aggregations