You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bm...@apache.org on 2021/01/22 11:51:10 UTC

[shiro] branch master updated: [SHIRO-807] remove deprecated method signature

This is an automated email from the ASF dual-hosted git repository.

bmarwell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shiro.git


The following commit(s) were added to refs/heads/master by this push:
     new 61963a8  [SHIRO-807] remove deprecated method signature
     new 1b54391  Merge pull request #272 from bmarwell/SHIRO-807
61963a8 is described below

commit 61963a8c60a986767e3ff3359b9041121083dec1
Author: Benjamin Marwell <bm...@apache.org>
AuthorDate: Tue Dec 29 17:30:41 2020 +0100

    [SHIRO-807] remove deprecated method signature
    
      - remove `public LdapContext getLdapContext(String username, String password)`
      - remove now redundant casts
---
 .../shiro/realm/ldap/DefaultLdapContextFactory.java | 21 +--------------------
 .../shiro/realm/ldap/JndiLdapContextFactory.java    | 18 +-----------------
 .../apache/shiro/realm/ldap/LdapContextFactory.java | 14 --------------
 .../realm/ldap/DefaultLdapContextFactoryTest.java   | 12 ++++++------
 .../realm/ldap/JndiLdapContextFactoryTest.java      | 14 +++++++-------
 5 files changed, 15 insertions(+), 64 deletions(-)

diff --git a/core/src/main/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactory.java b/core/src/main/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactory.java
index db2b72c..8b8f4d5 100644
--- a/core/src/main/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactory.java
+++ b/core/src/main/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactory.java
@@ -205,25 +205,6 @@ public class DefaultLdapContextFactory implements LdapContextFactory {
         return getLdapContext(systemUsername, systemPassword);
     }
 
-    /**
-     * Deprecated - use {@link #getLdapContext(Object, Object)} instead.  This will be removed before Apache Shiro 2.0.
-     *
-     * @param username the username to use when creating the connection.
-     * @param password the password to use when creating the connection.
-     * @return a {@code LdapContext} bound using the given username and password.
-     * @throws javax.naming.NamingException if there is an error creating the context.
-     * @deprecated the {@link #getLdapContext(Object, Object)} method should be used in all cases to ensure more than
-     *             String principals and credentials can be used.  Shiro no longer calls this method - it will be
-     *             removed before the 2.0 release.
-     */
-    @Deprecated
-    public LdapContext getLdapContext(String username, String password) throws NamingException {
-        if (username != null && principalSuffix != null) {
-            username += principalSuffix;
-        }
-        return getLdapContext((Object) username, password);
-    }
-
     public LdapContext getLdapContext(Object principal, Object credentials) throws NamingException {
         if (url == null) {
             throw new IllegalStateException("An LDAP URL must be specified of the form ldap://<hostname>:<port>");
@@ -314,4 +295,4 @@ public class DefaultLdapContextFactory implements LdapContextFactory {
         }
     }
 
-}
\ No newline at end of file
+}
diff --git a/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapContextFactory.java b/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapContextFactory.java
index 548057e..b1b22d8 100644
--- a/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapContextFactory.java
+++ b/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapContextFactory.java
@@ -399,23 +399,7 @@ public class JndiLdapContextFactory implements LdapContextFactory {
      * @throws NamingException if there is a problem connecting to the LDAP directory
      */
     public LdapContext getSystemLdapContext() throws NamingException {
-        return getLdapContext((Object)getSystemUsername(), getSystemPassword());
-    }
-
-    /**
-     * Deprecated - use {@link #getLdapContext(Object, Object)} instead.  This will be removed before Apache Shiro 2.0.
-     *
-     * @param username the username to use when creating the connection.
-     * @param password the password to use when creating the connection.
-     * @return a {@code LdapContext} bound using the given username and password.
-     * @throws javax.naming.NamingException if there is an error creating the context.
-     * @deprecated the {@link #getLdapContext(Object, Object)} method should be used in all cases to ensure more than
-     *             String principals and credentials can be used.  Shiro no longer calls this method - it will be
-     *             removed before the 2.0 release.
-     */
-    @Deprecated
-    public LdapContext getLdapContext(String username, String password) throws NamingException {
-        return getLdapContext((Object) username, password);
+        return getLdapContext(getSystemUsername(), getSystemPassword());
     }
 
     /**
diff --git a/core/src/main/java/org/apache/shiro/realm/ldap/LdapContextFactory.java b/core/src/main/java/org/apache/shiro/realm/ldap/LdapContextFactory.java
index 0cc90fe..373bff7 100644
--- a/core/src/main/java/org/apache/shiro/realm/ldap/LdapContextFactory.java
+++ b/core/src/main/java/org/apache/shiro/realm/ldap/LdapContextFactory.java
@@ -40,20 +40,6 @@ public interface LdapContextFactory {
     LdapContext getSystemLdapContext() throws NamingException;
 
     /**
-     * Creates (or retrieves from a pool) a {@code LdapContext} connection bound using the username and password
-     * specified.
-     *
-     * @param username the username to use when creating the connection.
-     * @param password the password to use when creating the connection.
-     * @return a {@code LdapContext} bound using the given username and password.
-     * @throws javax.naming.NamingException if there is an error creating the context.
-     * @deprecated the {@link #getLdapContext(Object, Object)} method should be used in all cases to ensure more than
-     * String principals and credentials can be used.
-     */
-    @Deprecated
-    LdapContext getLdapContext(String username, String password) throws NamingException;
-
-    /**
      * Creates (or retrieves from a pool) an {@code LdapContext} connection bound using the specified principal and
      * credentials.  The format of the principal and credentials are whatever is supported by the underlying
      * LDAP {@link javax.naming.spi.InitialContextFactory InitialContextFactory} implementation.  The default Sun
diff --git a/core/src/test/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactoryTest.java b/core/src/test/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactoryTest.java
index 9a52a3b..b383fb7 100644
--- a/core/src/test/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactoryTest.java
+++ b/core/src/test/java/org/apache/shiro/realm/ldap/DefaultLdapContextFactoryTest.java
@@ -61,12 +61,12 @@ public class DefaultLdapContextFactoryTest
         //garbage URL to test that the context is being created, but fails:
         String brokenHost = UUID.randomUUID().toString();
         factory.setUrl("ldap://" + brokenHost + ":389");
-        factory.getLdapContext((Object) "foo", "bar");
+        factory.getLdapContext("foo", "bar");
     }
 
     @Test(expected = IllegalStateException.class)
     public void testGetLdapContextWithoutUrl() throws NamingException {
-        factory.getLdapContext((Object) "foo", "bar");
+        factory.getLdapContext("foo", "bar");
     }
 
 
@@ -76,25 +76,25 @@ public class DefaultLdapContextFactoryTest
     @Test(expected = AuthenticationException.class)
     public void testEmptyStringCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", "");
+        factory.getLdapContext("jcoder", "");
     }
 
     @Test(expected = AuthenticationException.class)
     public void testEmptyCharArrayCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", new char[0]);
+        factory.getLdapContext("jcoder", new char[0]);
     }
 
     @Test(expected = AuthenticationException.class)
     public void testEmptyByteArrayCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", new byte[0]);
+        factory.getLdapContext("jcoder", new byte[0]);
     }
 
     @Test(expected = AuthenticationException.class)
     public void testEmptyNullCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", null);
+        factory.getLdapContext("jcoder", null);
     }
 
 
diff --git a/core/src/test/java/org/apache/shiro/realm/ldap/JndiLdapContextFactoryTest.java b/core/src/test/java/org/apache/shiro/realm/ldap/JndiLdapContextFactoryTest.java
index 87ce184..a1e0ee7 100644
--- a/core/src/test/java/org/apache/shiro/realm/ldap/JndiLdapContextFactoryTest.java
+++ b/core/src/test/java/org/apache/shiro/realm/ldap/JndiLdapContextFactoryTest.java
@@ -66,7 +66,7 @@ public class JndiLdapContextFactoryTest {
         //garbage URL to test that the context is being created, but fails:
         String brokenHost = UUID.randomUUID().toString();
         factory.setUrl("ldap://" + brokenHost + ":389");
-        factory.getLdapContext((Object) "foo", "bar");
+        factory.getLdapContext("foo", "bar");
     }
 
     @Test
@@ -105,7 +105,7 @@ public class JndiLdapContextFactoryTest {
 
     @Test(expected = IllegalStateException.class)
     public void testGetLdapContextWithoutUrl() throws NamingException {
-        factory.getLdapContext((Object) "foo", "bar");
+        factory.getLdapContext("foo", "bar");
     }
 
     @Test
@@ -123,7 +123,7 @@ public class JndiLdapContextFactoryTest {
         };
 
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object) "foo", "bar");
+        factory.getLdapContext("foo", "bar");
     }
 
     @SuppressWarnings({"deprecation"})
@@ -189,25 +189,25 @@ public class JndiLdapContextFactoryTest {
     @Test(expected = AuthenticationException.class)
     public void testEmptyStringCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", "");
+        factory.getLdapContext("jcoder", "");
     }
 
     @Test(expected = AuthenticationException.class)
     public void testEmptyCharArrayCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", new char[0]);
+        factory.getLdapContext("jcoder", new char[0]);
     }
 
     @Test(expected = AuthenticationException.class)
     public void testEmptyByteArrayCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", new byte[0]);
+        factory.getLdapContext("jcoder", new byte[0]);
     }
 
     @Test(expected = AuthenticationException.class)
     public void testEmptyNullCredentials() throws NamingException {
         factory.setUrl("ldap://localhost:389");
-        factory.getLdapContext((Object)"jcoder", null);
+        factory.getLdapContext("jcoder", null);
     }