Java Code Examples for jenkins.model.Jenkins#getSecurityRealm()

The following examples show how to use jenkins.model.Jenkins#getSecurityRealm() . 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: LDAPTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@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());
}
 
Example 2
Source File: ActiveDirectoryTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithReadme("active-directory/README.md")
public void configure_active_directory() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    final ActiveDirectorySecurityRealm realm = (ActiveDirectorySecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, realm.domains.size());
    final ActiveDirectoryDomain domain = realm.domains.get(0);
    assertEquals("acme", domain.name);
    assertEquals("admin", domain.bindName);
    assertEquals("ADMIN123", domain.bindPassword.getPlainText());
    assertEquals("ad1.acme.com:123,ad2.acme.com:456", domain.servers);
    assertEquals("jenkins", realm.getJenkinsInternalUser());

    assertTrue(realm.removeIrrelevantGroups);
    assertTrue(realm.startTls);
    assertNotNull(realm.getCache());
    assertEquals(500, realm.getCache().getSize());
    assertEquals(600, realm.getCache().getTtl());

}
 
Example 3
Source File: TopReadmeTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithReadme("README.md#0")
public void configure_demo_first_code_block() throws Exception {
    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"));
}
 
Example 4
Source File: HudsonPrivateSecurityRealmConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithReadme("embedded-userdatabase/README.md#0")
public void configure_local_security_and_admin_user() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    final HudsonPrivateSecurityRealm securityRealm = (HudsonPrivateSecurityRealm) jenkins.getSecurityRealm();
    assertFalse(securityRealm.allowsSignup());
    final User admin = User.getById("admin", false);
    assertNotNull(admin);
    final HudsonPrivateSecurityRealm.Details details = admin.getProperty(HudsonPrivateSecurityRealm.Details.class);
    assertTrue(details.isPasswordCorrect("somethingsecret"));

    final FullControlOnceLoggedInAuthorizationStrategy authorizationStrategy = (FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy();
    assertTrue(authorizationStrategy.isAllowAnonymousRead());
}
 
Example 5
Source File: TopReadmeTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithReadme("README.md#1")
public void configure_demo_second_code_block() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, securityRealm.getConfigurations().size());
}