Search in sources :

Example 91 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project directory-ldap-api by apache.

the class LdifUtilsTest method testConvertToLdifEncoding.

/**
 * Tests that unsafe characters are encoded using UTF-8 charset.
 * @throws LdapException
 *
 * @throws NamingException
 */
@Test
public void testConvertToLdifEncoding() throws LdapException {
    Attributes attributes = new BasicAttributes("cn", "Saarbr\u00FCcken");
    String ldif = LdifUtils.convertToLdif(attributes);
    assertEquals("cn:: U2FhcmJyw7xja2Vu\n", ldif);
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) Test(org.junit.Test)

Example 92 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project Openfire by igniterealtime.

the class LDAPTest method testGetRelativeDNFromResultMultiValue.

/**
 * Verifies that org.jivesoftware.openfire.ldap.LdapManager#getRelativeDNFromResult(javax.naming.directory.SearchResult)
 * can handle a result that contains multiple RDN values.
 */
@Test
public void testGetRelativeDNFromResultMultiValue() throws Exception {
    // Setup test fixture.
    final SearchResult input = new SearchResult("cn=bender,ou=people", null, new BasicAttributes(), true);
    // Execute system under test.
    final Rdn[] result = LdapManager.getRelativeDNFromResult(input);
    // Verify result.
    assertEquals(2, result.length);
    assertEquals("cn", result[0].getType());
    assertEquals("bender", result[0].getValue());
    assertEquals("ou", result[1].getType());
    assertEquals("people", result[1].getValue());
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) SearchResult(javax.naming.directory.SearchResult) Rdn(javax.naming.ldap.Rdn) Test(org.junit.Test)

Example 93 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project Openfire by igniterealtime.

the class LDAPTest method testGetRelativeDNFromResultSingleValue.

/**
 * Verifies that org.jivesoftware.openfire.ldap.LdapManager#getRelativeDNFromResult(javax.naming.directory.SearchResult)
 * can handle a result that contains one RDN value.
 */
@Test
public void testGetRelativeDNFromResultSingleValue() throws Exception {
    // Setup test fixture.
    final SearchResult input = new SearchResult("cn=bender", null, new BasicAttributes(), true);
    // Execute system under test.
    final Rdn[] result = LdapManager.getRelativeDNFromResult(input);
    // Verify result.
    assertEquals(1, result.length);
    assertEquals("cn", result[0].getType());
    assertEquals("bender", result[0].getValue());
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) SearchResult(javax.naming.directory.SearchResult) Rdn(javax.naming.ldap.Rdn) Test(org.junit.Test)

Example 94 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project Openfire by igniterealtime.

the class LDAPTest method testGetRelativeDNFromResultQuoted.

/**
 * Verifies that org.jivesoftware.openfire.ldap.LdapManager#getRelativeDNFromResult(javax.naming.directory.SearchResult)
 * can handle a result that contains a quoted RDN values.
 *
 * Openldap has been observed returning the type of quoted values that are tested here.
 */
@Test
public void testGetRelativeDNFromResultQuoted() throws Exception {
    // Setup test fixture.
    final SearchResult input = new SearchResult("\"cn=ship crew/cooks\"", null, new BasicAttributes(), true);
    // Execute system under test.
    final Rdn[] result = LdapManager.getRelativeDNFromResult(input);
    // Verify result.
    assertEquals(1, result.length);
    assertEquals("cn", result[0].getType());
    assertEquals("ship crew/cooks", result[0].getValue());
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) SearchResult(javax.naming.directory.SearchResult) Rdn(javax.naming.ldap.Rdn) Test(org.junit.Test)

Example 95 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project druid by druid-io.

the class BasicRoleBasedAuthorizerTest method setUp.

@Before
public void setUp() {
    TestDerbyConnector connector = derbyConnectorRule.getConnector();
    MetadataStorageTablesConfig tablesConfig = derbyConnectorRule.metadataTablesConfigSupplier().get();
    connector.createConfigTable();
    BasicAttributes userAttrs = new BasicAttributes(true);
    userAttrs.put(new BasicAttribute("sAMAccountName", "druiduser"));
    userAttrs.put(new BasicAttribute("memberOf", "CN=user,OU=Druid,OU=Application,OU=Groupings,DC=corp,DC=apache,DC=org"));
    BasicAttributes adminAttrs = new BasicAttributes(true);
    adminAttrs.put(new BasicAttribute("sAMAccountName", "druidadmin"));
    adminAttrs.put(new BasicAttribute("memberOf", "CN=admin,OU=Platform,OU=Groupings,DC=corp,DC=apache,DC=org"));
    userSearchResult = new SearchResult("CN=1234,OU=Employees,OU=People", null, userAttrs);
    adminSearchResult = new SearchResult("CN=9876,OU=Employees,OU=People", null, adminAttrs);
    updater = new CoordinatorBasicAuthorizerMetadataStorageUpdater(new AuthorizerMapper(ImmutableMap.of(DB_AUTHORIZER_NAME, new BasicRoleBasedAuthorizer(null, DB_AUTHORIZER_NAME, null, null, null, null, null, new MetadataStoreRoleProvider(null)), LDAP_AUTHORIZER_NAME, new BasicRoleBasedAuthorizer(null, LDAP_AUTHORIZER_NAME, null, null, null, null, null, new LDAPRoleProvider(null, groupFilters)))), connector, tablesConfig, new BasicAuthCommonCacheConfig(null, null, null, null), new ObjectMapper(new SmileFactory()), new NoopBasicAuthorizerCacheNotifier(), null);
    updater.start();
    authorizer = new BasicRoleBasedAuthorizer(null, DB_AUTHORIZER_NAME, null, null, null, null, null, new MetadataStoreRoleProvider(new MetadataStoragePollingBasicAuthorizerCacheManager(updater)));
    ldapAuthorizer = new BasicRoleBasedAuthorizer(null, LDAP_AUTHORIZER_NAME, null, null, null, null, null, new LDAPRoleProvider(new MetadataStoragePollingBasicAuthorizerCacheManager(updater), groupFilters));
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) CoordinatorBasicAuthorizerMetadataStorageUpdater(org.apache.druid.security.basic.authorization.db.updater.CoordinatorBasicAuthorizerMetadataStorageUpdater) MetadataStoragePollingBasicAuthorizerCacheManager(org.apache.druid.security.basic.authorization.db.cache.MetadataStoragePollingBasicAuthorizerCacheManager) BasicAuthCommonCacheConfig(org.apache.druid.security.basic.BasicAuthCommonCacheConfig) SearchResult(javax.naming.directory.SearchResult) TestDerbyConnector(org.apache.druid.metadata.TestDerbyConnector) LDAPRoleProvider(org.apache.druid.security.basic.authorization.LDAPRoleProvider) MetadataStorageTablesConfig(org.apache.druid.metadata.MetadataStorageTablesConfig) SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) BasicRoleBasedAuthorizer(org.apache.druid.security.basic.authorization.BasicRoleBasedAuthorizer) MetadataStoreRoleProvider(org.apache.druid.security.basic.authorization.MetadataStoreRoleProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

BasicAttributes (javax.naming.directory.BasicAttributes)100 Attributes (javax.naming.directory.Attributes)62 BasicAttribute (javax.naming.directory.BasicAttribute)57 Attribute (javax.naming.directory.Attribute)44 Test (org.junit.Test)22 SearchResult (javax.naming.directory.SearchResult)21 DirContext (javax.naming.directory.DirContext)18 NamingException (javax.naming.NamingException)15 InitialDirContext (javax.naming.directory.InitialDirContext)14 NamingEnumeration (javax.naming.NamingEnumeration)12 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)10 LdapContext (javax.naming.ldap.LdapContext)9 HashMap (java.util.HashMap)8 InitialLdapContext (javax.naming.ldap.InitialLdapContext)8 File (java.io.File)7 Map (java.util.Map)7 MutablePartitionConfiguration (org.apache.directory.server.core.configuration.MutablePartitionConfiguration)7 AbstractBootstrapSchema (org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema)7 IOException (java.io.IOException)6