use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadMatchingRuleUses.
private void loadMatchingRuleUses(Attribute matchingRuleUses) throws LdapException {
if (matchingRuleUses == null) {
return;
}
for (Value value : matchingRuleUses) {
String desc = value.getValue();
try {
MatchingRuleUse matchingRuleUse = MRU_DESCR_SCHEMA_PARSER.parseMatchingRuleUseDescription(desc);
updateSchemas(matchingRuleUse);
} catch (ParseException pe) {
throw new LdapException(pe);
}
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class BinaryValueTest method initAT.
/**
* Initialize an AttributeType and the associated MatchingRule
* and Syntax
*/
@Before
public void initAT() {
s = EntryUtils.syntaxFactory("1.1.1.1", false);
s.setSyntaxChecker(OctetStringSyntaxChecker.INSTANCE);
mr = EntryUtils.matchingRuleFactory("1.1.2.1");
mr.setSyntax(s);
mr.setLdapComparator(new ByteArrayComparator("1.1.1"));
mr.setNormalizer(new Normalizer("1.1.1") {
public static final long serialVersionUID = 1L;
public String normalize(String value) throws LdapException {
return normalize(value, PrepareString.AssertionType.ATTRIBUTE_VALUE);
}
public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
byte[] val = Strings.getBytesUtf8(value);
// each byte will be changed to be > 0, and spaces will be trimmed
byte[] newVal = new byte[val.length];
int i = 0;
for (byte b : val) {
newVal[i++] = (byte) (b & 0x007F);
}
return Strings.utf8ToString(Strings.trim(newVal));
}
});
at = new MutableAttributeType("1.1.3.1");
at.setEquality(mr);
at.setOrdering(mr);
at.setSubstring(mr);
at.setSyntax(s);
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class ExtendedResponseImplTest method testEqualsDiffImpl.
/**
* Tests for equality using different stub implementations.
*/
@Test
public void testEqualsDiffImpl() {
ExtendedResponseImpl resp0 = createStub();
ExtendedResponse resp1 = new ExtendedResponse() {
public String getResponseName() {
return "1.1.1.1";
}
public void setResponseName(String oid) {
}
public LdapResult getLdapResult() {
LdapResultImpl result = new LdapResultImpl();
try {
result.setMatchedDn(new Dn("dc=example,dc=com"));
} catch (LdapException ine) {
// do nothing
}
result.setResultCode(ResultCodeEnum.SUCCESS);
ReferralImpl refs = new ReferralImpl();
refs.addLdapUrl("ldap://someserver.com");
refs.addLdapUrl("ldap://apache.org");
refs.addLdapUrl("ldap://another.net");
result.setReferral(refs);
return result;
}
public MessageTypeEnum getType() {
return MessageTypeEnum.EXTENDED_RESPONSE;
}
public Map<String, Control> getControls() {
return EMPTY_CONTROL_MAP;
}
public ExtendedResponse addControl(Control control) {
return this;
}
public ExtendedResponse removeControl(Control control) {
return this;
}
public int getMessageId() {
return 45;
}
public Object get(Object a_key) {
return null;
}
public Object put(Object a_key, Object a_value) {
return null;
}
public ExtendedResponse addAllControls(Control[] controls) {
return this;
}
public boolean hasControl(String oid) {
return false;
}
public Control getControl(String oid) {
return null;
}
public ExtendedResponse setMessageId(int messageId) {
return this;
}
};
assertTrue(resp0.equals(resp1));
assertFalse(resp1.equals(resp0));
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class ModifyDnRequestImplTest method getRequest.
/**
* Constructs a ModifyDnrequest to test.
*
* @return the request
*/
private ModifyDnRequestImpl getRequest() {
// Construct the ModifyDn request to test
ModifyDnRequestImpl request = new ModifyDnRequestImpl();
request.setMessageId(45);
request.setDeleteOldRdn(true);
try {
request.setName(new Dn("dc=admins,dc=apache,dc=org"));
request.setNewRdn(new Rdn("dc=administrators"));
request.setNewSuperior(new Dn("dc=groups,dc=apache,dc=org"));
} catch (LdapException ine) {
// do nothing
}
return request;
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class ObjectClassHelper method buildSuperiors.
/**
* Build the references to this ObjectClass SUPERIORS, checking that the type
* hierarchy is correct.
*/
private static void buildSuperiors(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
List<String> superiorOids = objectClass.getSuperiorOids();
if (superiorOids != null) {
objectClass.getSuperiors().clear();
for (String superiorName : superiorOids) {
try {
ObjectClass superior = ocRegistry.lookup(ocRegistry.getOidByName(superiorName));
// Before adding the superior, check that the ObjectClass type is consistent
switch(objectClass.getType()) {
case ABSTRACT:
if (superior.getType() != ObjectClassTypeEnum.ABSTRACT) {
// An ABSTRACT OC can only inherit from ABSTRACT OCs
String msg = I18n.err(I18n.ERR_13766_ABSTRACT_OC_CANNOT_INHERIT_FROM_OC, objectClass.getOid(), superior.getObjectType(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
case AUXILIARY:
if (superior.getType() == ObjectClassTypeEnum.STRUCTURAL) {
// An AUXILIARY OC cannot inherit from STRUCTURAL OCs
String msg = I18n.err(I18n.ERR_13767_AUX_OC_CANNOT_INHERIT_FROM_STRUCT_OC, objectClass.getOid(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
case STRUCTURAL:
if (superior.getType() == ObjectClassTypeEnum.AUXILIARY) {
// A STRUCTURAL OC cannot inherit from AUXILIARY OCs
String msg = I18n.err(I18n.ERR_13768_STRUCT_OC_CANNOT_INHERIT_FROM_AUX_OC, objectClass.getOid(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
default:
throw new IllegalArgumentException(I18n.err(I18n.ERR_13717_UNEXPECTED_OBJECT_CLASS_TYPE_ENUM, objectClass.getType()));
}
objectClass.getSuperiors().add(superior);
} catch (LdapException ne) {
// Cannot find the OC
String msg = I18n.err(I18n.ERR_13769_CANNOT_REGISTER_SUPERIOR_MISSING, objectClass.getOid(), superiorName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, msg, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(superiorName);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
}
}
}
Aggregations