hudson.model.Hudson Java Examples
The following examples show how to use
hudson.model.Hudson.
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: ProfileApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void shouldFailForAnonymousRead() throws IOException { HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false); realm.createAccount("alice","alice"); j.jenkins.setSecurityRealm(realm); GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy(); j.jenkins.setAuthorizationStrategy(as); as.add(Hudson.READ,"alice"); Map resp = new RequestBuilder(baseUrl) .status(403) .get("/users/") .build(Map.class); assertEquals(403, resp.get("code")); }
Example #2
Source File: ProfileApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void shouldSucceedForAnonymousRead() throws IOException { HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false); realm.createAccount("alice","alice"); j.jenkins.setSecurityRealm(realm); GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy(); j.jenkins.setAuthorizationStrategy(as); as.add(Hudson.READ,"anonymous"); List resp = new RequestBuilder(baseUrl) .status(200) .get("/users/") .build(List.class); assertEquals(1, resp.size()); }
Example #3
Source File: ProfileApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void shouldFailForUnauthorizedUser() throws IOException, UnirestException { HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false); realm.createAccount("alice","alice"); realm.createAccount("bob","bob"); j.jenkins.setSecurityRealm(realm); GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy(); j.jenkins.setAuthorizationStrategy(as); as.add(Hudson.READ,"alice"); Map resp = new RequestBuilder(baseUrl) .status(403) .auth("bob", "bob") .get("/users/") .build(Map.class); assertEquals(403, resp.get("code")); }
Example #4
Source File: JmhBenchmarkState.java From jenkins-test-harness with MIT License | 6 votes |
private void launchInstance() throws Exception { ImmutablePair<Server, ServletContext> results = JenkinsRule._createWebServer(contextPath, localPort::setValue, getClass().getClassLoader(), localPort.getValue(), JenkinsRule::_configureUserRealm); server = results.left; ServletContext webServer = results.right; jenkins = new Hudson(temporaryDirectoryAllocator.allocate(), webServer); JenkinsRule._configureJenkinsForTest(jenkins); JenkinsRule._configureUpdateCenter(jenkins); jenkins.getActions().add(this); String url = Objects.requireNonNull(getJenkinsURL()).toString(); Objects.requireNonNull(JenkinsLocationConfiguration.get()).setUrl(url); LOGGER.log(Level.INFO, "Running on {0}", url); }
Example #5
Source File: GitHubOrgMetadataAction.java From github-branch-source-plugin with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public String getAvatarImageOf(String size) { if (avatar == null) { // fall back to the generic github org icon String image = avatarIconClassNameImageOf(getAvatarIconClassName(), size); return image != null ? image : (Stapler.getCurrentRequest().getContextPath() + Hudson.RESOURCE_PATH + "/plugin/github-branch-source/images/" + size + "/github-logo.png"); } else { String[] xy = size.split("x"); if (xy.length == 0) return avatar; if (avatar.contains("?")) return avatar + "&s=" + xy[0]; else return avatar + "?s=" + xy[0]; } }
Example #6
Source File: FolderAuthorizationStrategyManagementLink.java From folder-auth-plugin with MIT License | 5 votes |
@Nonnull @Restricted(NoExternalUse.class) @SuppressWarnings("unused") // used by index.jelly public Set<Permission> getFolderPermissions() { HashSet<PermissionGroup> groups = new HashSet<>(PermissionGroup.getAll()); groups.remove(PermissionGroup.get(Hudson.class)); groups.remove(PermissionGroup.get(Computer.class)); groups.remove(PermissionGroup.get(Permission.class)); return getSafePermissions(groups); }
Example #7
Source File: FolderAuthorizationStrategyManagementLink.java From folder-auth-plugin with MIT License | 5 votes |
@Nonnull @Restricted(NoExternalUse.class) @SuppressWarnings("unused") // used by index.jelly public Set<Permission> getAgentPermissions() { HashSet<PermissionGroup> groups = new HashSet<>(PermissionGroup.getAll()); groups.remove(PermissionGroup.get(Run.class)); groups.remove(PermissionGroup.get(SCM.class)); groups.remove(PermissionGroup.get(View.class)); groups.remove(PermissionGroup.get(Item.class)); groups.remove(PermissionGroup.get(Hudson.class)); groups.remove(PermissionGroup.get(Permission.class)); return getSafePermissions(groups); }
Example #8
Source File: ArtifactsSecurity564.java From blueocean-plugin with MIT License | 5 votes |
/** * Uses matrix-auth to provide artifacts permission. * * If hudson.security.ArtifactsPermission is set then the user must have Run.ARTIFACTS set. * * @throws Exception */ @Issue("SECURITY-564") @Test public void testArtifactsWithPermissions() throws Exception { String JOB_NAME = "artifactPermissions"; String artifactPath = "a/b/c"; HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false); realm.createAccount("alice","alice"); realm.createAccount("bob","bob"); j.jenkins.setSecurityRealm(realm); GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy(); j.jenkins.setAuthorizationStrategy(as); as.add(Hudson.READ,"alice"); as.add(Item.READ,"alice"); as.add(Run.ARTIFACTS,"alice"); as.add(Hudson.READ,"bob"); as.add(Item.READ,"bob"); FreeStyleProject p = j.createFreeStyleProject(JOB_NAME); p.getBuildersList().add(new ArtifactBuilder(artifactPath, 100)); p.getPublishersList().add(new ArtifactArchiver("**/*")); Run r = p.scheduleBuild2(0).waitForStart(); r = j.waitForCompletion(r); List artifacts = request().authAlice().get("/organizations/jenkins/pipelines/"+JOB_NAME+"/runs/"+r.getId()+"/artifacts").build(List.class); Assert.assertEquals(100, artifacts.size()); Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size")); Assert.assertEquals(artifactPath + "/0.txt", ((Map) artifacts.get(0)).get("path")); Assert.assertEquals("/job/artifactPermissions/1/artifact/"+ artifactPath +"/0.txt", ((Map) artifacts.get(0)).get("url")); List artifactsBob = request().auth("bob", "bob").get("/organizations/jenkins/pipelines/"+JOB_NAME+"/runs/"+r.getId()+"/artifacts").build(List.class); Assert.assertEquals(0, artifactsBob.size()); }
Example #9
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 5 votes |
/** * Creates a new instance of {@link jenkins.model.Jenkins}. If the derived class wants to create it in a different way, * you can override it. */ protected Hudson newHudson() throws Exception { jettyLevel(Level.WARNING); ServletContext webServer = createWebServer(); File home = homeLoader.allocate(); for (JenkinsRecipe.Runner r : recipes) r.decorateHome(this,home); try { return new Hudson(home, webServer, getPluginManager()); } catch (InterruptedException x) { throw new AssumptionViolatedException("Jenkins startup interrupted", x); } finally { jettyLevel(Level.INFO); } }
Example #10
Source File: EnvDashboardView.java From environment-dashboard-plugin with MIT License | 5 votes |
@DataBoundConstructor public EnvDashboardView(final String name, final String envOrder, final String compOrder, final String deployHistory) { super(name, Hudson.getInstance()); this.envOrder = envOrder; this.compOrder = compOrder; this.deployHistory = deployHistory; }
Example #11
Source File: EnvDashboardView.java From environment-dashboard-plugin with MIT License | 4 votes |
@Override public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { return Hudson.getInstance().doCreateItem(req, rsp); }
Example #12
Source File: OrganizationGravatarIcon.java From DotCi with MIT License | 4 votes |
public String getImageOf(final String size) { return Stapler.getCurrentRequest().getContextPath() + Hudson.RESOURCE_PATH + "/images/" + size + "/folder.png"; }
Example #13
Source File: OrganizationGravatarIcon.java From DotCi with MIT License | 4 votes |
public Descriptor<OrganizationGravatarIcon> getDescriptor() { return Hudson.getInstance().getDescriptorOrDie(getClass()); }
Example #14
Source File: OrganizationGravatarIcon.java From DotCi with MIT License | 4 votes |
public static DescriptorExtensionList<OrganizationGravatarIcon, DescriptorImpl> all() { return Hudson.getInstance().<OrganizationGravatarIcon, DescriptorImpl>getDescriptorList(OrganizationGravatarIcon.class); }
Example #15
Source File: OrganizationContainer.java From DotCi with MIT License | 4 votes |
@Override public TopLevelItemDescriptor getDescriptor() { return (DescriptorImpl) Hudson.getInstance().getDescriptorOrDie(getClass()); }
Example #16
Source File: OrganizationContainer.java From DotCi with MIT License | 4 votes |
public DynamicProject createProject(final Class<DynamicProject> type, final String projectName) throws IOException { return type.cast(createProject((TopLevelItemDescriptor) Hudson.getInstance().getDescriptor(type), projectName)); }