Java 8 InitialDirContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 InitialDirContext class.

This code example shows how to use the following methods:close, getAttributes
    // 
    String[] parts = hostIp.getHostAddress().split("\\.");
    String reverseIP = parts[3] + "." + parts[2] + "." + parts[1] + "."
      + parts[0] + ".in-addr.arpa";
 
    DirContext ictx = new InitialDirContext();
    Attributes attribute;
    try { 
      attribute = ictx.getAttributes("dns://"               // Use "dns:///" if the default
                         + ((ns == null) ? "" : ns) +
                         // nameserver is to be used 
                         "/" + reverseIP, new String[] { "PTR" });
    } finally { 
      ictx.close();
    } 
 
    String hostname = attribute.get("PTR").get().toString();
    int hostnameLength = hostname.length();
    if (hostname.charAt(hostnameLength - 1) == '.') {
      hostname = hostname.substring(0, hostnameLength - 1);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, rename
     * @param dn 
     * @param attributes 
     * @throws NamingException  
     */ 
    public void modifydn(String dn, String attributes)  throws NamingException{
    	DirContext ctx = new InitialDirContext(env);
	    ctx.rename(dn, attributes);
	    ctx.close();
    } 
     
    public void modify(String dn, int modifytype, String strAttributes, String delimiter, String separator) throws NamingException, PageException {
 
            DirContext context = new InitialDirContext(env);
            String strArrAttributes[] = toStringAttributes(strAttributes,delimiter);
             
            int count = 0;
            for(int i=0; i<strArrAttributes.length; i++) {
                String[] attributesValues = getAttributesValues(strArrAttributes[i], separator);
                if(attributesValues == null)count++;
                else count+=attributesValues.length;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close
    env.put(Context.SECURITY_PRINCIPAL, bindDN);
    env.put(Context.SECURITY_CREDENTIALS, password);
 
    try { 
      // Create initial context 
      Context ctx = new InitialDirContext(env);
      ctx.close();
    } catch (NamingException e) {
      throw new AuthenticationException("Error validating LDAP user", e);
    } 
  } 
 
  private boolean hasDomain(String userName) {
    return (ServiceUtils.indexOfDomainMatch(userName) > 0);
  } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, getAttributes
    // 
    String[] parts = hostIp.getHostAddress().split("\\.");
    String reverseIP = parts[3] + "." + parts[2] + "." + parts[1] + "."
      + parts[0] + ".in-addr.arpa";
 
    DirContext ictx = new InitialDirContext();
    Attributes attribute =
      ictx.getAttributes("dns://"               // Use "dns:///" if the default
                         + ((ns == null) ? "" : ns) + 
                         // nameserver is to be used 
                         "/" + reverseIP, new String[] { "PTR" });
    ictx.close();
     
    return attribute.get("PTR").get().toString();
  } 
 
  /** 
   * Returns all the IPs associated with the provided interface, if any, in 
   * textual form. 
   *  
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getAttributes
   { 
      log.info("IN CHECK DNS!!!!"); 
      Hashtable<String, String> env = new Hashtable<String, String>();
      env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
      env.put("java.naming.provider.url", "dns://localhost:6363");
      DirContext dnsContext = new InitialDirContext(env);
 
      log.info("Check domain: " + domain);
      Attributes attrs1 = dnsContext.getAttributes(domain, new String[]{"TXT"});
      log.info("Attributes size: " + attrs1.size());
      Assert.assertTrue(attrs1 != null);
      Assert.assertTrue(attrs1.size() > 0);
      javax.naming.directory.Attribute txtrecord = attrs1.get("txt");
      log.info("TEXT RECORD: " + txtrecord.get());
   } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, getAttributes
        // 
        String[] parts = hostIp.getHostAddress().split("\\.");
        String reverseIP = parts[3] + "." + parts[2] + "." + parts[1] + "."
                + parts[0] + ".in-addr.arpa";
 
        DirContext ictx = new InitialDirContext();
        Attributes attribute;
        try { 
            attribute = ictx.getAttributes("dns://"               // Use "dns:///" if the default
                    + ((ns == null) ? "" : ns) +
                    // nameserver is to be used 
                    "/" + reverseIP, new String[]{"PTR"});
        } finally { 
            ictx.close();
        } 
 
        return attribute.get("PTR").get().toString();
    } 
 
    /** 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getAttributes
 
		public Boolean call() {
			Hashtable env = new Hashtable();
			env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
			try { 
				DirContext ictx = new InitialDirContext(env);
				Attributes attrs = ictx.getAttributes(_hostName, new String[] { "MX" });
				Attribute attr = attrs.get("MX");
				return attr != null ? Boolean.TRUE : Boolean.FALSE;
			} 
			catch (NameNotFoundException e) {
				return Boolean.FALSE;
			} 
			catch (NamingException e) {
				throw NSForwardException._runtimeExceptionForThrowable(e);
			} 
		} 
 
	} 
 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
                .singleton(partitionConfiguration));
        // Start the Server 
     
        Hashtable<String, String> env = createEnv(principal, credentials);
        env.putAll(cfg.toJndiEnvironment());
        return new InitialDirContext(env);
    } 
     
    /** 
     * Initializes an in-memory LDAP server to use for testing. 
     *  
     * @param allowAnonymous 
     *            anonymous access is allowed or not 
     * @throws Exception 
     */ 
    public static boolean initLdapServer(boolean allowAnonymous, String ldapServerUrl, String basePath) throws Exception {
        return initLdapServer(allowAnonymous, ldapServerUrl, basePath, "data.ldif");
    } 
     
    /** 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
      } 
 
      env.put(Context.SECURITY_PRINCIPAL, bindUser);
      env.put(Context.SECURITY_CREDENTIALS, bindPassword);
 
      ctx = new InitialDirContext(env);
    } 
 
    return ctx;
  } 
   
  /** 
   * Caches groups, no need to do that for this provider 
   */ 
  @Override 
  public void cacheGroupsRefresh() throws IOException {
    // does nothing in this provider of user to groups mapping 
  } 
 
  /**  
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
				env.put(Context.PROVIDER_URL, url);
				env.put(Context.SECURITY_AUTHENTICATION, "Simple");
				env.put(Context.SECURITY_PRINCIPAL, principal);
				env.put(Context.SECURITY_CREDENTIALS, credentials);
		 
				dirContext = new InitialDirContext(env);
			} 
		} 
		catch (Exception e) {
			System.out.println("HazelcastDataStoreLDAP failure");
			e.printStackTrace();
		} 
	} 
	 
	@Override 
	public Object load(Object key) { 
		Object obj = null; 
		 
		try { 
			synchronized (dirContext) {
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 InitialDirContext Methods: