@Nonnull @Override public Set<Attribute<SystemCredentialsProvider, ?>> describe() { return Collections.singleton( new MultivaluedAttribute<SystemCredentialsProvider, DomainCredentials>("domainCredentials", DomainCredentials.class) .setter( (target, value) -> target.setDomainCredentialsMap(DomainCredentials.asMap(value))) ); }
credentialsProvider.setDomainCredentialsMap(credentialsMap); credentialsProvider.save();
Proc p = runSvnServe(getClass().getResource("HUDSON-1379.zip")); try { SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Collections.<Credentials>emptyList() )); SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-bob", null, "bob","bob") SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-bob", null, "bob","bob"),
/** * There was a bug that credentials stored in the remote call context was serialized wrongly. */ @Issue("JENKINS-8061") @Test public void remoteBuild() throws Exception { Proc p = runSvnServe(SubversionSCMTest.class.getResource("HUDSON-1379.zip")); try { SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-alice", null, "alice", "alice") ) )); FreeStyleProject b = r.createFreeStyleProject(); b.setScm(new SubversionSCM("svn://localhost/bob", "1-alice", ".")); b.setAssignedNode(r.createSlave()); FreeStyleBuild run = r.buildAndAssertSuccess(b); /* TODO runSvnServe not guaranteed to use port 3690; otherwise this works: assertLogContains(Messages.CredentialsSVNAuthenticationProviderImpl_sole_credentials("alice/******", "<svn://localhost:3690> 8a677b3a-1c61-4b23-9212-1bf3c3d713a7"), run); */ } finally { p.kill(); } } }
@Issue("SECURITY-303") @Test public void credentialsAccess() throws Exception { r.jenkins.setSecurityRealm(r.createDummySecurityRealm()); r.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy(). grant(Jenkins.READ, Item.READ, Item.BUILD, Item.CONFIGURE).everywhere().to("devlead"). grant(Jenkins.READ, Item.READ, Item.BUILD).everywhere().to("user")); SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Collections.<Credentials>singletonList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "svncreds", null, "svn", "s3cr3t")))); r.createFreeStyleProject("p"); assertSniff("devlead", "svn:s3cr3t", /* server response is bad, Jenkins should say so */ false); assertSniff("user", null, /* Jenkins should not even try to connect, pretend it is OK */ true); } private void assertSniff(String user, String sniffed, boolean ok) throws Exception {
main.svnkit("commit", "--message=externals", main.wc()); FreeStyleProject p = r.createFreeStyleProject("p"); SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "main-creds", null, "alice", "alice"), new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "ext-creds", null, "bob", "bob"))));
@Issue("JENKINS-1379") @Test public void superUserForAllRepos() throws Exception { Proc p = runSvnServe(getClass().getResource("HUDSON-1379.zip")); try { SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-alice", null, "alice","alice") ) )); FreeStyleProject b = r.createFreeStyleProject(); b.setScm(new SubversionSCM("svn://localhost/bob")); FreeStyleProject c = r.createFreeStyleProject(); c.setScm(new SubversionSCM("svn://localhost/charlie")); // should fail without a credential r.assertBuildStatus(Result.FAILURE,b.scheduleBuild2(0).get()); r.assertBuildStatus(Result.FAILURE,c.scheduleBuild2(0).get()); b.setScm(new SubversionSCM("svn://localhost/bob", "1-alice", ".")); c.setScm(new SubversionSCM("svn://localhost/charlie", "1-alice", ".")); // but with the super user credential both should work now r.buildAndAssertSuccess(b); r.buildAndAssertSuccess(c); } finally { p.kill(); } }