List of usage examples for javax.naming.directory DirContext destroySubcontext
public void destroySubcontext(Name name) throws NamingException;
From source file:Main.java
public static void main(String args[]) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX); env.put(Context.PROVIDER_URL, MY_HOST); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, MGR_DN); env.put(Context.SECURITY_CREDENTIALS, MGR_PW); DirContext ctx = new InitialDirContext(env); ctx.destroySubcontext(MY_ENTRY); }
From source file:org.geoserver.security.ldap.LDAPTestUtils.java
/** * Clear the directory sub-tree starting with the node represented by the * supplied distinguished name./*from w ww. j a va 2 s . co m*/ * * @param ctx The DirContext to use for cleaning the tree. * @param name the distinguished name of the root node. * @throws NamingException if anything goes wrong removing the sub-tree. */ public static void clearSubContexts(DirContext ctx, Name name) throws NamingException { NamingEnumeration enumeration = null; try { enumeration = ctx.listBindings(name); while (enumeration.hasMore()) { Binding element = (Binding) enumeration.next(); DistinguishedName childName = new DistinguishedName(element.getName()); childName.prepend((DistinguishedName) name); try { ctx.destroySubcontext(childName); } catch (ContextNotEmptyException e) { clearSubContexts(ctx, childName); ctx.destroySubcontext(childName); } } } catch (NamingException e) { e.printStackTrace(); } finally { try { enumeration.close(); } catch (Exception e) { // Never mind this } } }
From source file:org.wso2.carbon.connector.integration.test.ldap.LdapConnectorIntegrationTest.java
public void deleteSampleEntry() throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, providerUrl); env.put(Context.SECURITY_PRINCIPAL, securityPrincipal); env.put(Context.SECURITY_CREDENTIALS, securityCredentials); DirContext ctx = new InitialDirContext(env); String dn = "uid=" + testUserId + "," + userBase; ctx.destroySubcontext(dn); }
From source file:org.orbeon.oxf.processor.LDAPProcessor.java
private void delete(DirContext ctx, Delete delete) { try {//from w w w .j a v a 2 s . c o m ctx.destroySubcontext(delete.getName()); } catch (NamingException e) { throw new OXFException("LDAP Delete Failed", e); } }
From source file:org.easy.ldap.LdapDao.java
public void deleteSubContext(LdapName parentDn, LdapName subContextName) { DirContext ctx = null; try {/*from w ww .java 2 s . c o m*/ ctx = contextFactory.createContext(parentDn.toString()); ctx.destroySubcontext(subContextName); } catch (NamingException e) { throw new RuntimeException(subContextName.toString() + "," + parentDn.toString(), e); } finally { contextFactory.closeContext(ctx); } }
From source file:org.easy.ldap.LdapDao.java
/** * @param parentDn// w ww . ja v a 2 s . c o m * @param subContextRdn */ public void deleteSubContext(LdapName parentDn, Rdn subContextToDelete) { DirContext ctx = null; try { ctx = contextFactory.createContext(parentDn.toString()); ctx.destroySubcontext(subContextToDelete.toString()); } catch (NamingException e) { throw new RuntimeException(subContextToDelete.toString() + "," + parentDn.toString(), e); } finally { if (contextFactory != null) contextFactory.closeContext(ctx); } }
From source file:ldap.ActiveLoginImpl.java
/** * This deletes a user account. It requires a user naming attribute * (usually the uid).//from w w w . j a v a2s . c o m * <p/> * For consistancy, this should use UserAccount instead of a String login. * * @param login * @throws Exception */ public void deleteAccount(String login, DirContext context, String userDN) throws Exception { //String dn = getUserDN(login); context.destroySubcontext(userDN); }
From source file:CreateJavaSchema.java
protected void updateAttributes(DirContext attrRoot, String[] attrIDs) throws NamingException { /* Get rid of old attr IDs */ for (int i = 0; i < attrIDs.length; i++) { attrRoot.destroySubcontext(attrIDs[i]); }/*from w w w . java2s.c o m*/ // javaSerializedData Attributes attrs = new BasicAttributes(true); // ignore case attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.8"); attrs.put("NAME", "javaSerializedData"); attrs.put("DESC", "Serialized form of a Java object"); if (netscape41bug) { // DS 4.1 doesn't like Octet String attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.5"); } else { attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.40"); } attrs.put("SINGLE-VALUE", "true"); attrRoot.createSubcontext("javaSerializedData", attrs); System.out.println("Created javaSerializedData attribute"); // javaCodebase attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.7"); attrs.put("NAME", "javaCodebase"); attrs.put("DESC", "URL(s) specifying the location of class definition"); attrs.put("EQUALITY", "caseExactIA5Match"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.26"); attrRoot.createSubcontext("javaCodebase", attrs); System.out.println("Created javaCodebase attribute"); // javaClassName attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.6"); attrs.put("NAME", "javaClassName"); attrs.put("DESC", "Fully qualified name of distinguished class or interface"); attrs.put("EQUALITY", "caseExactMatch"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15"); attrs.put("SINGLE-VALUE", "true"); attrRoot.createSubcontext("javaClassName", attrs); System.out.println("Created javaClassName attribute"); // javaClassNames attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.13"); attrs.put("NAME", "javaClassNames"); attrs.put("DESC", "Fully qualified Java class or interface name"); attrs.put("EQUALITY", "caseExactMatch"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15"); attrRoot.createSubcontext("javaClassNames", attrs); System.out.println("Created javaClassNames attribute"); // javaFactory attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.10"); attrs.put("NAME", "javaFactory"); attrs.put("DESC", "Fully qualified Java class name of a JNDI object factory"); attrs.put("EQUALITY", "caseExactMatch"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15"); attrs.put("SINGLE-VALUE", "true"); attrRoot.createSubcontext("javaFactory", attrs); System.out.println("Created javaFactory attribute"); // javaReferenceAddress attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.11"); attrs.put("NAME", "javaReferenceAddress"); attrs.put("DESC", "Addresses associated with a JNDI Reference"); attrs.put("EQUALITY", "caseExactMatch"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15"); attrRoot.createSubcontext("javaReferenceAddress", attrs); System.out.println("Created javaReferenceAddress attribute"); // javaDoc attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.12"); attrs.put("NAME", "javaDoc"); attrs.put("DESC", "The Java documentation for the class"); attrs.put("EQUALITY", "caseExactIA5Match"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.26"); attrRoot.createSubcontext("javaDoc", attrs); System.out.println("Created javaDoc attribute"); }
From source file:CreateJavaSchema.java
protected void updateObjectClasses(DirContext ocRoot, String[] ocIDs) throws NamingException { /* Get rid of old OCs - reverse order */ for (int i = ocIDs.length - 1; i >= 0; i--) { ocRoot.destroySubcontext(ocIDs[i]); }//from www. ja v a 2 s . com // javaContainer Attributes attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.1"); attrs.put("NAME", "javaContainer"); attrs.put("DESC", "Container for a Java object"); attrs.put("SUP", "top"); attrs.put("STRUCTURAL", "true"); Attribute jcMust = new BasicAttribute("MUST", "cn"); if (netscape41bug) { jcMust.add("objectClass"); } attrs.put(jcMust); ocRoot.createSubcontext("javaContainer", attrs); System.out.println("Created javaContainer object class"); // javaObject attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.4"); attrs.put("NAME", "javaObject"); attrs.put("DESC", "Java object representation"); attrs.put("SUP", "top"); attrs.put("ABSTRACT", "true"); Attribute joMust = new BasicAttribute("MUST", "javaClassName"); if (netscape41bug) { joMust.add("objectClass"); } attrs.put(joMust); Attribute optional = new BasicAttribute("MAY", "javaCodebase"); optional.add("javaClassNames"); optional.add("javaDoc"); optional.add("description"); attrs.put(optional); ocRoot.createSubcontext("javaObject", attrs); System.out.println("Created javaObject object class"); // javaSerializedObject attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.5"); attrs.put("NAME", "javaSerializedObject"); attrs.put("DESC", "Java serialized object"); attrs.put("SUP", "javaObject"); attrs.put("AUXILIARY", "true"); Attribute jsoMust = new BasicAttribute("MUST", "javaSerializedData"); if (netscape41bug) { jsoMust.add("objectClass"); } if (netscapebug) { // Netscape ignores 'SUP' so we must add explicitly attrs.put(optional); jsoMust.add("javaClassName"); } attrs.put(jsoMust); ocRoot.createSubcontext("javaSerializedObject", attrs); System.out.println("Created javaSerializedObject object class"); // javaMarshalledObject attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.8"); attrs.put("NAME", "javaMarshalledObject"); attrs.put("DESC", "Java marshalled object"); attrs.put("SUP", "javaObject"); attrs.put("AUXILIARY", "true"); if (netscapebug) { // Netscape ignores 'SUP' so we must add explicitly attrs.put(optional); } attrs.put(jsoMust); // re-use the MUST from javaSerializedObject ocRoot.createSubcontext("javaMarshalledObject", attrs); System.out.println("Created javaMarshalledObject object class"); // javaNamingReference attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.7"); attrs.put("NAME", "javaNamingReference"); attrs.put("DESC", "JNDI reference"); attrs.put("SUP", "javaObject"); attrs.put("AUXILIARY", "true"); if (netscapebug) { // Netscape ignores 'SUP' so we must add explicitly attrs.put("MUST", "javaClassName"); } else { optional = new BasicAttribute("MAY"); } optional.add("javaReferenceAddress"); optional.add("javaFactory"); attrs.put(optional); ocRoot.createSubcontext("javaNamingReference", attrs); System.out.println("Created javaNamingReference object class"); }
From source file:org.nuxeo.ecm.directory.ldap.ExternalLDAPDirectoryFeature.java
protected void destroyRecursively(String dn, DirContext ctx, int limit) throws NamingException { if (limit == 0) { log.warn("Reach recursion limit, stopping deletion at" + dn); return;//from w w w . j av a 2 s . c om } SearchControls scts = new SearchControls(); scts.setSearchScope(SearchControls.ONELEVEL_SCOPE); NamingEnumeration<SearchResult> children = ctx.search(dn, "(objectClass=*)", scts); try { while (children.hasMore()) { SearchResult child = children.next(); String subDn = child.getName(); subDn = subDn + ',' + dn; destroyRecursively(subDn, ctx, limit); } } catch (SizeLimitExceededException e) { log.warn("SizeLimitExceededException: trying again on partial results " + dn); if (limit == -1) { limit = 100; } destroyRecursively(dn, ctx, limit - 1); } ctx.destroySubcontext(dn); }