Search in sources :

Example 1 with ForbiddenException

use of io.jenkins.blueocean.commons.ServiceException.ForbiddenException 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)

Aggregations

User (hudson.model.User)1 ForbiddenException (io.jenkins.blueocean.commons.ServiceException.ForbiddenException)1 BlueUser (io.jenkins.blueocean.rest.model.BlueUser)1