[java-opensaml] branch main updated: OSJ-359 - remove LDAPStorageService

Daniel Fisher dfisher at vt.edu
Thu Sep 8 00:57:31 UTC 2022


This is an automated email from the git hooks/post-receive script.

dfisher pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=51b5f4d2315861e766060e15dde762eca6ce3d73

The following commit(s) were added to refs/heads/main by this push:
     new 51b5f4d23 OSJ-359 - remove LDAPStorageService
51b5f4d23 is described below

commit 51b5f4d2315861e766060e15dde762eca6ce3d73
Author: Daniel Fisher <dfisher at vt.edu>
AuthorDate: Wed Sep 7 20:54:01 2022 -0400

    OSJ-359 - remove LDAPStorageService
    
    https://shibboleth.atlassian.net/browse/OSJ-359
---
 opensaml-storage-impl/pom.xml                      |  13 -
 .../opensaml/storage/impl/LDAPStorageService.java  | 300 ---------------------
 .../storage/impl/LDAPStorageServiceTest.java       | 190 -------------
 3 files changed, 503 deletions(-)

diff --git a/opensaml-storage-impl/pom.xml b/opensaml-storage-impl/pom.xml
index abc2b8c5e..ca5e4f3de 100644
--- a/opensaml-storage-impl/pom.xml
+++ b/opensaml-storage-impl/pom.xml
@@ -55,13 +55,6 @@
         	<artifactId>guava</artifactId>
         </dependency>
 
-        <!-- Needed for LDAP storage plugin. -->
-        <dependency>
-            <groupId>org.ldaptive</groupId>
-            <artifactId>ldaptive</artifactId>
-            <optional>true</optional>
-        </dependency>
-
         <!-- Needed for Memcache storage plugin. -->
         <dependency>
             <groupId>net.spy</groupId>
@@ -115,12 +108,6 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>com.unboundid</groupId>
-            <artifactId>unboundid-ldapsdk</artifactId>
-            <scope>test</scope>
-        </dependency>
-
         <dependency>
             <groupId>org.hsqldb</groupId>
             <artifactId>hsqldb</artifactId>
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/LDAPStorageService.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/LDAPStorageService.java
deleted file mode 100644
index c234adde0..000000000
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/LDAPStorageService.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.opensaml.storage.impl;
-
-import java.io.IOException;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
-import net.shibboleth.utilities.java.support.collection.Pair;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-
-import org.ldaptive.AttributeModification;
-import org.ldaptive.AttributeModificationType;
-import org.ldaptive.Connection;
-import org.ldaptive.DeleteOperation;
-import org.ldaptive.DeleteRequest;
-import org.ldaptive.LdapAttribute;
-import org.ldaptive.LdapEntry;
-import org.ldaptive.LdapException;
-import org.ldaptive.ModifyOperation;
-import org.ldaptive.ModifyRequest;
-import org.ldaptive.Response;
-import org.ldaptive.ResultCode;
-import org.ldaptive.SearchOperation;
-import org.ldaptive.SearchRequest;
-import org.ldaptive.SearchResult;
-import org.ldaptive.ext.MergeOperation;
-import org.ldaptive.ext.MergeRequest;
-import org.ldaptive.pool.PooledConnectionFactory;
-import org.opensaml.storage.AbstractStorageService;
-import org.opensaml.storage.StorageCapabilities;
-import org.opensaml.storage.StorageRecord;
-import org.opensaml.storage.VersionMismatchException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of {@link org.opensaml.storage.StorageService} that stores data in an LDAP. Does not support
- * expiration or versioning at this time.
- */
-public class LDAPStorageService extends AbstractStorageService implements StorageCapabilities {
-
-    /** Class logger. */
-    private final Logger log = LoggerFactory.getLogger(LDAPStorageService.class);
-
-    /** LDAP connection factory. */
-    private PooledConnectionFactory connectionFactory;
-
-    /** Attributes to include in merge operations. */
-    private LdapAttribute[] defaultAttributes;
-
-    /**
-     * Creates a new LDAP storage service.
-     * 
-     * @param factory to retrieve LDAP connections from
-     * @param attrs to include in all LDAP entries
-     */
-    public LDAPStorageService(@Nonnull final PooledConnectionFactory factory, final LdapAttribute... attrs) {
-        connectionFactory = Constraint.isNotNull(factory, "ConnectionFactory cannot be null");
-        defaultAttributes = attrs;
-
-        setContextSize(Integer.MAX_VALUE);
-        setKeySize(Integer.MAX_VALUE);
-        setValueSize(Integer.MAX_VALUE);
-    }
-    
-    /** {@inheritDoc} */
-    public boolean isServerSide() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    public boolean isClustered() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void doInitialize() throws ComponentInitializationException {
-        super.doInitialize();
-        connectionFactory.getConnectionPool().initialize();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void doDestroy() {
-        super.doDestroy();
-        if (isInitialized()) {
-            connectionFactory.getConnectionPool().close();
-            connectionFactory = null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean create(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key,
-            @Nonnull @NotEmpty final String value, @Nullable @Positive final Long expiration) throws IOException {
-        if (expiration != null) {
-            throw new UnsupportedOperationException("Expiration not supported");
-        }
-        final LdapEntry entry = new LdapEntry(context, defaultAttributes);
-        entry.addAttribute(new LdapAttribute(key, value));
-        try {
-            merge(entry);
-            return true;
-        } catch (final LdapException e) {
-            log.error("LDAP merge operation failed: {}", e.getMessage());
-            throw new IOException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public <T> StorageRecord<T> read(@Nonnull @NotEmpty final String context,
-            @Nonnull @NotEmpty final String key) throws IOException {
-        SearchResult result = null;
-        try {
-            result = search(context, key).getResult();
-        } catch (final LdapException e) {
-            if (e.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
-                log.error("LDAP search operation failed: {}", e.getMessage());
-                throw new IOException(e);
-            }
-        }
-        StorageRecord<T> record = null;
-        if (result != null && result.size() > 0) {
-            final LdapEntry entry = result.getEntry();
-            if (entry != null) {
-                final LdapAttribute attr = entry.getAttribute(key);
-                if (attr != null) {
-                    record = new StorageRecord<>(attr.getStringValue(), null);
-                }
-            }
-        }
-        return record;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nonnull public <T> Pair<Long,StorageRecord<T>> read(@Nonnull @NotEmpty final String context,
-            @Nonnull @NotEmpty final String key, @Positive final long version) throws IOException {
-        throw new UnsupportedOperationException("Versioning not supported");
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean update(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key,
-            @Nonnull @NotEmpty final String value, @Nullable @Positive final Long expiration) throws IOException {
-        if (expiration != null) {
-            throw new UnsupportedOperationException("Expiration not supported");
-        }
-        final LdapEntry entry = new LdapEntry(context, defaultAttributes);
-        entry.addAttribute(new LdapAttribute(key, value));
-        try {
-            merge(entry);
-            return true;
-        } catch (final LdapException e) {
-            log.error("LDAP merge operation failed: {}", e.getMessage());
-            throw new IOException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Long updateWithVersion(@Positive final long version,
-            @Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key,
-            @Nonnull @NotEmpty final String value, @Nullable @Positive final Long expiration) throws IOException,
-            VersionMismatchException {
-        throw new UnsupportedOperationException("Versioning not supported");
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean updateExpiration(@Nonnull @NotEmpty final String context,
-            @Nonnull @NotEmpty final String key, @Nullable @Positive final Long expiration) throws IOException {
-        throw new UnsupportedOperationException("Expiration not supported");
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean delete(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key)
-            throws IOException {
-        try {
-            deleteAttribute(context, key);
-            return true;
-        } catch (final LdapException e) {
-            log.error("LDAP modify operation failed: {}", e.getMessage());
-            throw new IOException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean deleteWithVersion(@Positive final long version, @Nonnull @NotEmpty final String context,
-            @Nonnull @NotEmpty final String key) throws IOException, VersionMismatchException {
-        throw new UnsupportedOperationException("Versioning not supported");
-    }
-
-    /** {@inheritDoc} */
-    @Override public void reap(@Nonnull @NotEmpty final String context) throws IOException {
-        // no-op, expiration not supported
-    }
-
-    /** {@inheritDoc} */
-    @Override public void updateContextExpiration(@Nonnull @NotEmpty final String context,
-            @Nullable @Positive final Long expiration) throws IOException {
-        throw new UnsupportedOperationException("Expiration not supported");
-    }
-
-    /** {@inheritDoc} */
-    @Override public void deleteContext(@Nonnull @NotEmpty final String context) throws IOException {
-        try {
-            delete(context);
-        } catch (final LdapException e) {
-            log.error("LDAP delete operation failed", e);
-            throw new IOException(e);
-        }
-    }
-
-    /**
-     * Executes a {@link MergeOperation} with the supplied entry.
-     * 
-     * @param entry to merge
-     * 
-     * @return response for the merge operation
-     * 
-     * @throws LdapException if the operation fails
-     */
-    @Nonnull private Response<Void> merge(@Nonnull final LdapEntry entry) throws LdapException {
-        try (final Connection conn = connectionFactory.getConnection()) {
-            final MergeOperation merge = new MergeOperation(conn);
-            final MergeRequest request = new MergeRequest(entry);
-            request.setIncludeAttributes(entry.getAttributeNames());
-            return merge.execute(request);
-        }
-    }
-
-    /**
-     * Executes a object level {@link SearchOperation} on the supplied DN, returning the supplied attributes.
-     * 
-     * @param dn to search on
-     * @param attrs to return
-     * 
-     * @return response for the search operation
-     * 
-     * @throws LdapException if the operation fails
-     */
-    @Nonnull private Response<SearchResult> search(@Nonnull final String dn, final String... attrs)
-            throws LdapException {
-        try (final Connection conn = connectionFactory.getConnection()) {
-            final SearchOperation search = new SearchOperation(conn);
-            return search.execute(SearchRequest.newObjectScopeSearchRequest(dn, attrs));
-        }
-    }
-
-    /**
-     * Executes a {@link ModifyOperation} on the supplied DN, removing the supplied attribute.
-     * 
-     * @param dn to modify
-     * @param attrName to remove
-     * 
-     * @return response for the modify operation
-     * 
-     * @throws LdapException if the operation fails
-     */
-    @Nonnull private Response<Void> deleteAttribute(@Nonnull final String dn, @Nonnull final String attrName)
-            throws LdapException {
-        try (final Connection conn = connectionFactory.getConnection()) {
-            final ModifyOperation modify = new ModifyOperation(conn);
-            return modify.execute(new ModifyRequest(dn, new AttributeModification(AttributeModificationType.REMOVE,
-                    new LdapAttribute(attrName))));
-        }
-    }
-
-    /**
-     * Executes a {@link DeleteOperation} on the supplied DN.
-     * 
-     * @param dn to delete
-     * 
-     * @return response for the delete operation
-     * 
-     * @throws LdapException if the operation fails
-     */
-    @Nonnull private Response<Void> delete(@Nonnull final String dn) throws LdapException {
-        try (final Connection conn = connectionFactory.getConnection()) {
-            final DeleteOperation delete = new DeleteOperation(conn);
-            return delete.execute(new DeleteRequest(dn));
-        }
-    }
-
-}
\ No newline at end of file
diff --git a/opensaml-storage-impl/src/test/java/org/opensaml/storage/impl/LDAPStorageServiceTest.java b/opensaml-storage-impl/src/test/java/org/opensaml/storage/impl/LDAPStorageServiceTest.java
deleted file mode 100644
index 309e6a9ac..000000000
--- a/opensaml-storage-impl/src/test/java/org/opensaml/storage/impl/LDAPStorageServiceTest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.opensaml.storage.impl;
-
-import java.io.IOException;
-import java.time.Duration;
-
-import javax.annotation.Nonnull;
-
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-import org.ldaptive.DefaultConnectionFactory;
-import org.ldaptive.LdapAttribute;
-import org.ldaptive.pool.BlockingConnectionPool;
-import org.ldaptive.pool.PooledConnectionFactory;
-import org.opensaml.storage.StorageRecord;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import com.unboundid.ldap.listener.InMemoryDirectoryServer;
-import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
-import com.unboundid.ldap.listener.InMemoryListenerConfig;
-import com.unboundid.ldap.sdk.LDAPException;
-
-/**
- * Test of {@link LDAPStorageService} implementation.
- */
-public class LDAPStorageServiceTest {
-
-    /** Storage service to test. */
-    protected LDAPStorageService storageService;
-
-    /** In-memory directory server. */
-    private InMemoryDirectoryServer directoryServer;
-
-    /** LDAP DN to test. */
-    private final String context = "cn=Principal,ou=people,dc=shibboleth,dc=net";
-
-    @BeforeClass
-    protected void setUp() throws ComponentInitializationException, LDAPException {
-        InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=shibboleth,dc=net");
-        config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", 10389));
-        config.addAdditionalBindCredentials("cn=Directory Manager", "password");
-        directoryServer = new InMemoryDirectoryServer(config);
-        directoryServer.importFromLDIF(true,
-                "src/test/resources/org/opensaml/storage/impl/LDAPStorageServiceTest.ldif");
-        directoryServer.startListening();
-
-        storageService = getStorageService();
-        storageService.initialize();
-    }
-    
-    @AfterClass
-    protected void tearDown() {
-        storageService.destroy();
-        directoryServer.shutDown(true);
-    }
-
-    @Nonnull protected PooledConnectionFactory getPooledConnectionFactory() {
-        return new PooledConnectionFactory(new BlockingConnectionPool(new DefaultConnectionFactory(
-                "ldap://localhost:10389")));
-    }
-
-    @Nonnull protected LDAPStorageService getStorageService() {
-        LDAPStorageService ss = new LDAPStorageService(
-                getPooledConnectionFactory(),
-                new LdapAttribute("objectClass", "inetOrgPerson", "organizationalPerson", "person", "top"),
-                new LdapAttribute("cn", "Principal"),
-                new LdapAttribute("sn", "Lastname"));
-        ss.setId("test");
-        return ss;
-    }
-
-    @Test
-    public void throwException() throws IOException {
-        try {
-            storageService.create(context, "mail", "principal at shibboleth.net", 5000L);
-            Assert.fail("Should have thrown exception");
-        } catch (UnsupportedOperationException e){ 
-            Assert.assertEquals(e.getClass(), UnsupportedOperationException.class);
-        }
-
-        try {
-            storageService.read(context, "mail", 3);
-            Assert.fail("Should have thrown exception");
-        } catch (UnsupportedOperationException e){ 
-            Assert.assertEquals(e.getClass(), UnsupportedOperationException.class);
-        }
-
-        try {
-            storageService.update(context, "mail", "principal at shibboleth.net", 10000L);
-            Assert.fail("Should have thrown exception");
-        } catch (UnsupportedOperationException e){ 
-            Assert.assertEquals(e.getClass(), UnsupportedOperationException.class);
-        }
-
-        try {
-            storageService.updateWithVersion(2, context, "mail", "principal at shibboleth.net", 10000L);
-            Assert.fail("Should have thrown exception");
-        } catch (UnsupportedOperationException e){ 
-            Assert.assertEquals(e.getClass(), UnsupportedOperationException.class);
-        } catch (Exception e) {
-            Assert.fail("Threw exception", e);
-        }
-
-        try {
-            storageService.updateExpiration(context, "mail", 8000L);
-            Assert.fail("Should have thrown exception");
-        } catch (UnsupportedOperationException e){ 
-            Assert.assertEquals(e.getClass(), UnsupportedOperationException.class);
-        }
-
-        try {
-            storageService.updateContextExpiration(context, 15000L);
-            Assert.fail("Should have thrown exception");
-        } catch (UnsupportedOperationException e){ 
-            Assert.assertEquals(e.getClass(), UnsupportedOperationException.class);
-        }
-    }
-
-    @Test
-    public void create() throws IOException {
-        storageService.create(context, "mail", "principal at shibboleth.net", null);
-        StorageRecord<?> rec = storageService.read(context, "mail");
-        Assert.assertNotNull(rec);
-        Assert.assertEquals(rec.getValue(), "principal at shibboleth.net");
-
-        storageService.update(context, "mail", "principal2 at shibboleth.net", null);
-        rec = storageService.read(context, "mail");
-        Assert.assertNotNull(rec);
-        Assert.assertEquals(rec.getValue(), "principal2 at shibboleth.net");
-
-        storageService.create(context, "mail", "principal3 at shibboleth.net", null);
-        
-        storageService.update(context, "description", "test user", null);
-        rec = storageService.read(context, "description");
-        Assert.assertNotNull(rec);
-        Assert.assertEquals(rec.getValue(), "test user");
-
-        storageService.delete(context, "description");
-        rec = storageService.read(context, "description");
-        Assert.assertNull(rec);
-        rec = storageService.read(context, "mail");
-        Assert.assertNotNull(rec);
-        Assert.assertEquals(rec.getValue(), "principal3 at shibboleth.net");
-
-        storageService.deleteContext(context);
-        rec = storageService.read(context, "mail");
-        Assert.assertNull(rec);
-    }
-
-    @Test public void invalidConfig() {
-        LDAPStorageService ss = new LDAPStorageService(getPooledConnectionFactory());
-        ss.setCleanupInterval(Duration.ofSeconds(1));
-
-        try {
-            ss.initialize();
-            Assert.fail("Storage service should have failed to initialize");
-        } catch (ComponentInitializationException e) {
-            // expected
-        }
-
-        ss.destroy();
-    }
-
-    @Test public void validConfig() throws ComponentInitializationException {
-        LDAPStorageService ss = new LDAPStorageService(getPooledConnectionFactory());
-        ss.setId("test");
-        ss.initialize();
-        ss.destroy();
-    }
-
-}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list