Search in sources :

Example 6 with Entry

use of com.unboundid.ldap.sdk.Entry in project oxTrust by GluuFederation.

the class LdifService method performImport.

@SuppressWarnings("resource")
public void performImport(Class entryClass, InputStream inputStream) {
    final ArrayList<Entry> entryList = new ArrayList<Entry>();
    final LDIFReader reader = new LDIFReader(inputStream);
    while (true) {
        try {
            final Entry entry = reader.readEntry();
            if (entry == null) {
                break;
            } else {
                entryList.add(entry);
            }
        } catch (final Exception e) {
            log.error("", e);
        }
    }
    entryList.stream().forEach(e -> {
        Collection<Attribute> attributes = e.getAttributes();
        List<Attribute> values = new ArrayList<>();
        values.addAll(attributes);
        ArrayList<AttributeData> datas = new ArrayList<>();
        values.stream().forEach(value -> {
            datas.add(new AttributeData(value.getName(), value.getValues(), (value.getValues().length > 1) ? true : false));
        });
        try {
            persistenceManager.importEntry(e.getDN(), entryClass, datas);
        } catch (Exception ex) {
            log.info("=========", ex);
        }
    });
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) Attribute(com.unboundid.ldap.sdk.Attribute) GluuAttribute(org.gluu.model.GluuAttribute) LDIFReader(com.unboundid.ldif.LDIFReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LDAPException(com.unboundid.ldap.sdk.LDAPException) AttributeData(org.gluu.persist.model.AttributeData)

Example 7 with Entry

use of com.unboundid.ldap.sdk.Entry in project zm-mailbox by Zimbra.

the class UBIDUserCertificateAttributeTest method getMultiAttrStringShouldReturnCertificateForAttributeNameWithBinary.

@Test
public void getMultiAttrStringShouldReturnCertificateForAttributeNameWithBinary() {
    Attribute attr = new Attribute(lookupAttr, certBase64);
    Entry entry = PowerMockito.mock(Entry.class);
    UBIDAttributes attributes = new UBIDAttributes(entry);
    // entry does not contain "userCertificate" attribute
    Mockito.when(entry.getAttribute(ContactConstants.A_userCertificate)).thenReturn(null);
    // entry contains "userCertificate;binary" attribute
    Mockito.when(entry.getAttribute(lookupAttr)).thenReturn(attr);
    try {
        assertEquals(attributes.getMultiAttrString(lookupAttr, false)[0], certBase64);
    } catch (com.zimbra.cs.ldap.LdapException e) {
        fail("Exception thrown");
    }
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) Attribute(com.unboundid.ldap.sdk.Attribute) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Entry

use of com.unboundid.ldap.sdk.Entry in project spring-security by spring-projects.

the class UnboundIdContainer method start.

@Override
public void start() {
    if (isRunning()) {
        return;
    }
    try {
        InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.defaultPartitionSuffix);
        config.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
        config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", this.port));
        config.setEnforceSingleStructuralObjectClass(false);
        config.setEnforceAttributeSyntaxCompliance(true);
        DN dn = new DN(this.defaultPartitionSuffix);
        Entry entry = new Entry(dn);
        entry.addAttribute("objectClass", "top", "domain", "extensibleObject");
        entry.addAttribute("dc", dn.getRDN().getAttributeValues()[0]);
        InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config);
        directoryServer.add(entry);
        importLdif(directoryServer);
        directoryServer.startListening();
        this.port = directoryServer.getListenPort();
        this.directoryServer = directoryServer;
        this.running = true;
    } catch (LDAPException ex) {
        throw new RuntimeException("Server startup failed", ex);
    }
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) LDAPException(com.unboundid.ldap.sdk.LDAPException) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) DN(com.unboundid.ldap.sdk.DN)

Example 9 with Entry

use of com.unboundid.ldap.sdk.Entry in project graylog2-server by Graylog2.

the class UnboundLDAPConnector method search.

public ImmutableList<LDAPEntry> search(LDAPConnection connection, String searchBase, Filter filter, String uniqueIdAttribute, Set<String> attributes) throws LDAPException {
    final ImmutableSet<String> allAttributes = ImmutableSet.<String>builder().add(OBJECT_CLASS_ATTRIBUTE).addAll(attributes).build();
    // TODO: Use LDAPEntrySource for a more memory efficient search
    final SearchRequest searchRequest = new SearchRequest(searchBase, SearchScope.SUB, filter, allAttributes.toArray(new String[0]));
    searchRequest.setTimeLimitSeconds(requestTimeoutSeconds);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Search LDAP for <{}> using search base <{}>", filter.toNormalizedString(), searchBase);
    }
    final SearchResult searchResult = connection.search(searchRequest);
    if (searchResult.getSearchEntries().isEmpty()) {
        LOG.trace("No LDAP entry found for filter <{}>", filter.toNormalizedString());
        return ImmutableList.of();
    }
    return searchResult.getSearchEntries().stream().map(entry -> createLDAPEntry(entry, uniqueIdAttribute)).collect(ImmutableList.toImmutableList());
}
Also used : LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Arrays(java.util.Arrays) Entry(com.unboundid.ldap.sdk.Entry) TrustAllX509TrustManager(org.graylog2.security.TrustAllX509TrustManager) Attribute(com.unboundid.ldap.sdk.Attribute) LoggerFactory(org.slf4j.LoggerFactory) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Singleton(javax.inject.Singleton) Base64(com.unboundid.util.Base64) BindRequest(com.unboundid.ldap.sdk.BindRequest) MessageFormat(java.text.MessageFormat) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) Inject(javax.inject.Inject) LDAPBindException(com.unboundid.ldap.sdk.LDAPBindException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) GeneralSecurityException(java.security.GeneralSecurityException) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) SSLUtil(com.unboundid.util.ssl.SSLUtil) Objects.requireNonNull(java.util.Objects.requireNonNull) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) Named(javax.inject.Named) BindResult(com.unboundid.ldap.sdk.BindResult) LDAPException(com.unboundid.ldap.sdk.LDAPException) ResultCode(com.unboundid.ldap.sdk.ResultCode) LDAPTestUtils(com.unboundid.util.LDAPTestUtils) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) ImmutableSet(com.google.common.collect.ImmutableSet) EncryptedValue(org.graylog2.security.encryption.EncryptedValue) Logger(org.slf4j.Logger) StaticUtils.isValidUTF8(com.unboundid.util.StaticUtils.isValidUTF8) TrustManagerProvider(org.graylog2.security.TrustManagerProvider) LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) Set(java.util.Set) FailoverServerSet(com.unboundid.ldap.sdk.FailoverServerSet) Ints(com.google.common.primitives.Ints) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) SocketFactory(javax.net.SocketFactory) SearchResult(com.unboundid.ldap.sdk.SearchResult) StaticUtils.toUTF8String(com.unboundid.util.StaticUtils.toUTF8String) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) EncryptedValueService(org.graylog2.security.encryption.EncryptedValueService) Optional(java.util.Optional) Filter(com.unboundid.ldap.sdk.Filter) SearchScope(com.unboundid.ldap.sdk.SearchScope) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) SearchResult(com.unboundid.ldap.sdk.SearchResult) StaticUtils.toUTF8String(com.unboundid.util.StaticUtils.toUTF8String)

Aggregations

Entry (com.unboundid.ldap.sdk.Entry)9 LDAPException (com.unboundid.ldap.sdk.LDAPException)6 Attribute (com.unboundid.ldap.sdk.Attribute)4 LDIFReader (com.unboundid.ldif.LDIFReader)4 IOException (java.io.IOException)4 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)3 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)3 SearchResult (com.unboundid.ldap.sdk.SearchResult)3 LDIFException (com.unboundid.ldif.LDIFException)3 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Ints (com.google.common.primitives.Ints)1 BindRequest (com.unboundid.ldap.sdk.BindRequest)1 BindResult (com.unboundid.ldap.sdk.BindResult)1 DN (com.unboundid.ldap.sdk.DN)1 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)1 FailoverServerSet (com.unboundid.ldap.sdk.FailoverServerSet)1