Search in sources :

Example 1 with LDAPSecurityRealm

use of hudson.security.LDAPSecurityRealm in project configuration-as-code-plugin by jenkinsci.

the class LDAPTest method configure_ldap.

@Test
@ConfiguredWithReadme("ldap/README.md")
public void configure_ldap() {
    final Jenkins jenkins = Jenkins.get();
    final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, securityRealm.getConfigurations().size());
    assertTrue(securityRealm.getUserIdStrategy() instanceof IdStrategy.CaseInsensitive);
    assertTrue(securityRealm.getGroupIdStrategy() instanceof IdStrategy.CaseSensitive);
    final LDAPConfiguration configuration = securityRealm.getConfigurations().get(0);
    assertEquals("ldap.acme.com", configuration.getServer());
    assertEquals("SECRET", configuration.getManagerPassword());
    assertEquals("manager", configuration.getManagerDN());
    assertEquals("(&(objectCategory=User)(sAMAccountName={0}))", configuration.getUserSearch());
    assertEquals("(&(cn={0})(objectclass=group))", configuration.getGroupSearchFilter());
    final FromGroupSearchLDAPGroupMembershipStrategy strategy = ((FromGroupSearchLDAPGroupMembershipStrategy) configuration.getGroupMembershipStrategy());
    assertEquals("(&(objectClass=group)(|(cn=GROUP_1)(cn=GROUP_2)))", strategy.getFilter());
}
Also used : Jenkins(jenkins.model.Jenkins) LDAPSecurityRealm(hudson.security.LDAPSecurityRealm) FromGroupSearchLDAPGroupMembershipStrategy(jenkins.security.plugins.ldap.FromGroupSearchLDAPGroupMembershipStrategy) IdStrategy(jenkins.model.IdStrategy) LDAPConfiguration(jenkins.security.plugins.ldap.LDAPConfiguration) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Example 2 with LDAPSecurityRealm

use of hudson.security.LDAPSecurityRealm in project configuration-as-code-plugin by jenkinsci.

the class TopReadmeTest method configure_demo_first_code_block.

@Test
@ConfiguredWithReadme("README.md#0")
public void configure_demo_first_code_block() {
    final Jenkins jenkins = Jenkins.get();
    assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
    final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, securityRealm.getConfigurations().size());
    assertEquals(50000, jenkins.getSlaveAgentPort());
    assertEquals(1, jenkins.getNodes().size());
    assertEquals("static-agent", jenkins.getNode("static-agent").getNodeName());
    final GitTool.DescriptorImpl gitTool = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
    assertEquals(1, gitTool.getInstallations().length);
    List<BasicSSHUserPrivateKey> sshPrivateKeys = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(sshPrivateKeys, hasSize(1));
    final BasicSSHUserPrivateKey ssh_with_passphrase = sshPrivateKeys.get(0);
    assertThat(ssh_with_passphrase.getPassphrase().getPlainText(), equalTo("ABCD"));
    final DirectEntryPrivateKeySource source = (DirectEntryPrivateKeySource) ssh_with_passphrase.getPrivateKeySource();
    assertThat(source.getPrivateKey().getPlainText(), equalTo("s3cr3t"));
}
Also used : Jenkins(jenkins.model.Jenkins) LDAPSecurityRealm(hudson.security.LDAPSecurityRealm) DirectEntryPrivateKeySource(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource) GitTool(hudson.plugins.git.GitTool) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Example 3 with LDAPSecurityRealm

use of hudson.security.LDAPSecurityRealm in project configuration-as-code-plugin by jenkinsci.

the class LDAPSecurityRealmTest method configure_securityRealm.

@Test
@ConfiguredWithCode("LDAPSecurityRealmTest.yml")
public void configure_securityRealm() {
    final Jenkins jenkins = Jenkins.getInstance();
    final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, securityRealm.getConfigurations().size());
    assertTrue(securityRealm.getUserIdStrategy() instanceof IdStrategy.CaseInsensitive);
    assertTrue(securityRealm.getGroupIdStrategy() instanceof IdStrategy.CaseSensitive);
    final LDAPConfiguration configuration = securityRealm.getConfigurations().get(0);
    assertEquals("ldap.acme.com", configuration.getServer());
    assertEquals("SECRET", configuration.getManagerPassword());
}
Also used : Jenkins(jenkins.model.Jenkins) LDAPSecurityRealm(hudson.security.LDAPSecurityRealm) IdStrategy(jenkins.model.IdStrategy) LDAPConfiguration(jenkins.security.plugins.ldap.LDAPConfiguration) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 4 with LDAPSecurityRealm

use of hudson.security.LDAPSecurityRealm in project configuration-as-code-plugin by jenkinsci.

the class TopReadmeTest method configure_demo_second_code_block.

@Test
@ConfiguredWithReadme("README.md#1")
public void configure_demo_second_code_block() {
    final Jenkins jenkins = Jenkins.get();
    final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, securityRealm.getConfigurations().size());
}
Also used : Jenkins(jenkins.model.Jenkins) LDAPSecurityRealm(hudson.security.LDAPSecurityRealm) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Aggregations

LDAPSecurityRealm (hudson.security.LDAPSecurityRealm)4 Jenkins (jenkins.model.Jenkins)4 Test (org.junit.Test)4 ConfiguredWithReadme (io.jenkins.plugins.casc.misc.ConfiguredWithReadme)3 IdStrategy (jenkins.model.IdStrategy)2 LDAPConfiguration (jenkins.security.plugins.ldap.LDAPConfiguration)2 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)1 DirectEntryPrivateKeySource (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource)1 GitTool (hudson.plugins.git.GitTool)1 FromGroupSearchLDAPGroupMembershipStrategy (jenkins.security.plugins.ldap.FromGroupSearchLDAPGroupMembershipStrategy)1 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)1