use of hudson.security.ACL in project selenium_java by sergueik.
the class AuditReportsAuthorizationStrategy method getRootACL.
@Override
public ACL getRootACL() {
return new ACL() {
@Override
public boolean hasPermission(final Authentication auth, final Permission requestedPermission) {
final String requestedUser = auth.getName();
final ACL originalACL = template.getRootACL();
boolean retval = originalACL.hasPermission(auth, requestedPermission);
if (retval) {
if (0 == Permission.ID_COMPARATOR.compare(requestedPermission, AuditReportsAuthorizationStrategy.this.permission)) {
retval = retval && requestedUser.equalsIgnoreCase(AuditReportsAuthorizationStrategy.this.user);
}
}
return retval;
}
};
}
use of hudson.security.ACL in project blueocean-plugin by jenkinsci.
the class ScmResourceImpl method checkPermission.
@Nonnull
private User checkPermission() {
ACL acl;
if (item.getParent() != null && item.getParent() instanceof OrganizationFolder) {
acl = ((OrganizationFolder) item.getParent()).getACL();
} else {
acl = item.getACL();
}
Authentication a = Jenkins.getAuthentication2();
User user = User.get2(a);
if (user == null) {
throw new ServiceException.UnauthorizedException("No logged in user found");
}
if (!acl.hasPermission2(a, Item.CONFIGURE)) {
throw new ServiceException.ForbiddenException(String.format("User %s must have Job configure permission to access content", a.getName()));
}
return user;
}
use of hudson.security.ACL in project blueocean-plugin by jenkinsci.
the class OrganizationFolderTest method testOrganizationFolderFactoryNoPermissionsFolder.
@Test(expected = ServiceException.ForbiddenException.class)
public void testOrganizationFolderFactoryNoPermissionsFolder() throws Exception {
List<OrganizationFolderPipelineImpl.OrganizationFolderFactory> organizationFolderFactoryList = ExtensionList.lookup(OrganizationFolderPipelineImpl.OrganizationFolderFactory.class);
OrganizationFolderFactoryTestImpl organizationFolderFactoryTest = ((ExtensionList<OrganizationFolderPipelineImpl.OrganizationFolderFactory>) organizationFolderFactoryList).get(OrganizationFolderFactoryTestImpl.class);
assertNotNull(organizationFolderFactoryTest);
OrganizationFolderPipelineImpl folderPipeline = organizationFolderFactoryTest.getFolder(orgFolder, new Reachable() {
@Override
public Link getLink() {
return organization.getLink().rel("/pipelines/");
}
}, mockOrganization());
assertNotNull(folderPipeline);
assertNotNull(folderPipeline.getQueue());
assertNotNull(folderPipeline.getQueue().iterator());
// Make sure the user does not have permissions to that folder
PowerMockito.when(orgFolder.getACL()).thenReturn(new ACL() {
@Override
public boolean hasPermission(Authentication arg0, Permission arg1) {
return false;
}
});
ScmResourceImpl scmResource = new ScmResourceImpl(orgFolder, folderPipeline);
StaplerRequest staplerRequest = PowerMockito.mock(StaplerRequest.class);
assertEquals("hello", scmResource.getContent(staplerRequest));
}
use of hudson.security.ACL in project blueocean-plugin by jenkinsci.
the class OrganizationFolderTest method testOrganizationFolderFactory.
@Test
public void testOrganizationFolderFactory() throws Exception {
List<OrganizationFolderPipelineImpl.OrganizationFolderFactory> organizationFolderFactoryList = ExtensionList.lookup(OrganizationFolderPipelineImpl.OrganizationFolderFactory.class);
OrganizationFolderFactoryTestImpl organizationFolderFactoryTest = ((ExtensionList<OrganizationFolderPipelineImpl.OrganizationFolderFactory>) organizationFolderFactoryList).get(OrganizationFolderFactoryTestImpl.class);
assertNotNull(organizationFolderFactoryTest);
OrganizationFolderPipelineImpl folderPipeline = organizationFolderFactoryTest.getFolder(orgFolder, () -> organization.getLink().rel("/pipelines/"), mockOrganization());
assertNotNull(folderPipeline);
assertNotNull(folderPipeline.getQueue());
assertNotNull(folderPipeline.getQueue().iterator());
// Make sure the user does has permissions to that folder
PowerMockito.when(orgFolder.getACL()).thenReturn(new ACL() {
@Override
public boolean hasPermission(Authentication arg0, Permission arg1) {
return true;
}
});
ScmResourceImpl scmResource = new ScmResourceImpl(orgFolder, folderPipeline);
StaplerRequest staplerRequest = PowerMockito.mock(StaplerRequest.class);
assertEquals("hello", scmResource.getContent(staplerRequest));
}
use of hudson.security.ACL in project blueocean-plugin by jenkinsci.
the class AbstractPipelineCreateRequest method checkUserIsAuthenticatedAndHasItemCreatePermission.
protected User checkUserIsAuthenticatedAndHasItemCreatePermission(BlueOrganization organization) {
ModifiableTopLevelItemGroup p = getParent(organization);
User authenticatedUser = User.current();
if (authenticatedUser == null) {
throw new ServiceException.UnauthorizedException("Must be logged in to create a pipeline");
}
Authentication authentication = Jenkins.getAuthentication2();
ACL acl = (p instanceof AccessControlled) ? ((AccessControlled) p).getACL() : Jenkins.get().getACL();
if (!acl.hasPermission2(authentication, Item.CREATE)) {
throw new ServiceException.ForbiddenException(String.format("User %s doesn't have Job create permission", authenticatedUser.getId()));
}
return authenticatedUser;
}
Aggregations