Search in sources :

Example 11 with ACL

use of hudson.security.ACL in project blueocean-plugin by jenkinsci.

the class AbstractPipelineCreateRequest method createProject.

@Nonnull
protected TopLevelItem createProject(String name, String descriptorName, Class<? extends TopLevelItemDescriptor> descriptorClass, BlueOrganization organization) throws IOException {
    ModifiableTopLevelItemGroup p = getParent(organization);
    final ACL acl = (p instanceof AccessControlled) ? ((AccessControlled) p).getACL() : Jenkins.get().getACL();
    Authentication a = Jenkins.getAuthentication2();
    if (!acl.hasPermission2(a, Item.CREATE)) {
        throw new ServiceException.ForbiddenException(String.format("Failed to create pipeline: %s. User %s doesn't have Job create permission", name, a.getName()));
    }
    TopLevelItemDescriptor descriptor = Items.all().findByName(descriptorName);
    if (descriptor == null || !(descriptorClass.isAssignableFrom(descriptor.getClass()))) {
        throw new ServiceException.BadRequestException(String.format("Failed to create pipeline: %s, descriptor %s is not found", name, descriptorName));
    }
    if (!descriptor.isApplicableIn(p)) {
        throw new ServiceException.ForbiddenException(String.format("Failed to create pipeline: %s. Pipeline can't be created in Jenkins root folder", name));
    }
    if (!acl.hasCreatePermission2(a, p, descriptor)) {
        throw new ServiceException.ForbiddenException("Missing permission: " + Item.CREATE.group.title + "/" + Item.CREATE.name + " " + Item.CREATE + "/" + descriptor.getDisplayName());
    }
    return p.createProject(descriptor, name, true);
}
Also used : AccessControlled(hudson.security.AccessControlled) ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) Authentication(org.springframework.security.core.Authentication) TopLevelItemDescriptor(hudson.model.TopLevelItemDescriptor) ACL(hudson.security.ACL) Nonnull(javax.annotation.Nonnull)

Aggregations

ACL (hudson.security.ACL)11 Authentication (org.acegisecurity.Authentication)8 Permission (hudson.security.Permission)5 User (hudson.model.User)4 Nonnull (javax.annotation.Nonnull)4 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Authentication (org.springframework.security.core.Authentication)3 ExtensionList (hudson.ExtensionList)2 Item (hudson.model.Item)2 TopLevelItemDescriptor (hudson.model.TopLevelItemDescriptor)2 AccessControlled (hudson.security.AccessControlled)2 BlueUserPermission (io.jenkins.blueocean.rest.model.BlueUserPermission)2 OrganizationFolder (jenkins.branch.OrganizationFolder)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 StaplerRequest (org.kohsuke.stapler.StaplerRequest)2 Cause (hudson.model.Cause)1 CauseAction (hudson.model.CauseAction)1 ItemGroup (hudson.model.ItemGroup)1