Search in sources :

Example 1 with UserImpl

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());
}
Also used : UserDetails(org.acegisecurity.userdetails.UserDetails) UserImpl(io.jenkins.blueocean.service.embedded.rest.UserImpl) Mailer(hudson.tasks.Mailer) UsernamePasswordAuthenticationToken(org.acegisecurity.providers.UsernamePasswordAuthenticationToken) User(hudson.model.User) Test(org.junit.Test)

Example 2 with UserImpl

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;
}
Also used : BlueFavoriteContainer(io.jenkins.blueocean.rest.model.BlueFavoriteContainer) BlueFavorite(io.jenkins.blueocean.rest.model.BlueFavorite) User(hudson.model.User) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) UserImpl(io.jenkins.blueocean.service.embedded.rest.UserImpl) JSONArray(net.sf.json.JSONArray) Reachable(io.jenkins.blueocean.rest.Reachable) IOException(java.io.IOException)

Aggregations

User (hudson.model.User)2 UserImpl (io.jenkins.blueocean.service.embedded.rest.UserImpl)2 Mailer (hudson.tasks.Mailer)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 BlueFavorite (io.jenkins.blueocean.rest.model.BlueFavorite)1 BlueFavoriteContainer (io.jenkins.blueocean.rest.model.BlueFavoriteContainer)1 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)1 IOException (java.io.IOException)1 JSONArray (net.sf.json.JSONArray)1 UsernamePasswordAuthenticationToken (org.acegisecurity.providers.UsernamePasswordAuthenticationToken)1 UserDetails (org.acegisecurity.userdetails.UserDetails)1 Test (org.junit.Test)1