reader.close(); syntaxCheckerList.add( entry.getEntry() );
reader.close(); normalizerList.add( entry.getEntry() );
reader.close(); syntaxList.add( entry.getEntry() );
Entry entry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
/** * {@inheritDoc} */ @Override public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException { List<Entry> syntaxList = new ArrayList<>(); if ( schemas == null ) { return syntaxList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.SYNTAXES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "syntax LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); syntaxList.add( entry.getEntry() ); } } } return syntaxList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException, IOException { List<Entry> matchingRuleList = new ArrayList<>(); if ( schemas == null ) { return matchingRuleList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.MATCHING_RULES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "matchingRules LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); matchingRuleList.add( entry.getEntry() ); } } } return matchingRuleList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapException, IOException { List<Entry> ditStructureRuleList = new ArrayList<>(); if ( schemas == null ) { return ditStructureRuleList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.DIT_STRUCTURE_RULES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "ditStructureRule LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); ditStructureRuleList.add( entry.getEntry() ); } } } return ditStructureRuleList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException { List<Entry> comparatorList = new ArrayList<>(); if ( schemas == null ) { return comparatorList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.COMPARATORS_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "comparator LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); comparatorList.add( entry.getEntry() ); } } } return comparatorList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException, IOException { List<Entry> ditContentRulesList = new ArrayList<>(); if ( schemas == null ) { return ditContentRulesList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.DIT_CONTENT_RULES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "ditContentRule LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); ditContentRulesList.add( entry.getEntry() ); } } } return ditContentRulesList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException, IOException { List<Entry> syntaxCheckerList = new ArrayList<>(); if ( schemas == null ) { return syntaxCheckerList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.SYNTAX_CHECKERS_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "syntaxChecker LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); syntaxCheckerList.add( entry.getEntry() ); } } } return syntaxCheckerList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException { List<Entry> syntaxList = new ArrayList<>(); if ( schemas == null ) { return syntaxList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.SYNTAXES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "syntax LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); syntaxList.add( entry.getEntry() ); } } } return syntaxList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapException, IOException { List<Entry> matchingRuleUseList = new ArrayList<>(); if ( schemas == null ) { return matchingRuleUseList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.MATCHING_RULE_USE_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "matchingRuleUse LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); matchingRuleUseList.add( entry.getEntry() ); } } } return matchingRuleUseList; }
/** * Apply LDIF text. * * @param ldif * LDIF text. * @throws LdapException * if some LDAP related error occurs. * @throws IOException * if stream could not be closed. */ private void applyLdif(final String ldif) throws LdapException, IOException { try (LdifReader entries = new LdifReader(new StringReader(ldif))) { for (LdifEntry ldifEntry : entries) { final DefaultEntry newEntry = new DefaultEntry(this.service.getSchemaManager(), ldifEntry.getEntry()); LOGGER.debug("LDIF entry: {}", newEntry); this.service.getAdminSession().add(newEntry); } } }
/** * Creates a principal in the KDC with the specified user and password. * * @param principal principal name, do not include the domain. * @param password password. * @throws Exception thrown if the principal could not be created. */ public synchronized void createPrincipal(String principal, String password) throws Exception { String orgName= conf.getProperty(ORG_NAME); String orgDomain = conf.getProperty(ORG_DOMAIN); String baseDn = "ou=users,dc=" + orgName.toLowerCase() + ",dc=" + orgDomain.toLowerCase(); String content = "dn: uid=" + principal + "," + baseDn + "\n" + "objectClass: top\n" + "objectClass: person\n" + "objectClass: inetOrgPerson\n" + "objectClass: krb5principal\n" + "objectClass: krb5kdcentry\n" + "cn: " + principal + "\n" + "sn: " + principal + "\n" + "uid: " + principal + "\n" + "userPassword: " + password + "\n" + "krb5PrincipalName: " + principal + "@" + getRealm() + "\n" + "krb5KeyVersionNumber: 0"; for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) { ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(), ldifEntry.getEntry())); } }
private void importLdif(LdifReader ldifReader) throws Exception { try { for (LdifEntry ldifEntry : ldifReader) { checkPartition(ldifEntry); System.out.print(ldifEntry.toString()); directoryService.getAdminSession() .add(new DefaultEntry(directoryService.getSchemaManager(), ldifEntry.getEntry())); } } finally { IOUtils.closeQuietly(ldifReader); } }
protected List<LdifEntry> loadLdif(LdifReader ldifReader) throws Exception { List<LdifEntry> entries = new ArrayList<LdifEntry>(); for (LdifEntry ldifEntry : ldifReader) { Dn dn = ldifEntry.getDn(); if (ldifEntry.isEntry()) { org.apache.directory.api.ldap.model.entry.Entry items = ldifEntry.getEntry(); rootDSE.add(new DefaultEntry(directoryService.getSchemaManager(), items)); LOG.info("Added entry {}", dn); entries.add(ldifEntry); } } return entries; }
public synchronized void createPrincipal(String principal, String password) throws Exception { String baseDn = getKdcServer().getSearchBaseDn(); String content = "dn: uid=" + principal + "," + baseDn + "\n" + "objectClass: top\n" + "objectClass: person\n" + "objectClass: inetOrgPerson\n" + "objectClass: krb5principal\n" + "objectClass: krb5kdcentry\n" + "cn: " + principal + "\n" + "sn: " + principal + "\n" + "uid: " + principal + "\n" + "userPassword: " + password + "\n" // using businessCategory as a proxy for memberoOf attribute pending: https://issues.apache.org/jira/browse/DIRSERVER-1844 + "businessCategory: " + "cn=admins,ou=system" + "\n" + "businessCategory: " + "cn=bees,ou=system" + "\n" + "krb5PrincipalName: " + principal + "@" + getRealm() + "\n" + "krb5KeyVersionNumber: 0"; for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) { service.getAdminSession().add(new DefaultEntry(service.getSchemaManager(), ldifEntry.getEntry())); } }
/** * Stream will be closed automatically. */ public void importLdif(InputStream is) throws Exception { try (LdifReader reader = new LdifReader(is)) { CoreSession coreSession = directoryService.getAdminSession(); // see LdifFileLoader for (LdifEntry ldifEntry : reader) { String ldif = ldifEntry.toString(); LOG.info(ldif); if (ChangeType.Add == ldifEntry.getChangeType() || /* assume "add" by default */ ChangeType.None == ldifEntry.getChangeType()) { coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), ldifEntry.getEntry())); } else if (ChangeType.Modify == ldifEntry.getChangeType()) { coreSession.modify(ldifEntry.getDn(), ldifEntry.getModifications()); } else if (ChangeType.Delete == ldifEntry.getChangeType()) { coreSession.delete(ldifEntry.getDn()); } else { throw new IllegalStateException(); } } } }
/** * injects an LDIF entry in the given DirectoryService * * @param entry the LdifEntry to be injected * @param service the DirectoryService * @throws Exception If the entry cannot be injected */ private static void injectEntry( LdifEntry entry, DirectoryService service ) throws LdapException { if ( entry.isChangeAdd() || entry.isLdifContent() ) { service.getAdminSession().add( new DefaultEntry( service.getSchemaManager(), entry .getEntry() ) ); } else if ( entry.isChangeModify() ) { service.getAdminSession().modify( entry.getDn(), entry.getModifications() ); } else { String message = I18n.err( I18n.ERR_117, entry.getChangeType() ); throw new LdapException( message ); } }