Search in sources :

Example 56 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project ART-TIME by Artezio.

the class LdapClientTest method getAttributesFor.

private Attributes getAttributesFor(Employee e) {
    Attributes attributes = new BasicAttributes();
    attributes.put(USERNAME_ATTRIBUTE, e.getUserName());
    attributes.put(FIRSTNAME_ATTRIBUTE, e.getFirstName());
    attributes.put(LASTNAME_ATTRIBUTE, e.getLastName());
    attributes.put(MAIL_ATTRIBUTE, e.getEmail());
    attributes.put(DEPARTMENT_ATTRIBUTE, e.getDepartment());
    attributes.put("RandomAttribute", "Random Value");
    attributes.put("RandomAttribute2", "Random Value 2");
    return attributes;
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 57 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project ART-TIME by Artezio.

the class LdapClientTest method getAttributesFor.

private Attributes getAttributesFor(String department) {
    Attributes attributes = new BasicAttributes();
    attributes.put(DEPARTMENT_ATTRIBUTE, department);
    attributes.put("RandomAttribute", "Random Value");
    attributes.put("RandomAttribute2", "Random Value 2");
    return attributes;
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 58 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project spring-security by spring-projects.

the class JndiDnsResolverTests method testResolveIpAddress.

@Test
public void testResolveIpAddress() throws Exception {
    Attributes records = new BasicAttributes("A", "63.246.7.80");
    when(context.getAttributes("www.springsource.com", new String[] { "A" })).thenReturn(records);
    String ipAddress = dnsResolver.resolveIpAddress("www.springsource.com");
    assertThat(ipAddress).isEqualTo("63.246.7.80");
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) BasicAttributes(javax.naming.directory.BasicAttributes) Test(org.junit.Test)

Example 59 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project hadoop by apache.

the class TestLdapGroupsMappingBase method setupMocksBase.

@Before
public void setupMocksBase() throws NamingException {
    MockitoAnnotations.initMocks(this);
    DirContext ctx = getContext();
    doReturn(ctx).when(groupsMapping).getDirContext();
    when(ctx.search(Mockito.anyString(), Mockito.anyString(), Mockito.any(Object[].class), Mockito.any(SearchControls.class))).thenReturn(userNames);
    // We only ever call hasMoreElements once for the user NamingEnum, so
    // we can just have one return value
    when(userNames.hasMoreElements()).thenReturn(true);
    SearchResult groupSearchResult = mock(SearchResult.class);
    // We're going to have to define the loop here. We want two iterations,
    // to get both the groups
    when(groupNames.hasMoreElements()).thenReturn(true, true, false);
    when(groupNames.nextElement()).thenReturn(groupSearchResult);
    // Define the attribute for the name of the first group
    Attribute group1Attr = new BasicAttribute("cn");
    group1Attr.add(testGroups[0]);
    Attributes group1Attrs = new BasicAttributes();
    group1Attrs.put(group1Attr);
    // Define the attribute for the name of the second group
    Attribute group2Attr = new BasicAttribute("cn");
    group2Attr.add(testGroups[1]);
    Attributes group2Attrs = new BasicAttributes();
    group2Attrs.put(group2Attr);
    // This search result gets reused, so return group1, then group2
    when(groupSearchResult.getAttributes()).thenReturn(group1Attrs, group2Attrs);
    when(getUserNames().nextElement()).thenReturn(getUserSearchResult());
    when(getUserSearchResult().getAttributes()).thenReturn(getAttributes());
    // Define results for groups 1 level up
    SearchResult parentGroupResult = mock(SearchResult.class);
    // only one parent group
    when(parentGroupNames.hasMoreElements()).thenReturn(true, false);
    when(parentGroupNames.nextElement()).thenReturn(parentGroupResult);
    // Define the attribute for the parent group
    Attribute parentGroup1Attr = new BasicAttribute("cn");
    parentGroup1Attr.add(testParentGroups[2]);
    Attributes parentGroup1Attrs = new BasicAttributes();
    parentGroup1Attrs.put(parentGroup1Attr);
    // attach the attributes to the result
    when(parentGroupResult.getAttributes()).thenReturn(parentGroup1Attrs);
    when(parentGroupResult.getNameInNamespace()).thenReturn("CN=some_group,DC=test,DC=com");
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) SearchControls(javax.naming.directory.SearchControls) SearchResult(javax.naming.directory.SearchResult) DirContext(javax.naming.directory.DirContext) Before(org.junit.Before)

Example 60 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project nhin-d by DirectProject.

the class RESTSmtpAgentConfigFunctional_Test method setUp.

/**
     * Initialize the servers- LDAP and HTTP.
     */
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
    // check for Windows... it doens't like file://<drive>... turns it into FTP
    File file = new File("./src/test/resources/bundles/testBundle.p7b");
    if (file.getAbsolutePath().contains(":/"))
        filePrefix = "file:///";
    else
        filePrefix = "file:///";
    CertCacheFactory.getInstance().flushAll();
    /*
		 * Setup the LDAP Server
		 */
    MutablePartitionConfiguration pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTest");
    pcfg.setSuffix("cn=lookupTest");
    // Create some indices
    Set<String> indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    Attributes attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    Attribute attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    Set<MutablePartitionConfiguration> pcfgs = new HashSet<MutablePartitionConfiguration>();
    pcfgs.add(pcfg);
    //
    //
    //
    // add the lookupTestPublic
    //
    //
    pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTestPublic");
    pcfg.setSuffix("cn=lookupTestPublic");
    // Create some indices
    indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    pcfgs.add(pcfg);
    configuration.setContextPartitionConfigurations(pcfgs);
    this.configuration.setWorkingDirectory(new File("LDAP-TEST"));
    // add the private key schema
    ///
    Set<AbstractBootstrapSchema> schemas = configuration.getBootstrapSchemas();
    schemas.add(new PrivkeySchema());
    configuration.setBootstrapSchemas(schemas);
    super.setUp();
    // import the ldif file
    InputStream stream = TestUtils.class.getResourceAsStream("/ldifs/privCertsOnly.ldif");
    if (stream == null)
        throw new IOException("Failed to load ldif file");
    importLdif(stream);
    // setup the mock DNS SRV adapter
    mockLookup = mock(Lookup.class);
    LookupFactory.getFactory().addOverrideImplementation(mockLookup);
    SRVRecord srvRecord = new SRVRecord(new Name("_ldap._tcp.example.com."), DClass.IN, 3600, 0, 1, port, new Name("localhost."));
    when(mockLookup.run()).thenReturn(new Record[] { srvRecord });
    // create the web service and proxy
    ConfigServiceRunner.startConfigService();
    proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
    certService = new DefaultCertificateService(ConfigServiceRunner.getRestAPIBaseURL(), HttpClientFactory.createHttpClient(), new OpenServiceSecurityManager());
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attribute(javax.naming.directory.Attribute) BasicAttribute(javax.naming.directory.BasicAttribute) DefaultCertificateService(org.nhind.config.rest.impl.DefaultCertificateService) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) OpenServiceSecurityManager(org.nhindirect.common.rest.OpenServiceSecurityManager) IOException(java.io.IOException) PrivkeySchema(org.nhindirect.ldap.PrivkeySchema) Name(org.xbill.DNS.Name) AbstractBootstrapSchema(org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema) MutablePartitionConfiguration(org.apache.directory.server.core.configuration.MutablePartitionConfiguration) Lookup(org.nhindirect.stagent.cert.impl.util.Lookup) SRVRecord(org.xbill.DNS.SRVRecord) File(java.io.File) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy) HashSet(java.util.HashSet)

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