Search in sources :

Example 11 with Attribute

use of com.unboundid.ldap.sdk.Attribute in project gocd by gocd.

the class InMemoryLdapServerForTests method startServer.

private InMemoryDirectoryServer startServer(int port, String baseDn, String bindDn, String bindPassword) throws LDAPException, BindException {
    InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", port);
    InMemoryDirectoryServerConfig serverConfig = new InMemoryDirectoryServerConfig(new DN(baseDn));
    /* Ignore schema so that it does not complain that some attributes (like sAMAccountName) are not valid. */
    serverConfig.setSchema(null);
    serverConfig.setListenerConfigs(listenerConfig);
    serverConfig.addAdditionalBindCredentials(bindDn, bindPassword);
    InMemoryDirectoryServer server = new InMemoryDirectoryServer(serverConfig);
    try {
        server.startListening();
    } catch (LDAPException e) {
        throw new RuntimeException(e);
    }
    new LDIFAddChangeRecord(baseDn, new Attribute("objectClass", "domain", "top")).processChange(server);
    return server;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) Attribute(com.unboundid.ldap.sdk.Attribute) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) InMemoryListenerConfig(com.unboundid.ldap.listener.InMemoryListenerConfig) DN(com.unboundid.ldap.sdk.DN)

Example 12 with Attribute

use of com.unboundid.ldap.sdk.Attribute in project oxCore by GluuFederation.

the class LdapOperationsServiceImpl method populateAttributeDataTypesMapping.

private void populateAttributeDataTypesMapping(String schemaEntryDn) {
    try {
        if (ATTRIBUTE_DATA_TYPES.size() == 0) {
            // schemaEntryDn="ou=schema";
            SearchResultEntry entry = lookup(schemaEntryDn, "attributeTypes");
            Attribute attrAttributeTypes = entry.getAttribute("attributeTypes");
            Map<String, Pair<String, String>> tmpMap = new HashMap<String, Pair<String, String>>();
            for (String strAttributeType : attrAttributeTypes.getValues()) {
                AttributeTypeDefinition attrTypeDef = new AttributeTypeDefinition(strAttributeType);
                String[] names = attrTypeDef.getNames();
                if (names != null) {
                    for (String name : names) {
                        tmpMap.put(name, new Pair<String, String>(attrTypeDef.getBaseSyntaxOID(), attrTypeDef.getSuperiorType()));
                    }
                }
            }
            // Fill missing values
            for (String name : tmpMap.keySet()) {
                Pair<String, String> currPair = tmpMap.get(name);
                String sup = currPair.getSecond();
                if (currPair.getFirst() == null && sup != null) {
                    // No OID syntax?
                    // Try to lookup superior type
                    Pair<String, String> pair = tmpMap.get(sup);
                    if (pair != null) {
                        currPair.setFirst(pair.getFirst());
                    }
                }
            }
            // Populate map of attribute names vs. Java classes
            for (String name : tmpMap.keySet()) {
                String syntaxOID = tmpMap.get(name).getFirst();
                if (syntaxOID != null) {
                    Class<?> cls = OID_SYNTAX_CLASS_MAPPING.get(syntaxOID);
                    if (cls != null) {
                        ATTRIBUTE_DATA_TYPES.put(name, cls);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) Attribute(com.unboundid.ldap.sdk.Attribute) HashMap(java.util.HashMap) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) InvalidSimplePageControlException(org.gluu.persist.ldap.exception.InvalidSimplePageControlException) ConnectionException(org.gluu.persist.exception.operation.ConnectionException) SearchException(org.gluu.persist.exception.operation.SearchException) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) MappingException(org.gluu.persist.exception.mapping.MappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) Pair(org.xdi.util.Pair)

Example 13 with Attribute

use of com.unboundid.ldap.sdk.Attribute 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 14 with Attribute

use of com.unboundid.ldap.sdk.Attribute 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 15 with Attribute

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

the class UBIDMutableEntry method mapToAttrs.

// ZMutableEntry
@Override
public void mapToAttrs(Map<String, Object> mapAttrs) {
    AttributeManager attrMgr = AttributeManager.getInst();
    for (Map.Entry<String, Object> me : mapAttrs.entrySet()) {
        String attrName = me.getKey();
        Object v = me.getValue();
        boolean containsBinaryData = attrMgr == null ? false : attrMgr.containsBinaryData(attrName);
        boolean isBinaryTransfer = attrMgr == null ? false : attrMgr.isBinaryTransfer(attrName);
        if (v instanceof String) {
            ASN1OctetString value = UBIDUtil.newASN1OctetString(containsBinaryData, (String) v);
            Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, value);
            entry.addAttribute(a);
        } else if (v instanceof String[]) {
            String[] sa = (String[]) v;
            ASN1OctetString[] values = new ASN1OctetString[sa.length];
            for (int i = 0; i < sa.length; i++) {
                values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, sa[i]);
            }
            Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
            entry.addAttribute(a);
        } else if (v instanceof Collection) {
            Collection c = (Collection) v;
            ASN1OctetString[] values = new ASN1OctetString[c.size()];
            int i = 0;
            for (Object o : c) {
                values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, o.toString());
                i++;
            }
            Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
            entry.addAttribute(a);
        }
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) AttributeManager(com.zimbra.cs.account.AttributeManager) Attribute(com.unboundid.ldap.sdk.Attribute) Collection(java.util.Collection) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Map(java.util.Map)

Aggregations

Attribute (com.unboundid.ldap.sdk.Attribute)18 ArrayList (java.util.ArrayList)6 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)4 Entry (com.unboundid.ldap.sdk.Entry)3 SearchResult (com.unboundid.ldap.sdk.SearchResult)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 AttributeData (org.gluu.persist.model.AttributeData)3 Test (org.junit.Test)3 TeamModel (com.gitblit.models.TeamModel)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 AddRequest (com.unboundid.ldap.sdk.AddRequest)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)2 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)2 AttributeManager (com.zimbra.cs.account.AttributeManager)2 MappingException (org.gluu.persist.exception.mapping.MappingException)2 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)2 SearchException (org.gluu.persist.exception.operation.SearchException)2 LdapAttribute (org.ldaptive.LdapAttribute)2