javax.naming.ldap.Control Java Examples

The following examples show how to use javax.naming.ldap.Control. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientId.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: DigestClientId.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: LdapReferralException.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: SimpleClientIdHashCode.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #5
Source File: DigestClientId.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: SimpleClientId.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: ClientId.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: UnsolicitedResponseImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: ClientId.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: UnsolicitedResponseImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: UnsolicitedResponseImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: LdapReferralException.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: LdapReferralException.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: SimpleClientIdHashCode.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: DigestClientId.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #16
Source File: SimpleClientId.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #17
Source File: SimpleClientId.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #18
Source File: DigestClientId.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #19
Source File: LdapNamingEnumeration.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected NameClassPair createItem(String dn, Attributes attrs,
        Vector<Control> respCtls) throws NamingException {

    Attribute attr;
    String className = null;

    // use the Java classname if present
    if ((attr = attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME])) != null) {
        className = (String)attr.get();
    } else {
        className = defaultClassName;
    }
    CompositeName cn = new CompositeName();
    cn.add(getAtom(dn));

    NameClassPair ncp;
    if (respCtls != null) {
        ncp = new NameClassPairWithControls(
                    cn.toString(), className,
                    homeCtx.convertControls(respCtls));
    } else {
        ncp = new NameClassPair(cn.toString(), className);
    }
    ncp.setNameInNamespace(dn);
    return ncp;
}
 
Example #20
Source File: ReadOnlyLDAPUserStoreManager.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the controls to navigate to next page.
 *
 * @param controls
 * @return
 */
private static byte[] parseControls(Control[] controls) {

    byte[] cookie = null;
    // Handle the paged results control response
    if (controls != null) {
        for (int i = 0; i < controls.length; i++) {
            if (controls[i] instanceof PagedResultsResponseControl) {
                PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i];
                cookie = prrc.getCookie();
            }
        }
    }
    return cookie;
}
 
Example #21
Source File: DelegatingLdapContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public LdapContext newInitialLdapContext(Hashtable<?, ?> environment, Control[] connCtls) throws NamingException {
    ClassLoader previous = setSocketFactory();
    try {
        return new InitialLdapContext(environment, null);
    } finally {
        unsetSocketFactory(previous);
    }
}
 
Example #22
Source File: ClientId.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static String toStringControls(Control[] ctls) {
    if (ctls == null) {
        return "";
    }
    StringBuffer str = new StringBuffer();
    for (int i = 0; i < ctls.length; i++) {
        str.append(ctls[i].getID());
        str.append(' ');
    }
    return str.toString();
}
 
Example #23
Source File: DelegatingLdapContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void reconnect(Control[] controls) throws NamingException {
    if (!(delegating instanceof LdapContext))
        throw Assert.unsupported();
    ClassLoader previous = setSocketFactory();
    try {
        ((LdapContext) delegating).reconnect(controls);
    } finally {
        unsetSocketFactory(previous);
    }
}
 
Example #24
Source File: Connection.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
synchronized void abandonOutstandingReqs(Control[] reqCtls) {
    LdapRequest ldr = pendingRequests;

    while (ldr != null) {
        abandonRequest(ldr, reqCtls);
        pendingRequests = ldr = ldr.next;
    }
}
 
Example #25
Source File: LdapCtxFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Context getInitialContext(Hashtable<?,?> envprops)
    throws NamingException {

    try {
        String providerUrl = (envprops != null) ?
            (String)envprops.get(Context.PROVIDER_URL) : null;

        // If URL not in environment, use defaults
        if (providerUrl == null) {
            return new LdapCtx("", LdapCtx.DEFAULT_HOST,
                LdapCtx.DEFAULT_PORT, envprops, false);
        }

        // Extract URL(s)
        String[] urls = LdapURL.fromList(providerUrl);

        if (urls.length == 0) {
            throw new ConfigurationException(Context.PROVIDER_URL +
                " property does not contain a URL");
        }

        // Generate an LDAP context
        return getLdapCtxInstance(urls, envprops);

    } catch (LdapReferralException e) {

        if (envprops != null &&
            "throw".equals(envprops.get(Context.REFERRAL))) {
            throw e;
        }

        Control[] bindCtls = (envprops != null)?
            (Control[])envprops.get(LdapCtx.BIND_CONTROLS) : null;

        return (LdapCtx)e.getReferralContext(envprops, bindCtls);
    }
}
 
Example #26
Source File: DelegatingLdapContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public LdapContext newInstance(Control[] requestControls) throws NamingException {
    if (!(delegating instanceof LdapContext))
        throw Assert.unsupported();
    LdapContext newContext = ((LdapContext) delegating).newInstance(requestControls);
    return new DelegatingLdapContext(newContext, socketFactory);
}
 
Example #27
Source File: LdapReferralException.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ||
                handleReferrals == LdapClient.LDAP_REF_FOLLOW_SCHEME ? reqCtls : null);
}
 
Example #28
Source File: ClientId.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static String toStringControls(Control[] ctls) {
    if (ctls == null) {
        return "";
    }
    StringBuffer str = new StringBuffer();
    for (int i = 0; i < ctls.length; i++) {
        str.append(ctls[i].getID());
        str.append(' ');
    }
    return str.toString();
}
 
Example #29
Source File: LdapCtxFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Context getInitialContext(Hashtable<?,?> envprops)
    throws NamingException {

    try {
        String providerUrl = (envprops != null) ?
            (String)envprops.get(Context.PROVIDER_URL) : null;

        // If URL not in environment, use defaults
        if (providerUrl == null) {
            return new LdapCtx("", LdapCtx.DEFAULT_HOST,
                LdapCtx.DEFAULT_PORT, envprops, false);
        }

        // Extract URL(s)
        String[] urls = LdapURL.fromList(providerUrl);

        if (urls.length == 0) {
            throw new ConfigurationException(Context.PROVIDER_URL +
                " property does not contain a URL");
        }

        // Generate an LDAP context
        return getLdapCtxInstance(urls, envprops);

    } catch (LdapReferralException e) {

        if (envprops != null &&
            "throw".equals(envprops.get(Context.REFERRAL))) {
            throw e;
        }

        Control[] bindCtls = (envprops != null)?
            (Control[])envprops.get(LdapCtx.BIND_CONTROLS) : null;

        return (LdapCtx)e.getReferralContext(envprops, bindCtls);
    }
}
 
Example #30
Source File: Connection.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void ldapUnbind(Control[] reqCtls) {

        BerEncoder ber = new BerEncoder(256);
        int unbindMsgId = getMsgId();

        //
        // build the unbind request.
        //

        try {

            ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
                ber.encodeInt(unbindMsgId);
                // IMPLICIT TAGS
                ber.encodeByte(LdapClient.LDAP_REQ_UNBIND);
                ber.encodeByte(0);

                if (v3) {
                    LdapClient.encodeControls(ber, reqCtls);
                }
            ber.endSeq();

            if (traceFile != null) {
                Ber.dumpBER(traceFile, traceTagOut, ber.getBuf(),
                    0, ber.getDataLen());
            }

            synchronized (this) {
                outStream.write(ber.getBuf(), 0, ber.getDataLen());
                outStream.flush();
            }

        } catch (IOException ex) {
            //System.err.println("ldap.unbind: " + ex);
        }

        // Don't expect any response for the unbind request.
    }