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);
}
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)));
}
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>
* <ldif-file> ::= <ldif-attrval-record> <ldif-attrval-records> |
* <ldif-change-record> <ldif-change-records> <ldif-attrval-record> ::=
* <dn-spec> <sep> <attrval-spec> <attrval-specs> <ldif-change-record> ::=
* <dn-spec> <sep> <controls-e> <changerecord> <dn-spec> ::= "dn:" <fill>
* <distinguishedName> | "dn::" <fill> <base64-distinguishedName>
* <changerecord> ::= "changetype:" <fill> <change-op>
* </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;
}
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);
}
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;
}
}
Aggregations