javax.naming.directory.InitialDirContext#addToEnvironment ( )源码实例Demo

下面列出了javax.naming.directory.InitialDirContext#addToEnvironment ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Openfire   文件: LdapManager.java
/**
 * Looks up an LDAP object by its DN and returns {@code true} if
 * the search was successful.
 *
 * @param ctx the Context to use for the lookup.
 * @param dn the object's dn to lookup.
 * @return true if the lookup was successful.
 * @throws NamingException if login credentials were wrong.
 */
private Boolean lookupExistence(InitialDirContext ctx, LdapName dn, String[] returnattrs) throws NamingException {
    Log.debug("In lookupExistence(ctx, dn, returnattrs), searchdn is: {}", dn);

    // Bind to the object's DN
    ctx.addToEnvironment(Context.PROVIDER_URL, getProviderURL(dn));

    String filter = "(&(objectClass=*))";
    SearchControls srcnt = new SearchControls();
    srcnt.setSearchScope(SearchControls.OBJECT_SCOPE);
    srcnt.setReturningAttributes(returnattrs);

    NamingEnumeration<SearchResult> answer = null;

    try {
        answer = ctx.search(
                "",
                filter,
                srcnt);
    } catch (javax.naming.NameNotFoundException nex) {
        Log.debug("Unable to find ldap object {}.", dn);
    }

    if (answer == null || !answer.hasMoreElements())
    {
        Log.debug(".... lookupExistence: DN not found.");
        return false;
    }
    else
    {
        Log.debug(".... lookupExistence: DN found.");
        return true;
    }
}
 
源代码2 项目: dragonwell8_jdk   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "throw");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码3 项目: TencentKona-8   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "throw");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码4 项目: jdk8u60   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "follow");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码5 项目: openjdk-jdk8u   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "throw");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "throw");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码7 项目: jdk8u-jdk   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "follow");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码8 项目: hottub   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "follow");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码9 项目: openjdk-8-source   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "follow");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码10 项目: openjdk-8   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "follow");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码11 项目: jdk8u_jdk   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "throw");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码12 项目: jdk8u-jdk   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "follow");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}
 
源代码13 项目: jdk8u-dev-jdk   文件: LDAPCertStore.java
/**
 * Create InitialDirContext.
 *
 * @param server Server DNS name hosting LDAP service
 * @param port   Port at which server listens for requests
 * @throws InvalidAlgorithmParameterException if creation fails
 */
private void createInitialDirContext(String server, int port)
        throws InvalidAlgorithmParameterException {
    String url = "ldap://" + server + ":" + port;
    Hashtable<String,Object> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    // If property is set to true, disable application resource file lookup.
    boolean disableAppResourceFiles = AccessController.doPrivileged(
        new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
    if (disableAppResourceFiles) {
        if (debug != null) {
            debug.println("LDAPCertStore disabling app resource files");
        }
        env.put("com.sun.naming.disable.app.resource.files", "true");
    }

    try {
        ctx = new InitialDirContext(env);
        /*
         * By default, follow referrals unless application has
         * overridden property in an application resource file.
         */
        Hashtable<?,?> currentEnv = ctx.getEnvironment();
        if (currentEnv.get(Context.REFERRAL) == null) {
            ctx.addToEnvironment(Context.REFERRAL, "follow");
        }
    } catch (NamingException e) {
        if (debug != null) {
            debug.println("LDAPCertStore.engineInit about to throw "
                + "InvalidAlgorithmParameterException");
            e.printStackTrace();
        }
        Exception ee = new InvalidAlgorithmParameterException
            ("unable to create InitialDirContext using supplied parameters");
        ee.initCause(e);
        throw (InvalidAlgorithmParameterException)ee;
    }
}