Search in sources :

Example 1 with LDIFEntryReader

use of org.forgerock.opendj.ldif.LDIFEntryReader in project OpenAM by OpenRock.

the class OpenDJUpgrader method findBaseDNs.

private List<DN> findBaseDNs() throws IOException {
    final List<DN> baseDNs = new LinkedList<DN>();
    final SearchRequest request = LDAPRequests.newSearchRequest("cn=backends,cn=config", SearchScope.WHOLE_SUBTREE, "(objectclass=ds-cfg-backend)", "ds-cfg-base-dn");
    try (LDIFEntryReader reader = new LDIFEntryReader(new FileInputStream(installRoot + "/config/config.ldif"))) {
        final EntryReader filteredReader = LDIF.search(reader, request);
        while (filteredReader.hasNext()) {
            final Entry entry = filteredReader.readEntry();
            final Attribute values = entry.getAttribute("ds-cfg-base-dn");
            if (values != null) {
                for (final ByteString value : values) {
                    baseDNs.add(DN.valueOf(value.toString()));
                }
            }
        }
    }
    return baseDNs;
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) EntryReader(org.forgerock.opendj.ldif.EntryReader) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) ZipEntry(java.util.zip.ZipEntry) Entry(org.forgerock.opendj.ldap.Entry) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) DN(org.forgerock.opendj.ldap.DN) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream)

Example 2 with LDIFEntryReader

use of org.forgerock.opendj.ldif.LDIFEntryReader in project OpenAM by OpenRock.

the class IdRepoTestBase method setUpSuite.

@BeforeClass
public void setUpSuite() throws Exception {
    InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() {

        @Override
        public Set<Class<? extends Module>> getGuiceModules(Class<? extends Annotation> aClass) {
            return Collections.<Class<? extends Module>>singleton(TestGuiceModule.class);
        }
    });
    PowerMockito.mockStatic(WebtopNaming.class);
    idRepoListener = PowerMockito.mock(IdRepoListener.class);
    when(WebtopNaming.getAMServerID()).thenReturn("01");
    when(WebtopNaming.getSiteID(eq("01"))).thenReturn("02");
    memoryBackend = decorateBackend(new MemoryBackend(new LDIFEntryReader(getClass().getResourceAsStream(getLDIFPath()))));
}
Also used : IdRepoListener(com.sun.identity.idm.IdRepoListener) Set(java.util.Set) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) GuiceModuleLoader(org.forgerock.guice.core.GuiceModuleLoader) MemoryBackend(org.forgerock.opendj.ldap.MemoryBackend) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with LDIFEntryReader

use of org.forgerock.opendj.ldif.LDIFEntryReader in project OpenAM by OpenRock.

the class OpenDJUpgrader method patchConfiguration.

private void patchConfiguration() throws IOException {
    message("Patching configuration config/config.ldif...");
    try (InputStream defaultCurrentConfig = new FileInputStream(installRoot + "/config/upgrade/config.ldif." + currentVersion);
        InputStream defaultNewConfig = new FileInputStream(installRoot + "/config/upgrade/config.ldif." + newVersion);
        InputStream currentConfig = new FileInputStream(getBackupFileName("config/config.ldif"));
        OutputStream newCurrentConfig = new FileOutputStream(installRoot + "/config/config.ldif")) {
        final LDIFEntryReader defaultCurrentConfigReader = new LDIFEntryReader(defaultCurrentConfig);
        final LDIFEntryReader defaultNewConfigReader = new LDIFEntryReader(defaultNewConfig);
        final LDIFEntryReader currentConfigReader = new LDIFEntryReader(currentConfig);
        final LDIFEntryWriter newConfigWriter = new LDIFEntryWriter(newCurrentConfig);
        LDIF.copyTo(LDIF.patch(currentConfigReader, LDIF.diff(defaultCurrentConfigReader, defaultNewConfigReader)), newConfigWriter);
        newConfigWriter.flush();
        message("done");
    } catch (final IOException ioe) {
        message("failed: " + ioe.getMessage());
        throw ioe;
    }
}
Also used : LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) LDIFEntryWriter(org.forgerock.opendj.ldif.LDIFEntryWriter) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

LDIFEntryReader (org.forgerock.opendj.ldif.LDIFEntryReader)3 FileInputStream (java.io.FileInputStream)2 IdRepoListener (com.sun.identity.idm.IdRepoListener)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 GuiceModuleLoader (org.forgerock.guice.core.GuiceModuleLoader)1 Attribute (org.forgerock.opendj.ldap.Attribute)1 ByteString (org.forgerock.opendj.ldap.ByteString)1 DN (org.forgerock.opendj.ldap.DN)1 Entry (org.forgerock.opendj.ldap.Entry)1 MemoryBackend (org.forgerock.opendj.ldap.MemoryBackend)1 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)1 EntryReader (org.forgerock.opendj.ldif.EntryReader)1