List of usage examples for javax.naming.directory BasicAttributes BasicAttributes
public BasicAttributes(boolean ignoreCase)
From source file:Main.java
public static void main(String[] argv) throws Exception { Attributes attrs = new BasicAttributes(true); Attribute objclass = new BasicAttribute("objectclass"); objclass.add("top"); objclass.add("extensible"); attrs.put(objclass);/* w w w .j a v a 2 s. c o m*/ Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); Context entry = ctx.createSubcontext("cn=Sample", attrs); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Attributes attrs = new BasicAttributes(true); Attribute objclass = new BasicAttribute("objectclass"); objclass.add("top"); objclass.add("extensible"); attrs.put(objclass);//from w w w . j a v a2s. com Object obj = "yourObject"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); ctx.bind("cn=Sample", obj, attrs); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("sn", "YourName")); matchAttrs.put(new BasicAttribute("mail")); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); NamingEnumeration e = ctx.search("ou=People", matchAttrs); if (e.hasMore()) { SearchResult entry = (SearchResult) e.next(); // Abandon rest of results e.close();// ww w .j a va2 s .c o m } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] attrIDs = { "sn", "number", "value", "mail" }; Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("sn", "YourName")); matchAttrs.put(new BasicAttribute("mail")); Object obj = "yourObject"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); NamingEnumeration e = ctx.search("ou=People", matchAttrs, attrIDs); while (e.hasMore()) { SearchResult entry = (SearchResult) e.next(); System.out.println(entry.getName()); }/*ww w.ja v a 2 s. c o m*/ }
From source file:Modify1Example.java
public static void main(String args[]) { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); try {/* www . j a v a 2 s . c o m*/ DirContext dctx = new InitialDirContext(env); Attributes attrs = new BasicAttributes(true); attrs.put(new BasicAttribute("email", "name@site.com")); attrs.put(new BasicAttribute("website")); dctx.modifyAttributes("cn=Name, ou=People", DirContext.ADD_ATTRIBUTE, attrs); } catch (Exception e) { System.out.println(e); } }
From source file:AttributeExample.java
public static void main(String[] argc) throws Exception { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); DirContext dctx = new InitialDirContext(env); Attributes attrs = new BasicAttributes(true); attrs.put(new BasicAttribute("email")); attrs.put(new BasicAttribute("website", "www.pri.com")); NamingEnumeration result = dctx.search("ou=People", attrs); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); Attributes srchAttrs = sr.getAttributes(); NamingEnumeration attributes = srchAttrs.getAll(); while (attributes.hasMore()) { Attribute attr = (Attribute) attributes.next(); System.out.println("Attribute: " + attr.getID()); NamingEnumeration values = attr.getAll(); while (values.hasMore()) { Object value = values.next(); System.out.println("Value = " + value); }/* ww w . jav a 2 s. co m*/ } } }
From source file:Create.java
public static void main(String[] args) { // Set up the environment for creating the initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {/* www .j a v a2 s . c om*/ // Create the initial context DirContext ctx = new InitialDirContext(env); // Create attributes to be associated with the new context Attributes attrs = new BasicAttributes(true); // case-ignore Attribute objclass = new BasicAttribute("objectclass"); objclass.add("top"); objclass.add("organizationalUnit"); attrs.put(objclass); // Create the context Context result = ctx.createSubcontext("ou=NewOu", attrs); // Check that it was created by listing its parent NamingEnumeration list = ctx.list(""); // Go through each item in list while (list.hasMore()) { NameClassPair nc = (NameClassPair) list.next(); System.out.println(nc); } // Close the contexts when we're done result.close(); ctx.close(); } catch (NamingException e) { System.out.println("Create failed: " + e); } }
From source file:de.sub.goobi.helper.ldap.LdapUser.java
/** * Constructor of LdapUser. */ public LdapUser() { this.myAttrs = new BasicAttributes(true); }
From source file:org.kitodo.production.ldap.LdapUser.java
/** * Constructor of LdapUser. */ public LdapUser() { this.attributes = new BasicAttributes(true); }
From source file:org.apache.archiva.redback.rest.services.LdapGroupMappingServiceTest.java
@Override public void startServer() throws Exception { super.startServer(); groupSuffix = apacheDs.addSimplePartition("test", new String[] { "archiva", "apache", "org" }).getSuffix(); log.info("groupSuffix: {}", groupSuffix); suffix = "ou=People,dc=archiva,dc=apache,dc=org"; log.info("DN Suffix: {}", suffix); apacheDs.startServer();/*from w w w .ja v a 2s .c o m*/ BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("organizationalUnit"); Attributes attributes = new BasicAttributes(true); attributes.put(objectClass); attributes.put("organizationalUnitName", "foo"); apacheDs.getAdminContext().createSubcontext(suffix, attributes); createGroups(); }