@Override public String toString() { return String.format( "[%s@%d::criticality=%s, flags=%s, maxAttributeCount=%s, cookie=%s]", getClass().getName(), hashCode(), getCriticality(), flags, maxAttributeCount, LdapUtils.base64Encode(cookie)); }
/** * Returns the dir sync cookie in the supplied response or null if no cookie exists. * * @param response of a previous dir sync operation * * @return dir sync cookie or null */ protected byte[] getDirSyncCookie(final Response<SearchResult> response) { byte[] cookie = null; final DirSyncControl ctl = (DirSyncControl) response.getControl(DirSyncControl.OID); if (ctl != null) { if (ctl.getCookie() != null && ctl.getCookie().length > 0) { cookie = ctl.getCookie(); } } return cookie; }
/** * Returns the dir sync flags in the supplied response or -1 if no flags exists. * * @param response of a previous dir sync operation * * @return dir sync flags or -1 */ protected long getDirSyncFlags(final Response<SearchResult> response) { long flags = -1; final DirSyncControl ctl = (DirSyncControl) response.getControl(DirSyncControl.OID); if (ctl != null) { flags = ctl.getFlags(); } return flags; }
@Override public int hashCode() { return LdapUtils.computeHashCode(HASH_CODE_SEED, getOID(), getCriticality(), flags, maxAttributeCount, cookie); }
/** * Creates a new dir sync control. * * @param f request flags * @param value dir sync cookie * @param count maximum attribute count * @param critical whether this control is critical */ public DirSyncControl(final Flag[] f, final byte[] value, final int count, final boolean critical) { super(OID, critical); if (f != null) { long l = 0; for (Flag flag : f) { if (flag != null) { l += flag.value(); } } setFlags(l); } setCookie(value); setMaxAttributeCount(count); }
@Override public byte[] encode() { final ConstructedDEREncoder se = new ConstructedDEREncoder( UniversalDERTag.SEQ, new IntegerType(BigInteger.valueOf(getFlags())), new IntegerType(getMaxAttributeCount()), new OctetStringType(getCookie() != null ? getCookie() : EMPTY_COOKIE)); return se.encode(); }
final DirSyncControl c = (DirSyncControl) requestControl; ctl = new AdDirSyncImpl(); ((AdDirSyncImpl) ctl).setCookie(c.getCookie()); ((AdDirSyncImpl) ctl).setFlags(AdDirSyncFlag.getFlags((int) c.getFlags())); ((AdDirSyncImpl) ctl).setMaxReturnLength(c.getMaxAttributeCount()); ctl.setCritical(c.getCriticality()); } else if (VirtualListViewRequestControl.OID.equals(requestControl.getOID())) { final VirtualListViewRequestControl c = (VirtualListViewRequestControl) requestControl;
/** * @param berValue to decode. * @param expected dir sync control to test. * * @throws Exception On test failure. */ @Test(groups = {"control"}, dataProvider = "request-response") public void decode(final byte[] berValue, final DirSyncControl expected) throws Exception { final DirSyncControl actual = new DirSyncControl(expected.getCriticality()); actual.decode(berValue); Assert.assertEquals(actual, expected); } }
/** * Returns the list of request controls configured for this client. * * @param cookie to add to the dir sync control or null * * @return search request controls */ private RequestControl[] createRequestControls(final byte[] cookie) { return new RequestControl[] { new DirSyncControl(dirSyncFlags, cookie, maxAttributeCount, true), new ExtendedDnControl(extendedDnFlag), new ShowDeletedControl(), }; } }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { final byte[] cookie = OctetStringType.readBuffer(encoded); if (cookie != null && cookie.length > 0) { getObject().setCookie(cookie); } } }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setMaxAttributeCount(IntegerType.decode(encoded).intValue()); } }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setFlags(IntegerType.decode(encoded).longValue()); } }
@Override public byte[] encode() { final ConstructedDEREncoder se = new ConstructedDEREncoder( UniversalDERTag.SEQ, new IntegerType(BigInteger.valueOf(getFlags())), new IntegerType(getMaxAttributeCount()), new OctetStringType(getCookie() != null ? getCookie() : EMPTY_COOKIE)); return se.encode(); }
/** * Returns the list of request controls configured for this client. * * @param cookie to add to the dir sync control or null * * @return search request controls */ private RequestControl[] createRequestControls(final byte[] cookie) { return new RequestControl[] { new DirSyncControl(dirSyncFlags, cookie, maxAttributeCount, true), new ExtendedDnControl(extendedDnFlag), new ShowDeletedControl(), }; } }
@Override public int hashCode() { return LdapUtils.computeHashCode(HASH_CODE_SEED, getOID(), getCriticality(), flags, maxAttributeCount, cookie); }
/** * Creates a new dir sync control. * * @param f request flags * @param value dir sync cookie * @param count maximum attribute count * @param critical whether this control is critical */ public DirSyncControl(final Flag[] f, final byte[] value, final int count, final boolean critical) { super(OID, critical); if (f != null) { long l = 0; for (Flag flag : f) { if (flag != null) { l += flag.value(); } } setFlags(l); } setCookie(value); setMaxAttributeCount(count); }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { final byte[] cookie = OctetStringType.readBuffer(encoded); if (cookie != null && cookie.length > 0) { getObject().setCookie(cookie); } } }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setMaxAttributeCount(IntegerType.decode(encoded).intValue()); } }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setFlags(IntegerType.decode(encoded).longValue()); } }
@Override public byte[] encode() { final ConstructedDEREncoder se = new ConstructedDEREncoder( UniversalDERTag.SEQ, new IntegerType(BigInteger.valueOf(getFlags())), new IntegerType(getMaxAttributeCount()), new OctetStringType(getCookie() != null ? getCookie() : EMPTY_COOKIE)); return se.encode(); }