use of org.acegisecurity.Authentication in project blueocean-plugin by jenkinsci.
the class GithubPipelineUpdateRequest method update.
@Nonnull
@Override
public BluePipeline update(BluePipeline pipeline) throws IOException {
ACL acl = Jenkins.getInstance().getACL();
Authentication a = Jenkins.getAuthentication();
if (!acl.hasPermission(a, Item.CONFIGURE)) {
throw new ServiceException.ForbiddenException(String.format("Failed to update Git pipeline: %s. User %s doesn't have Job configure permission", pipeline.getName(), a.getName()));
}
User user = User.current();
if (user == null) {
throw new ServiceException.UnauthorizedException("User is not authenticated");
}
Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
if (item instanceof OrganizationFolder) {
OrganizationFolder folder = (OrganizationFolder) item;
GitHubSCMNavigator gitHubSCMNavigator = getNavigator(folder);
if (gitHubSCMNavigator != null) {
folder.getNavigators().replace(gitHubSCMNavigator);
if (repos.size() == 1) {
SCMSourceEvent.fireNow(new GithubPipelineCreateRequest.SCMSourceEventImpl(repos.get(0), item, gitHubSCMNavigator.getApiUri(), gitHubSCMNavigator));
} else {
folder.scheduleBuild(new Cause.UserIdCause());
}
}
}
return pipeline;
}
use of org.acegisecurity.Authentication in project blueocean-plugin by jenkinsci.
the class GitPipelineUpdateRequest method update.
@CheckForNull
@Override
@SuppressWarnings("unchecked")
public BluePipeline update(BluePipeline pipeline) throws IOException {
Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
if (item instanceof MultiBranchProject) {
ACL acl = Jenkins.getInstance().getACL();
Authentication a = Jenkins.getAuthentication();
if (!acl.hasPermission(a, Item.CONFIGURE)) {
throw new ServiceException.ForbiddenException(String.format("Failed to update Git pipeline: %s. User %s doesn't have Job configure permission", pipeline.getName(), a.getName()));
}
MultiBranchProject mbp = (MultiBranchProject) item;
BranchSource branchSource = getGitScmSource(mbp);
if (branchSource != null) {
mbp.getSourcesList().replaceBy(Collections.singleton(branchSource));
mbp.scheduleBuild2(0, new CauseAction(new Cause.UserIdCause()));
}
}
return pipeline;
}
use of org.acegisecurity.Authentication in project blueocean-plugin by jenkinsci.
the class BlueOceanRootAction method getTarget.
@Override
public Object getTarget() {
StaplerRequest request = Stapler.getCurrentRequest();
if (request.getOriginalRestOfPath().startsWith("/rest/")) {
if (enableJWT) {
Authentication tokenAuthentication = JwtAuthenticationToken.create(request);
//create a new context and set it to holder to not clobber existing context
SecurityContext securityContext = new SecurityContextImpl();
securityContext.setAuthentication(tokenAuthentication);
SecurityContextHolder.setContext(securityContext);
//TODO: implement this as filter, see PluginServletFilter to clear the context
} else {
HashCode hashCode = Hashing.sha1().newHasher().putString(Jenkins.getAuthentication().getName(), StandardCharsets.UTF_8).putLong(randomBits).hash();
// Base64 encode to ensure no non-ASCII characters get into the header
String refresherToken = Base64.encode(hashCode.asBytes());
Stapler.getCurrentResponse().setHeader("X-Blueocean-Refresher", refresherToken);
}
} else {
//If user doesn't have overall Jenkins read permission then return 403, which results in classic UI redirecting
// user to login page
Jenkins.getInstance().checkPermission(Jenkins.READ);
}
return app;
}
use of org.acegisecurity.Authentication 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);
}
Aggregations