@Test
  public void testConfigure() throws InvalidConfigurationException, NamingException {
    try {
      ldapContextFactory.getSystemLdapContext();
      Assert.fail("Expected NamingException");
    } catch (NamingException e) {
      // expected
    }

    // now configure the relam
    CConnectionInfo connectionInfo = new CConnectionInfo();
    connectionInfo.setHost("localhost");
    connectionInfo.setPort(12345);
    connectionInfo.setAuthScheme("none");
    connectionInfo.setSearchBase("o=sonatype");
    connectionInfo.setProtocol("ldap");

    ldapConfig.updateConnectionInfo(connectionInfo);
    ldapConfig.save();

    // now we should be able to get a valid configuration
    ldapContextFactory.getSystemLdapContext();
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  public void validateLdapConfig(LdapConnectionInfoDTO connInfo) throws Exception {
    CConnectionInfo fileConfig = LdapConfigurationUtil.getConfiguration().getConnectionInfo();
    Assert.assertEquals(connInfo.getAuthScheme(), fileConfig.getAuthScheme());
    Assert.assertEquals(connInfo.getHost(), fileConfig.getHost());
    Assert.assertEquals(connInfo.getPort(), fileConfig.getPort());
    Assert.assertEquals(connInfo.getProtocol(), fileConfig.getProtocol());
    Assert.assertEquals(connInfo.getRealm(), fileConfig.getRealm());
    Assert.assertEquals(connInfo.getSearchBase(), fileConfig.getSearchBase());
    Assert.assertEquals(connInfo.getSystemUsername(), fileConfig.getSystemUsername());

    // if the expectedPassword == null then the actual should be null
    if (connInfo.getSystemPassword() == null) {
      Assert.assertNull(fileConfig.getSystemPassword());
    } else {
      // make sure its not clear text
      Assert.assertNotSame(connInfo.getSystemPassword(), fileConfig.getSystemPassword());
      Assert.assertTrue(fileConfig.getSystemPassword().length() > 0);
    }
  }