private boolean prepareNextPage(LdapContext ldapContext) throws Exception { Control[] responseControls = ldapContext.getResponseControls(); byte[] cookie = null; if (responseControls != null) { for (Control responseControl : responseControls) { if (responseControl instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) responseControl; cookie = prrc.getCookie(); } } } if (cookie == null) { return false; } else { ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pageSize, cookie, Control.CRITICAL)}); return true; } }
DigestClientId(int version, String hostname, int port, String protocol, Control[] bindCtls, OutputStream trace, String socketFactory, String username, Object passwd, Hashtable<?,?> env) { super(version, hostname, port, protocol, bindCtls, trace, socketFactory, username, passwd); if (env == null) { propvals = null; } else { // Could be smarter and apply default values for props // but for now, we just record and check exact matches propvals = new String[SASL_PROPS.length]; for (int i = 0; i < SASL_PROPS.length; i++) { propvals[i] = (String) env.get(SASL_PROPS[i]); if (propvals[i] != null) { pHash = pHash * 31 + propvals[i].hashCode(); } } } myHash = super.hashCode() + pHash; }
SimpleClientId(int version, String hostname, int port, String protocol, Control[] bindCtls, OutputStream trace, String socketFactory, String username, Object passwd) { super(version, hostname, port, protocol, bindCtls, trace, socketFactory); this.username = username; if (passwd == null) { this.passwd = null; } else if (passwd instanceof String) { this.passwd = passwd; } else if (passwd instanceof byte[]) { this.passwd = ((byte[])passwd).clone(); } else if (passwd instanceof char[]) { this.passwd = ((char[])passwd).clone(); } else { this.passwd = passwd; } myHash = super.hashCode() + (username != null ? username.hashCode() : 0) + (passwd != null ? passwd.hashCode() : 0); }
UnsolicitedResponseImpl(String oid, byte[] berVal, Vector<Vector<String>> ref, int status, String msg, String matchedDN, Control[] controls) { this.oid = oid; this.extensionValue = berVal; if (ref != null && ref.size() > 0) { int len = ref.size(); referrals = new String[len]; for (int i = 0; i < len; i++) { // ref is a list of single-String Vectors referrals[i] = ref.elementAt(i).elementAt(0); } } exception = LdapCtx.mapErrorCode(status, msg); // matchedDN ignored for now; could be used to set resolvedName // exception.setResolvedName(new CompositeName().add(matchedDN)); this.controls = controls; }
private static boolean equalsControls(Control[] a, Control[] b) { if (a == b) { return true; // both null or same } if (a == null || b == null) { return false; // one is non-null } if (a.length != b.length) { return false; } for (int i = 0; i < a.length; i++) { if (!a[i].getID().equals(b[i].getID()) || a[i].isCritical() != b[i].isCritical() || !Arrays.equals(a[i].getEncodedValue(), b[i].getEncodedValue())) { return false; } } return true; }
/** * Constructs a new instance of LdapReferralException. * @param resolvedName The part of the name that has been successfully * resolved. * @param resolvedObj The object to which resolution was successful. * @param remainingName The remaining unresolved portion of the name. * @param explanation Additional detail about this exception. */ LdapReferralException(Name resolvedName, Object resolvedObj, Name remainingName, String explanation, Hashtable<?,?> envprops, String nextName, int handleReferrals, Control[] reqCtls) { super(explanation); if (debug) System.out.println("LdapReferralException constructor"); setResolvedName(resolvedName); setResolvedObj(resolvedObj); setRemainingName(remainingName); this.envprops = envprops; this.nextName = nextName; this.handleReferrals = handleReferrals; // If following referral, request controls are passed to referral ctx this.reqCtls = (handleReferrals == LdapClient.LDAP_REF_FOLLOW ? reqCtls : null); }
/** * Gets a context at which to continue processing. * The supplied environment properties and connection controls are used. */ public Context getReferralContext(Hashtable<?,?> newProps, Control[] connCtls) throws NamingException { if (debug) System.out.println("LdapReferralException.getReferralContext"); LdapReferralContext refCtx = new LdapReferralContext( this, newProps, connCtls, reqCtls, nextName, skipThisReferral, handleReferrals); refCtx.setHopCount(hopCount + 1); if (skipThisReferral) { skipThisReferral = false; // reset } return (Context)refCtx; }
DigestClientId(int version, String hostname, int port, String protocol, Control[] bindCtls, OutputStream trace, String socketFactory, String username, Object passwd, Hashtable<?,?> env) { super(version, hostname, port, protocol, bindCtls, trace, socketFactory, username, passwd); if (env == null) { propvals = null; } else { // Could be smarter and apply default values for props // but for now, we just record and check exact matches propvals = new String[SASL_PROPS.length]; for (int i = 0; i < SASL_PROPS.length; i++) { propvals[i] = (String) env.get(SASL_PROPS[i]); } } myHash = super.hashCode() ^ Arrays.hashCode(propvals); }
SimpleClientId(int version, String hostname, int port, String protocol, Control[] bindCtls, OutputStream trace, String socketFactory, String username, Object passwd) { super(version, hostname, port, protocol, bindCtls, trace, socketFactory); this.username = username; int pwdHashCode = 0; if (passwd == null) { this.passwd = null; } else if (passwd instanceof byte[]) { this.passwd = ((byte[])passwd).clone(); pwdHashCode = Arrays.hashCode((byte[])passwd); } else if (passwd instanceof char[]) { this.passwd = ((char[])passwd).clone(); pwdHashCode = Arrays.hashCode((char[])passwd); } else { this.passwd = passwd; pwdHashCode = passwd.hashCode(); } myHash = super.hashCode() ^ (username != null ? username.hashCode() : 0) ^ pwdHashCode; }
public static void main(String[] args) throws Throwable { Class<?> simpleClientIdClass = Class.forName("com.sun.jndi.ldap.SimpleClientId"); Constructor<?> init = simpleClientIdClass.getDeclaredConstructor( int.class, String.class, int.class, String.class, Control[].class, OutputStream.class, String.class, String.class, Object.class); init.setAccessible(true); Object p1 = new byte[]{66,77}; Object p2 = new char[]{'w','d'}; Object p3 = "word"; test(init, new byte[]{65}, new byte[]{65}); test(init, new char[]{'p'}, new char[]{'p'}); test(init, "pass", "pass"); test(init, p1, p1); test(init, p2, p2); test(init, p3, p3); test(init, null, null); }
private List<SearchResult> pagedSearch(LdapContext ldapContext, String searchFilter) throws Exception { List<SearchResult> data = new ArrayList<SearchResult>(); log.trace("Using paged ldap search, pageSize={}", pageSize); Control[] requestControls = new Control[]{new PagedResultsControl(pageSize, Control.CRITICAL)}; ldapContext.setRequestControls(requestControls); do { List<SearchResult> pageResult = simpleSearch(ldapContext, searchFilter); data.addAll(pageResult); log.trace("Page returned {} entries", pageResult.size()); } while (prepareNextPage(ldapContext)); if (log.isDebugEnabled()) { log.debug("Found a total of {} entries for ldap filter {}", data.size(), searchFilter); } return data; }