use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-fortress-core by apache.
the class RoleDAO method create.
/**
* @param entity
* @return
* @throws CreateException
*/
Role create(Role entity) throws CreateException {
LdapConnection ld = null;
String dn = getDn(entity.getName(), entity.getContextId());
try {
Entry entry = new DefaultEntry(dn);
entry.add(SchemaConstants.OBJECT_CLASS_AT, ROLE_OBJ_CLASS);
entity.setId();
entry.add(GlobalIds.FT_IID, entity.getId());
entry.add(ROLE_NM, entity.getName());
// description field is optional on this object class:
if (StringUtils.isNotEmpty(entity.getDescription())) {
entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
}
// CN attribute is required for this object class:
entry.add(SchemaConstants.CN_AT, entity.getName());
entry.add(GlobalIds.CONSTRAINT, ConstraintUtil.setConstraint(entity));
// These multi-valued attributes are optional. The utility function will return quietly if items are not loaded into collection:
loadAttrs(entity.getParents(), entry, GlobalIds.PARENT_NODES);
ld = getAdminConnection();
add(ld, entry, entity);
} catch (LdapException e) {
String error = "create role [" + entity.getName() + "] caught LdapException=" + e.getMessage();
throw new CreateException(GlobalErrIds.ROLE_ADD_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-fortress-core by apache.
the class OrgUnitDAO method create.
/**
* @param entity
* @return
* @throws org.apache.directory.fortress.core.CreateException
*/
OrgUnit create(OrgUnit entity) throws CreateException {
LdapConnection ld = null;
Dn dn = getDn(entity);
try {
Entry entry = new DefaultEntry(dn);
entry.add(SchemaConstants.OBJECT_CLASS_AT, ORGUNIT_OBJ_CLASS);
entity.setId();
entry.add(GlobalIds.FT_IID, entity.getId());
String description = entity.getDescription();
if (!Strings.isEmpty(description)) {
entry.add(SchemaConstants.DESCRIPTION_AT, description);
}
// organizational name requires OU attribute:
entry.add(SchemaConstants.OU_AT, entity.getName());
// These multi-valued attributes are optional. The utility function will return quietly if no items are loaded into collection:
loadAttrs(entity.getParents(), entry, GlobalIds.PARENT_NODES);
ld = getAdminConnection();
add(ld, entry, entity);
} catch (LdapException e) {
String error = "create orgUnit name [" + entity.getName() + "] type [" + entity.getType() + "] root [" + dn + "] caught LdapException=" + e;
int errCode;
if (entity.getType() == OrgUnit.Type.PERM) {
errCode = GlobalErrIds.ORG_ADD_FAILED_PERM;
} else {
errCode = GlobalErrIds.ORG_ADD_FAILED_USER;
}
throw new CreateException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class AttributesFactory method convert.
/**
* Convert a Syntax instance into an Entry
*
* @param syntax The LdapSytax to convert
* @param schema The schema containing this Syntax
* @param schemaManager The SchemaManager
* @return And entry defining a LdapSyntax
* @throws LdapException If the conversion failed
*/
public Entry convert(LdapSyntax syntax, Schema schema, SchemaManager schemaManager) throws LdapException {
Entry entry = new DefaultEntry(schemaManager);
entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_OC);
entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
injectCommon(syntax, entry, schemaManager);
return entry;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class AttributesFactory method convert.
/**
* Converts a MatchingRuleUse into an Entry
*
* @param matchingRuleUse The MatchingRuleUse to convert
* @param schema The schema containing this MatchingRuleUse
* @param schemaManager The SchemaManager
* @return The converted MatchingRuleUse
*/
public Entry convert(MatchingRuleUse matchingRuleUse, 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 Normalizer instance into an Entry
*
* @param oid The Normalizer's OID
* @param normalizer The Normalizer to convert
* @param schema The schema containing this Normalizer
* @param schemaManager The SchemaManager
* @return An Entry defining a Normalizer
*/
public Entry convert(String oid, Normalizer normalizer, Schema schema, SchemaManager schemaManager) {
Entry entry = new DefaultEntry(schemaManager);
entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_NORMALIZER_OC);
entry.put(MetaSchemaConstants.M_OID_AT, oid);
entry.put(MetaSchemaConstants.M_FQCN_AT, normalizer.getClass().getName());
entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
return entry;
}
Aggregations