Java Code Examples for jenkins.model.Jenkins#setSecurityRealm()
The following examples show how to use
jenkins.model.Jenkins#setSecurityRealm() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FolderRoleBenchmark.java From folder-auth-plugin with MIT License | 4 votes |
@Override public void setup() throws Exception { Jenkins jenkins = getJenkins(); jenkins.setSecurityRealm(new JenkinsRule().createDummySecurityRealm()); Set<GlobalRole> globalRoles = ImmutableSet.of(( new GlobalRole("ADMIN", wrapPermissions(Jenkins.ADMINISTER), Collections.singleton("admin"))), new GlobalRole("read", wrapPermissions(Jenkins.READ), Collections.singleton("authenticated")) ); Set<FolderRole> folderRoles = new HashSet<>(); Random random = new Random(100L); // create the folders for (int i = 0; i < 10; i++) { String topFolderName = "TopFolder" + i; Folder folder = jenkins.createProject(Folder.class, topFolderName); Set<String> users = new HashSet<>(); for (int k = 0; k < random.nextInt(5); k++) { users.add("user" + random.nextInt(100)); } FolderRole userRole = new FolderRole(topFolderName, wrapPermissions(Item.READ, Item.DISCOVER), Collections.singleton(topFolderName), users); folderRoles.add(userRole); for (int j = 0; j < 5; j++) { Folder bottom = folder.createProject(Folder.class, "BottomFolder" + j); Set<String> maintainers = new HashSet<>(2); maintainers.add("user" + random.nextInt(100)); maintainers.add("user" + random.nextInt(100)); FolderRole maintainerRole = new FolderRole(bottom.getFullName(), wrapPermissions(Item.READ, Item.DISCOVER, Item.CREATE), Collections.singleton(topFolderName), maintainers); Set<String> admin = Collections.singleton("user" + random.nextInt(100)); FolderRole folderAdminRole = new FolderRole(bottom.getFullName(), wrapPermissions(Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.CREATE), Collections.singleton(topFolderName), admin); folderRoles.add(maintainerRole); folderRoles.add(folderAdminRole); for (int k = 0; k < 5; k++) { bottom.createProject(FreeStyleProject.class, "Project" + k); } } } jenkins.setAuthorizationStrategy(new FolderBasedAuthorizationStrategy(globalRoles, folderRoles, Collections.emptySet())); }
Example 2
Source File: FolderBasedAuthorizationStrategyTest.java From folder-auth-plugin with MIT License | 4 votes |
@Before public void setUp() throws Exception { Jenkins jenkins = jenkinsRule.jenkins; jenkins.setSecurityRealm(jenkinsRule.createDummySecurityRealm()); FolderBasedAuthorizationStrategy strategy = new FolderBasedAuthorizationStrategy(Collections.emptySet(), Collections.emptySet(), Collections.emptySet()); jenkins.setAuthorizationStrategy(strategy); final String adminRoleName = "adminRole"; final String overallReadRoleName = "overallRead"; FolderAuthorizationStrategyAPI.addGlobalRole(new GlobalRole(adminRoleName, wrapPermissions(FolderAuthorizationStrategyManagementLink.getSafePermissions( new HashSet<>(PermissionGroup.getAll()))))); FolderAuthorizationStrategyAPI.assignSidToGlobalRole("admin", adminRoleName); FolderAuthorizationStrategyAPI.addGlobalRole(new GlobalRole(overallReadRoleName, wrapPermissions(Permission.READ))); FolderAuthorizationStrategyAPI.assignSidToGlobalRole("authenticated", overallReadRoleName); FolderAuthorizationStrategyAPI.addFolderRole(new FolderRole("folderRole1", wrapPermissions(Item.READ), ImmutableSet.of("root"))); FolderAuthorizationStrategyAPI.assignSidToFolderRole("user1", "folderRole1"); FolderAuthorizationStrategyAPI.assignSidToFolderRole("user2", "folderRole1"); FolderAuthorizationStrategyAPI.addFolderRole(new FolderRole("folderRole2", wrapPermissions(Item.CONFIGURE, Item.DELETE), ImmutableSet.of("root/child1"))); FolderAuthorizationStrategyAPI.assignSidToFolderRole("user2", "folderRole2"); /* * Folder hierarchy for the test * * root * / \ * child1 child2 * / \ * child3 job1 * / * job2 */ root = jenkins.createProject(Folder.class, "root"); child1 = root.createProject(Folder.class, "child1"); child2 = root.createProject(Folder.class, "child2"); child3 = child1.createProject(Folder.class, "child3"); job1 = child2.createProject(FreeStyleProject.class, "job1"); job2 = child3.createProject(FreeStyleProject.class, "job2"); admin = User.getById("admin", true); user1 = User.getById("user1", true); user2 = User.getById("user2", true); }