Search in sources :

Example 1 with TopLevelItemDescriptor

use of hudson.model.TopLevelItemDescriptor in project configuration-as-code-plugin by jenkinsci.

the class TopLevelItemConfigurator method configure.

@Override
public TopLevelItem configure(Object c) throws Exception {
    Map config = (Map) c;
    final Jenkins jenkins = Jenkins.getInstance();
    final TopLevelItemDescriptor descriptor = (TopLevelItemDescriptor) jenkins.getDescriptorOrDie(target);
    final String name = (String) config.remove("name");
    final TopLevelItem item = descriptor.newInstance(jenkins, name);
    configure(config, item);
    return item;
}
Also used : Jenkins(jenkins.model.Jenkins) TopLevelItem(hudson.model.TopLevelItem) TopLevelItemDescriptor(hudson.model.TopLevelItemDescriptor) Map(java.util.Map)

Example 2 with TopLevelItemDescriptor

use of hudson.model.TopLevelItemDescriptor in project blueocean-plugin by jenkinsci.

the class AbstractPipelineCreateRequestImpl method create.

@Nonnull
public TopLevelItem create(ModifiableTopLevelItemGroup parent, String name, String descriptorName, Class<? extends TopLevelItemDescriptor> descriptorClass) throws IOException {
    ACL acl = Jenkins.getInstance().getACL();
    Authentication a = Jenkins.getAuthentication();
    if (!acl.hasPermission(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.BadRequestExpception(String.format("Failed to create pipeline: %s, descriptor %s is not found", name, descriptorName));
    }
    ItemGroup p = Jenkins.getInstance();
    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.hasCreatePermission(a, p, descriptor)) {
        throw new ServiceException.ForbiddenException("Missing permission: " + Item.CREATE.group.title + "/" + Item.CREATE.name + Item.CREATE + "/" + descriptor.getDisplayName());
    }
    return parent.createProject(descriptor, name, true);
}
Also used : ItemGroup(hudson.model.ItemGroup) ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) Authentication(org.acegisecurity.Authentication) TopLevelItemDescriptor(hudson.model.TopLevelItemDescriptor) ACL(hudson.security.ACL) Nonnull(javax.annotation.Nonnull)

Example 3 with TopLevelItemDescriptor

use of hudson.model.TopLevelItemDescriptor 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

TopLevelItemDescriptor (hudson.model.TopLevelItemDescriptor)3 ACL (hudson.security.ACL)2 Nonnull (javax.annotation.Nonnull)2 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)2 ItemGroup (hudson.model.ItemGroup)1 TopLevelItem (hudson.model.TopLevelItem)1 AccessControlled (hudson.security.AccessControlled)1 Map (java.util.Map)1 Jenkins (jenkins.model.Jenkins)1 Authentication (org.acegisecurity.Authentication)1 Authentication (org.springframework.security.core.Authentication)1