use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class AttributesFactory method convert.
/**
* Converts a NameForm into an Entry
*
* @param nameForm The NameForm to convert
* @param schema The schema containing this NameForm
* @param schemaManager The SchemaManager
* @return The converted NameForm
*/
public Entry convert(NameForm nameForm, Schema schema, SchemaManager schemaManager) {
Entry entry = new DefaultEntry(schemaManager);
entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "");
entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
return entry;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class AttributesFactory method convert.
/**
* Convert a LdapComparator instance into an Entry
*
* @param oid The LdapComparator's OID
* @param comparator The LdapComparator to convert
* @param schema The schema containing this Comparator
* @param schemaManager The SchemaManager
* @return An Entry defining a LdapComparator
*/
public Entry convert(String oid, LdapComparator<? super Object> comparator, Schema schema, SchemaManager schemaManager) {
Entry entry = new DefaultEntry(schemaManager);
entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC);
entry.put(MetaSchemaConstants.M_OID_AT, oid);
entry.put(MetaSchemaConstants.M_FQCN_AT, comparator.getClass().getName());
entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
return entry;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class LdifAttributesReader method parseEntry.
/**
* Parse a ldif file. The following rules are processed :
*
* <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>
*
* @param schemaManager The SchemaManager
* @return The read entry
* @throws LdapLdifException If the entry can't be read or is invalid
*/
private Entry parseEntry(SchemaManager schemaManager) throws LdapLdifException {
if ((lines == null) || lines.isEmpty()) {
LOG.debug(I18n.msg(I18n.MSG_13408_END_OF_LDIF));
return null;
}
Entry entry = new DefaultEntry(schemaManager);
// 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) {
parseEntryAttribute(schemaManager, entry, 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, entry));
return entry;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class LdifAttributesReader method parseEntry.
/**
* A method which parses a ldif string and returns an Entry.
*
* @param schemaManager The SchemaManager
* @param ldif The ldif string
* @return An entry
* @throws LdapLdifException If something went wrong
*/
public Entry parseEntry(SchemaManager schemaManager, String ldif) throws LdapLdifException {
lines = new ArrayList<String>();
position = 0;
LOG.debug(I18n.msg(I18n.MSG_13407_STARTS_PARSING_LDIF));
if (Strings.isEmpty(ldif)) {
return new DefaultEntry(schemaManager);
}
StringReader strIn = new StringReader(ldif);
reader = new BufferedReader(strIn);
try {
readLines();
Entry entry = parseEntry(schemaManager);
if (LOG.isDebugEnabled()) {
if (entry == null) {
LOG.debug(I18n.msg(I18n.MSG_13401_PARSED_NO_ENTRY));
} else {
LOG.debug(I18n.msg(I18n.MSG_13402_PARSED_ONE_ENTRY));
}
}
return entry;
} catch (LdapLdifException ne) {
LOG.error(I18n.err(I18n.ERR_13403_CANNOT_PARSE_LDIF_BUFFER, ne.getLocalizedMessage()));
throw new LdapLdifException(I18n.err(I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER), ne);
} finally {
try {
reader.close();
} catch (IOException ioe) {
throw new LdapLdifException(I18n.err(I18n.ERR_13450_CANNOT_CLOSE_FILE), ioe);
}
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-fortress-core by apache.
the class PermDAO method createObject.
/**
* @param entity
* @return
* @throws org.apache.directory.fortress.core.CreateException
*/
PermObj createObject(PermObj entity) throws CreateException {
LdapConnection ld = null;
String dn = getDn(entity, entity.getContextId());
try {
Entry entry = new DefaultEntry(dn);
entry.add(SchemaConstants.OBJECT_CLASS_AT, PERM_OBJ_OBJ_CLASS);
entry.add(GlobalIds.POBJ_NAME, entity.getObjName());
// this will generatre a new random, unique id on this entity:
entity.setInternalId();
// create the rDN:
entry.add(GlobalIds.FT_IID, entity.getInternalId());
// ou is required:
entry.add(SchemaConstants.OU_AT, entity.getOu());
// description is optional:
if (StringUtils.isNotEmpty(entity.getDescription())) {
entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
}
// type is optional:
if (StringUtils.isNotEmpty(entity.getType())) {
entry.add(GlobalIds.TYPE, entity.getType());
}
// if the props is null don't try to load these attributes
if (PropUtil.isNotEmpty(entity.getProperties())) {
loadProperties(entity.getProperties(), entry, GlobalIds.PROPS);
}
// now add the new entry to directory:
ld = getAdminConnection();
add(ld, entry, entity);
entity.setDn(dn);
} catch (LdapException e) {
String error = "createObject perm obj [" + entity.getObjName() + "] caught LdapException=" + e.getMessage();
throw new CreateException(GlobalErrIds.PERM_ADD_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
Aggregations