use of org.apache.directory.api.ldap.model.filter.PresenceNode in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestPresentNoControls.
/**
* Test the decoding of a SearchRequest with no controls. Test the present
* filter : =* The search filter is :
* (&(|(objectclass=*)(ou=*))(!(objectclass>=ttt)))
*/
@Test
public void testDecodeSearchRequestPresentNoControls() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x7B);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x79, 0x02, 0x01, // messageID MessageID
0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
0x74, // SearchRequest ::= APPLICATION[3] SEQUENCE {
0x04, // baseObject LDAPDN,
0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope
0x01, // wholeSubtree (2) },
0x0A, 0x01, // derefAliases ENUMERATED {
0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
(byte) 0xFF, // filter Filter,
(byte) 0xA0, // Filter ::= CHOICE {
0x29, // and [0] SET OF Filter,
(byte) 0xA1, // or [1] SET of Filter,
0x11, (byte) 0x87, // present [7] AttributeDescription,
0x0B, // AttributeDescription ::= LDAPString
'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
(byte) 0x87, 0x02, 'o', // present [7]
'u', // AttributeDescription ::= LDAPString
(byte) 0xA2, // not [2] Filter,
0x14, (byte) 0xA5, // greaterOrEqual [5]
0x12, // attributeDesc AttributeDescription (LDAPString),
0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
0x04, 0x03, 't', 't', 't', // attributes AttributeDescriptionList }
0x30, // AttributeDescriptionList ::= SEQUENCE OF
0x15, // AttributeDescription
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
'0', // ::= LDAPString
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
'1', // ::= LDAPString
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
'2' // LDAPString
});
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
SearchRequest searchRequest = ldapMessageContainer.getMessage();
assertEquals(1, searchRequest.getMessageId());
assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
assertEquals(1000, searchRequest.getSizeLimit());
assertEquals(1000, searchRequest.getTimeLimit());
assertEquals(true, searchRequest.getTypesOnly());
// (& (...
ExprNode filter = searchRequest.getFilter();
AndNode andNode = (AndNode) filter;
assertNotNull(andNode);
List<ExprNode> andNodes = andNode.getChildren();
// (& (| (...
assertEquals(2, andNodes.size());
OrNode orFilter = (OrNode) andNodes.get(0);
assertNotNull(orFilter);
// (& (| (objectclass=*) (...
List<ExprNode> orNodes = orFilter.getChildren();
assertEquals(2, orNodes.size());
PresenceNode presenceNode = (PresenceNode) orNodes.get(0);
assertNotNull(presenceNode);
assertEquals("objectclass", presenceNode.getAttribute());
// (& (| (objectclass=*) (ou=*) ) (...
presenceNode = (PresenceNode) orNodes.get(1);
assertNotNull(presenceNode);
assertEquals("ou", presenceNode.getAttribute());
// (& (| (objectclass=*) (ou=*) ) (! ...
NotNode notNode = (NotNode) andNodes.get(1);
assertNotNull(notNode);
// (& (| (objectclass=*) (ou=*) ) (! (objectclass>=ttt) ) )
GreaterEqNode<?> greaterOrEqual = (GreaterEqNode<?>) notNode.getFirstChild();
assertNotNull(greaterOrEqual);
assertEquals("objectclass", greaterOrEqual.getAttribute());
assertEquals("ttt", greaterOrEqual.getValue().getValue());
// The attributes
List<String> attributes = searchRequest.getAttributes();
for (String attribute : attributes) {
assertNotNull(attribute);
}
// attributes may have been reordered
try {
ByteBuffer bb = encoder.encodeMessage(searchRequest);
// Check the length
assertEquals(0x7B, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu.substring(0, 0x6C), decodedPdu.substring(0, 0x6C));
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.model.filter.PresenceNode in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestRootDse.
/**
* Test the decoding of a SearchRequest
* for rootDSE
*/
@Test
public void testDecodeSearchRequestRootDse() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x33);
stream.put(new byte[] { 0x30, (byte) 0x84, 0x00, 0x00, 0x00, 0x2D, 0x02, 0x01, 0x01, 0x63, (byte) 0x84, 0x00, 0x00, 0x00, 0x24, 0x04, 0x00, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, 0x00, (byte) 0x87, 0x0B, 0x6F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x30, (byte) 0x84, 0x00, 0x00, 0x00, 0x00 });
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
SearchRequest searchRequest = ldapMessageContainer.getMessage();
assertEquals(1, searchRequest.getMessageId());
assertEquals("", searchRequest.getBase().toString());
assertEquals(SearchScope.OBJECT, searchRequest.getScope());
assertEquals(AliasDerefMode.NEVER_DEREF_ALIASES, searchRequest.getDerefAliases());
assertEquals(0, searchRequest.getSizeLimit());
assertEquals(0, searchRequest.getTimeLimit());
assertEquals(false, searchRequest.getTypesOnly());
ExprNode filter = searchRequest.getFilter();
PresenceNode presenceNode = (PresenceNode) filter;
assertNotNull(presenceNode);
assertEquals("objectClass", presenceNode.getAttribute());
List<String> attributes = searchRequest.getAttributes();
assertEquals(0, attributes.size());
}
use of org.apache.directory.api.ldap.model.filter.PresenceNode in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestWithStarAndAttr.
/**
* Test the decoding of a SearchRequest with a star and an attribute. The search
* filter is : (objectclass=*)
*/
@Test
public void testDecodeSearchRequestWithStarAndAttr() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x40);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x3E, 0x02, 0x01, // messageID MessageID
0x03, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
0x39, // SearchRequest ::= APPLICATION[3] SEQUENCE {
0x04, // baseObject LDAPDN,
0x12, 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x0A, 0x01, // scope ENUMERATED {
0x00, // wholeSubtree (2) },
0x0A, 0x01, // derefAliases ENUMERATED {
0x03, // sizeLimit INTEGER (0 .. maxInt), (infinite)
0x02, 0x01, // timeLimit INTEGER (0 .. maxInt), (infinite)
0x00, 0x02, 0x01, 0x00, 0x01, 0x01, // typesOnly
0x00, // Filter ::= CHOICE {
(byte) 0x87, // present [7] AttributeDescription,
0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's', // attributes AttributeDescriptionList }
0x30, // AttributeDescriptionList ::= SEQUENCE OF
0x07, // AttributeDescription
0x04, // Request for sn
0x02, 's', 'n', 0x04, 0x01, // * attribute
'*' });
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
SearchRequest searchRequest = ldapMessageContainer.getMessage();
assertEquals(3, searchRequest.getMessageId());
assertEquals("ou=users,ou=system", searchRequest.getBase().toString());
assertEquals(SearchScope.OBJECT, searchRequest.getScope());
assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
assertEquals(0, searchRequest.getSizeLimit());
assertEquals(0, searchRequest.getTimeLimit());
assertEquals(false, searchRequest.getTypesOnly());
// (objectClass = *)
ExprNode filter = searchRequest.getFilter();
PresenceNode presenceNode = (PresenceNode) filter;
assertNotNull(presenceNode);
assertEquals("objectClass", presenceNode.getAttribute());
// The attributes
List<String> attributes = searchRequest.getAttributes();
assertEquals(2, attributes.size());
Set<String> expectedAttrs = new HashSet<String>();
expectedAttrs.add("sn");
expectedAttrs.add("*");
for (String attribute : attributes) {
assertTrue(expectedAttrs.contains(attribute));
expectedAttrs.remove(attribute);
}
assertEquals(0, expectedAttrs.size());
}
use of org.apache.directory.api.ldap.model.filter.PresenceNode in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestOneEmptyAttribute.
/**
* Test the decoding of a SearchRequest with an empty attribute. The search
* filter is : (objectclass=*)
*/
@Test
public void testDecodeSearchRequestOneEmptyAttribute() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x3F);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x3D, 0x02, 0x01, // messageID MessageID
0x03, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
0x38, // SearchRequest ::= APPLICATION[3] SEQUENCE {
0x04, // baseObject LDAPDN,
0x12, 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x0A, 0x01, // scope ENUMERATED {
0x00, // wholeSubtree (2) },
0x0A, 0x01, // derefAliases ENUMERATED {
0x03, // sizeLimit INTEGER (0 .. maxInt), (infinite)
0x02, 0x01, // timeLimit INTEGER (0 .. maxInt), (infinite)
0x00, 0x02, 0x01, 0x00, 0x01, 0x01, // typesOnly
0x00, // Filter ::= CHOICE {
(byte) 0x87, // present [7] AttributeDescription,
0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's', // attributes AttributeDescriptionList }
0x30, // AttributeDescriptionList ::= SEQUENCE OF
0x06, // AttributeDescription
0x04, // Request for sn
0x02, 's', 'n', 0x04, // Empty attribute
0x00 });
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
SearchRequest searchRequest = ldapMessageContainer.getMessage();
assertEquals(3, searchRequest.getMessageId());
assertEquals("ou=users,ou=system", searchRequest.getBase().toString());
assertEquals(SearchScope.OBJECT, searchRequest.getScope());
assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
assertEquals(0, searchRequest.getSizeLimit());
assertEquals(0, searchRequest.getTimeLimit());
assertEquals(false, searchRequest.getTypesOnly());
// (objectClass = *)
ExprNode filter = searchRequest.getFilter();
PresenceNode presenceNode = (PresenceNode) filter;
assertNotNull(presenceNode);
assertEquals("objectClass", presenceNode.getAttribute());
// The attributes
List<String> attributes = searchRequest.getAttributes();
assertEquals(1, attributes.size());
}
use of org.apache.directory.api.ldap.model.filter.PresenceNode in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestSubEntryControl.
/**
* Test the decoding of a SearchRequest with SubEntry control.
*/
@Test
public void testDecodeSearchRequestSubEntryControl() {
byte[] asn1BER = new byte[] { 0x30, 0x5D, 0x02, 0x01, // messageID
0x04, 0x63, 0x33, 0x04, // baseObject: dc=my-domain,dc=com
0x13, 'd', 'c', '=', 'm', 'y', '-', 'd', 'o', 'm', 'a', 'i', 'n', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0a, 0x01, // scope: subtree
0x02, 0x0a, 0x01, // derefAliases: derefAlways
0x03, 0x02, 0x01, // sizeLimit: 0
0x00, 0x02, 0x01, // timeLimit: 0
0x00, 0x01, 0x01, // typesOnly: false
0x00, (byte) 0x87, // filter: (objectClass=*)
0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's', 0x30, 0x00, (byte) 0xa0, // controls
0x23, 0x30, 0x21, 0x04, 0x17, '1', '.', '3', '.', '6', '.', '1', '.', '4', '.', '1', '.', '4', '2', '0', '3', '.', '1', '.', '1', '0', '.', // SubEntry OID
'1', 0x01, 0x01, // criticality: true
(byte) 0xFF, 0x04, 0x03, 0x01, 0x01, // SubEntry visibility
(byte) 0xFF };
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
stream.put(asn1BER);
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
SearchRequest searchRequest = ldapMessageContainer.getMessage();
assertEquals(4, searchRequest.getMessageId());
assertEquals(1, searchRequest.getControls().size());
// SubEntry Control
String subEntryControlOID = "1.3.6.1.4.1.4203.1.10.1";
Control subEntryControl = searchRequest.getControl(subEntryControlOID);
assertEquals(subEntryControlOID, subEntryControl.getOid());
assertTrue(subEntryControl.isCritical());
assertTrue(subEntryControl instanceof SubentriesDecorator);
assertTrue(((SubentriesDecorator) subEntryControl).getDecorated().isVisible());
assertEquals("dc=my-domain,dc=com", searchRequest.getBase().toString());
assertEquals(SearchScope.SUBTREE, searchRequest.getScope());
assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
assertEquals(0, searchRequest.getSizeLimit());
assertEquals(0, searchRequest.getTimeLimit());
assertEquals(false, searchRequest.getTypesOnly());
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof PresenceNode);
assertEquals("objectClass", ((PresenceNode) filter).getAttribute());
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(searchRequest);
// Check the length
assertEquals(0x5F, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(decodedPdu, encodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations