Search in sources :

Example 86 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project java-driver by datastax.

the class EC2MultiRegionAddressTranslatorTest method should_return_same_address_when_no_entry_found.

@Test(groups = "unit")
public void should_return_same_address_when_no_entry_found() throws Exception {
    InitialDirContext mock = mock(InitialDirContext.class);
    when(mock.getAttributes(anyString(), any(String[].class))).thenReturn(new BasicAttributes());
    EC2MultiRegionAddressTranslator translator = new EC2MultiRegionAddressTranslator(mock);
    InetSocketAddress address = new InetSocketAddress("192.0.2.5", 9042);
    assertThat(translator.translate(address)).isEqualTo(address);
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) InetSocketAddress(java.net.InetSocketAddress) InitialDirContext(javax.naming.directory.InitialDirContext) Test(org.testng.annotations.Test)

Example 87 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project fess by codelibs.

the class LdapManager method addUserAttributes.

protected void addUserAttributes(final BasicAttributes entry, final User user) {
    entry.put(new BasicAttribute("cn", user.getName()));
    entry.put(new BasicAttribute("userPassword", user.getOriginalPassword()));
    OptionalUtil.ofNullable(user.getSurname()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrSurname(), s)));
    OptionalUtil.ofNullable(user.getGivenName()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrGivenName(), s)));
    OptionalUtil.ofNullable(user.getMail()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrMail(), s)));
    OptionalUtil.ofNullable(user.getEmployeeNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrEmployeeNumber(), s)));
    OptionalUtil.ofNullable(user.getTelephoneNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrTelephoneNumber(), s)));
    OptionalUtil.ofNullable(user.getHomePhone()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrHomePhone(), s)));
    OptionalUtil.ofNullable(user.getHomePostalAddress()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrHomePostalAddress(), s)));
    OptionalUtil.ofNullable(user.getLabeledURI()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrLabeledURI(), s)));
    OptionalUtil.ofNullable(user.getRoomNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrRoomNumber(), s)));
    OptionalUtil.ofNullable(user.getDescription()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDescription(), s)));
    OptionalUtil.ofNullable(user.getTitle()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrTitle(), s)));
    OptionalUtil.ofNullable(user.getPager()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPager(), s)));
    OptionalUtil.ofNullable(user.getStreet()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrStreet(), s)));
    OptionalUtil.ofNullable(user.getPostalCode()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPostalCode(), s)));
    OptionalUtil.ofNullable(user.getPhysicalDeliveryOfficeName()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPhysicalDeliveryOfficeName(), s)));
    OptionalUtil.ofNullable(user.getDestinationIndicator()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDestinationIndicator(), s)));
    OptionalUtil.ofNullable(user.getInternationaliSDNNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrInternationaliSDNNumber(), s)));
    OptionalUtil.ofNullable(user.getState()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrState(), s)));
    OptionalUtil.ofNullable(user.getEmployeeType()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrEmployeeType(), s)));
    OptionalUtil.ofNullable(user.getFacsimileTelephoneNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrFacsimileTelephoneNumber(), s)));
    OptionalUtil.ofNullable(user.getPostOfficeBox()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPostOfficeBox(), s)));
    OptionalUtil.ofNullable(user.getInitials()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrInitials(), s)));
    OptionalUtil.ofNullable(user.getCarLicense()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrCarLicense(), s)));
    OptionalUtil.ofNullable(user.getMobile()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrMobile(), s)));
    OptionalUtil.ofNullable(user.getPostalAddress()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPostalAddress(), s)));
    OptionalUtil.ofNullable(user.getCity()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrCity(), s)));
    OptionalUtil.ofNullable(user.getTeletexTerminalIdentifier()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrTeletexTerminalIdentifier(), s)));
    OptionalUtil.ofNullable(user.getX121Address()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrX121Address(), s)));
    OptionalUtil.ofNullable(user.getBusinessCategory()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrBusinessCategory(), s)));
    OptionalUtil.ofNullable(user.getRegisteredAddress()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrRegisteredAddress(), s)));
    OptionalUtil.ofNullable(user.getDisplayName()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDisplayName(), s)));
    OptionalUtil.ofNullable(user.getPreferredLanguage()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPreferredLanguage(), s)));
    OptionalUtil.ofNullable(user.getDepartmentNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDepartmentNumber(), s)));
    OptionalUtil.ofNullable(user.getUidNumber()).filter(s -> StringUtil.isNotBlank(s.toString())).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrUidNumber(), s)));
    OptionalUtil.ofNullable(user.getGidNumber()).filter(s -> StringUtil.isNotBlank(s.toString())).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrGidNumber(), s)));
    OptionalUtil.ofNullable(user.getHomeDirectory()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrHomeDirectory(), s)));
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) Constants(org.codelibs.fess.Constants) NamingException(javax.naming.NamingException) User(org.codelibs.fess.es.user.exentity.User) Supplier(java.util.function.Supplier) SearchControls(javax.naming.directory.SearchControls) ArrayList(java.util.ArrayList) InitialDirContext(javax.naming.directory.InitialDirContext) HashSet(java.util.HashSet) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) Role(org.codelibs.fess.es.user.exentity.Role) LdapConfigurationException(org.codelibs.fess.exception.LdapConfigurationException) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Locale(java.util.Locale) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) FessUser(org.codelibs.fess.entity.FessUser) Context(javax.naming.Context) Hashtable(java.util.Hashtable) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalUtil(org.codelibs.fess.util.OptionalUtil) OptionalEntity(org.dbflute.optional.OptionalEntity) LdapOperationException(org.codelibs.fess.exception.LdapOperationException) DirContext(javax.naming.directory.DirContext) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) BasicAttributes(javax.naming.directory.BasicAttributes) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DfTypeUtil(org.dbflute.util.DfTypeUtil) Attributes(javax.naming.directory.Attributes) SystemHelper(org.codelibs.fess.helper.SystemHelper) PostConstruct(javax.annotation.PostConstruct) TimeoutManager(org.codelibs.core.timer.TimeoutManager) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) SearchResult(javax.naming.directory.SearchResult) Group(org.codelibs.fess.es.user.exentity.Group)

Example 88 with BasicAttributes

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

the class LdifAttributesReader method parseAttributes.

/**
 * Parse a ldif file. The following rules are processed :
 *
 * <pre>
 * &lt;ldif-file&gt; ::= &lt;ldif-attrval-record&gt; &lt;ldif-attrval-records&gt; |
 * &lt;ldif-change-record&gt; &lt;ldif-change-records&gt; &lt;ldif-attrval-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;attrval-spec&gt; &lt;attrval-specs&gt; &lt;ldif-change-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;controls-e&gt; &lt;changerecord&gt; &lt;dn-spec&gt; ::= "dn:" &lt;fill&gt;
 * &lt;distinguishedName&gt; | "dn::" &lt;fill&gt; &lt;base64-distinguishedName&gt;
 * &lt;changerecord&gt; ::= "changetype:" &lt;fill&gt; &lt;change-op&gt;
 * </pre>
 *
 * @return The read entry
 * @throws LdapLdifException If the entry can't be read or is invalid
 */
private Attributes parseAttributes() throws LdapLdifException {
    if ((lines == null) || lines.isEmpty()) {
        LOG.debug(I18n.msg(I18n.MSG_13408_END_OF_LDIF));
        return null;
    }
    Attributes attributes = new BasicAttributes(true);
    // Now, let's iterate through the other lines
    for (String line : lines) {
        // Each line could start either with an OID, an attribute type, with
        // "control:" or with "changetype:"
        String lowerLine = Strings.toLowerCaseAscii(line);
        // 3) The first line after the Dn is anything else
        if (lowerLine.startsWith("control:")) {
            LOG.error(I18n.err(I18n.ERR_13401_CHANGE_NOT_ALLOWED));
            throw new LdapLdifException(I18n.err(I18n.ERR_13440_NO_CHANGE));
        } else if (lowerLine.startsWith("changetype:")) {
            LOG.error(I18n.err(I18n.ERR_13401_CHANGE_NOT_ALLOWED));
            throw new LdapLdifException(I18n.err(I18n.ERR_13440_NO_CHANGE));
        } else if (line.indexOf(':') > 0) {
            parseAttribute(attributes, line, lowerLine);
        } else {
            // Invalid attribute Value
            LOG.error(I18n.err(I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE));
            throw new LdapLdifException(I18n.err(I18n.ERR_13441_BAD_ATTRIBUTE));
        }
    }
    LOG.debug(I18n.msg(I18n.MSG_13405_READ_ATTR, attributes));
    return attributes;
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 89 with BasicAttributes

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

the class TriggerUtils method createTriggerExecutionSubentry.

/**
 * Create the Trigger execution subentry
 *
 * @param apCtx The administration point context
 * @param subentryCN The CN used by the suentry
 * @param subtreeSpec The subtree specification
 * @param prescriptiveTriggerSpec The prescriptive trigger specification
 * @throws NamingException If the operation failed
 */
public static void createTriggerExecutionSubentry(LdapContext apCtx, String subentryCN, String subtreeSpec, String prescriptiveTriggerSpec) throws NamingException {
    Attributes subentry = new BasicAttributes(SchemaConstants.CN_AT, subentryCN, true);
    Attribute objectClass = new BasicAttribute(SchemaConstants.OBJECT_CLASS_AT);
    subentry.put(objectClass);
    objectClass.add(SchemaConstants.TOP_OC);
    objectClass.add(SchemaConstants.SUBENTRY_OC);
    objectClass.add(SchemaConstants.TRIGGER_EXECUTION_SUBENTRY_OC);
    subentry.put(SchemaConstants.SUBTREE_SPECIFICATION_AT, subtreeSpec);
    subentry.put(SchemaConstants.PRESCRIPTIVE_TRIGGER_SPECIFICATION_AT, prescriptiveTriggerSpec);
    apCtx.createSubcontext("cn=" + subentryCN, subentry);
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) Attributes(javax.naming.directory.Attributes) BasicAttributes(javax.naming.directory.BasicAttributes)

Example 90 with BasicAttributes

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

the class AttributeUtils method toCaseInsensitive.

/**
 * Check if the attributes is a BasicAttributes, and if so, switch
 * the case sensitivity to false to avoid tricky problems in the server.
 * (Ldap attributeTypes are *always* case insensitive)
 *
 * @param attributes The Attributes to check
 * @return The modified Attributes
 */
public static Attributes toCaseInsensitive(Attributes attributes) {
    if (attributes == null) {
        return attributes;
    }
    if (attributes instanceof BasicAttributes) {
        if (attributes.isCaseIgnored()) {
            // Just do nothing if the Attributes is already case insensitive
            return attributes;
        } else {
            // Ok, bad news : we have to create a new BasicAttributes
            // which will be case insensitive
            Attributes newAttrs = new BasicAttributes(true);
            NamingEnumeration<?> attrs = attributes.getAll();
            if (attrs != null) {
                // Iterate through the attributes now
                while (attrs.hasMoreElements()) {
                    newAttrs.put((javax.naming.directory.Attribute) attrs.nextElement());
                }
            }
            return newAttrs;
        }
    } else {
        // we can safely return the attributes if it's not a BasicAttributes
        return attributes;
    }
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

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