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

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


The following commit(s) were added to refs/heads/master by this push:
     new c1278d57f02 Remove AuthenticatorFactory's impl classes (#24139)
c1278d57f02 is described below

commit c1278d57f02ac6f42501a18606559e07f804289f
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 13 18:44:13 2023 +0800

    Remove AuthenticatorFactory's impl classes (#24139)
---
 .../authentication/AuthenticatorFactory.java       | 17 +++++-------
 .../authentication/MySQLAuthenticationHandler.java |  5 ++--
 .../authenticator/MySQLAuthenticatorFactory.java   | 30 ----------------------
 .../OpenGaussAuthenticationHandler.java            |  5 ++--
 .../OpenGaussAuthenticatorFactory.java             | 30 ----------------------
 .../PostgreSQLAuthenticationHandler.java           |  5 ++--
 .../PostgreSQLAuthenticatorFactory.java            | 30 ----------------------
 7 files changed, 16 insertions(+), 106 deletions(-)

diff --git 
a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/authentication/AuthenticatorFactory.java
 
b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/authentication/AuthenticatorFactory.java
index c8cd52f750d..4efae089612 100644
--- 
a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/authentication/AuthenticatorFactory.java
+++ 
b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/authentication/AuthenticatorFactory.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.proxy.frontend.authentication;
 
-import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.authority.rule.AuthorityRule;
 
@@ -26,21 +25,19 @@ import java.util.Arrays;
 /**
  * Authenticator factory.
  */
-@RequiredArgsConstructor
-public abstract class AuthenticatorFactory<E extends Enum<E> & 
AuthenticatorType> {
-    
-    private final Class<E> enumClass;
+public final class AuthenticatorFactory<E extends Enum<E> & AuthenticatorType> 
{
     
     /**
      * Create new instance of authenticator.
      * 
+     * @param authenticatorTypeClass authenticator type class
      * @param authenticationMethod authentication method
      * @param rule authority rule
      * @return new instance of authenticator
      */
     @SneakyThrows(ReflectiveOperationException.class)
-    public Authenticator newInstance(final String authenticationMethod, final 
AuthorityRule rule) {
-        E authenticatorType = getAuthenticatorType(authenticationMethod);
+    public Authenticator newInstance(final Class<E> authenticatorTypeClass, 
final String authenticationMethod, final AuthorityRule rule) {
+        E authenticatorType = getAuthenticatorType(authenticatorTypeClass, 
authenticationMethod);
         try {
             return 
authenticatorType.getAuthenticatorClass().getConstructor().newInstance();
         } catch (final NoSuchMethodException ignored) {
@@ -48,11 +45,11 @@ public abstract class AuthenticatorFactory<E extends 
Enum<E> & AuthenticatorType
         }
     }
     
-    private E getAuthenticatorType(final String authenticationMethod) {
+    private E getAuthenticatorType(final Class<E> authenticatorTypeClass, 
final String authenticationMethod) {
         try {
-            return E.valueOf(enumClass, authenticationMethod.toUpperCase());
+            return E.valueOf(authenticatorTypeClass, 
authenticationMethod.toUpperCase());
         } catch (final IllegalArgumentException ignored) {
-            return 
Arrays.stream(enumClass.getEnumConstants()).filter(AuthenticatorType::isDefault).findAny().orElseThrow(IllegalArgumentException::new);
+            return 
Arrays.stream(authenticatorTypeClass.getEnumConstants()).filter(AuthenticatorType::isDefault).findAny().orElseThrow(IllegalArgumentException::new);
         }
     }
 }
diff --git 
a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
 
b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
index d7b176ee724..7841ca11f3f 100644
--- 
a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
+++ 
b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
@@ -26,7 +26,8 @@ import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.frontend.authentication.Authenticator;
-import 
org.apache.shardingsphere.proxy.frontend.mysql.authentication.authenticator.MySQLAuthenticatorFactory;
+import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
+import 
org.apache.shardingsphere.proxy.frontend.mysql.authentication.authenticator.MySQLAuthenticatorType;
 
 import java.util.Optional;
 
@@ -65,6 +66,6 @@ public final class MySQLAuthenticationHandler {
      * @return authenticator
      */
     public Authenticator getAuthenticator(final AuthorityRule rule, final 
ShardingSphereUser user) {
-        return new 
MySQLAuthenticatorFactory().newInstance(rule.getAuthenticatorType(user), rule);
+        return new 
AuthenticatorFactory<MySQLAuthenticatorType>().newInstance(MySQLAuthenticatorType.class,
 rule.getAuthenticatorType(user), rule);
     }
 }
diff --git 
a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/authenticator/MySQLAuthenticatorFactory.java
 
b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/authenticator/MySQLAuthenticatorFactory.java
deleted file mode 100644
index eb1b846bdc2..00000000000
--- 
a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/authenticator/MySQLAuthenticatorFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.apache.shardingsphere.proxy.frontend.mysql.authentication.authenticator;
-
-import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
-
-/**
- * Authenticator factory for MySQL.
- */
-public final class MySQLAuthenticatorFactory extends 
AuthenticatorFactory<MySQLAuthenticatorType> {
-    
-    public MySQLAuthenticatorFactory() {
-        super(MySQLAuthenticatorType.class);
-    }
-}
diff --git 
a/proxy/frontend/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
 
b/proxy/frontend/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
index a0d123191b2..6722b35ac62 100644
--- 
a/proxy/frontend/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
+++ 
b/proxy/frontend/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
@@ -33,7 +33,8 @@ import 
org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.frontend.authentication.Authenticator;
-import 
org.apache.shardingsphere.proxy.frontend.opengauss.authentication.authenticator.OpenGaussAuthenticatorFactory;
+import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
+import 
org.apache.shardingsphere.proxy.frontend.opengauss.authentication.authenticator.OpenGaussAuthenticatorType;
 
 import javax.crypto.Mac;
 import javax.crypto.SecretKeyFactory;
@@ -148,6 +149,6 @@ public final class OpenGaussAuthenticationHandler {
     }
     
     private static Authenticator getAuthenticator(final AuthorityRule rule, 
final ShardingSphereUser user) {
-        return new 
OpenGaussAuthenticatorFactory().newInstance(rule.getAuthenticatorType(user), 
rule);
+        return new 
AuthenticatorFactory<OpenGaussAuthenticatorType>().newInstance(OpenGaussAuthenticatorType.class,
 rule.getAuthenticatorType(user), rule);
     }
 }
diff --git 
a/proxy/frontend/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/authenticator/OpenGaussAuthenticatorFactory.java
 
b/proxy/frontend/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/authenticator/OpenGaussAuthenticatorFactory.java
deleted file mode 100644
index 465be761eab..00000000000
--- 
a/proxy/frontend/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/authenticator/OpenGaussAuthenticatorFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.apache.shardingsphere.proxy.frontend.opengauss.authentication.authenticator;
-
-import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
-
-/**
- * Authenticator factory for openGauss.
- */
-public final class OpenGaussAuthenticatorFactory extends 
AuthenticatorFactory<OpenGaussAuthenticatorType> {
-    
-    public OpenGaussAuthenticatorFactory() {
-        super(OpenGaussAuthenticatorType.class);
-    }
-}
diff --git 
a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
 
b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
index 07e8b35a731..4dec2e17999 100644
--- 
a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
+++ 
b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
@@ -30,7 +30,8 @@ import 
org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.frontend.authentication.Authenticator;
-import 
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.PostgreSQLAuthenticatorFactory;
+import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
+import 
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.PostgreSQLAuthenticatorType;
 
 import java.util.Optional;
 
@@ -67,6 +68,6 @@ public final class PostgreSQLAuthenticationHandler {
      * @return authenticator
      */
     public Authenticator getAuthenticator(final AuthorityRule rule, final 
ShardingSphereUser user) {
-        return new 
PostgreSQLAuthenticatorFactory().newInstance(rule.getAuthenticatorType(user), 
rule);
+        return new 
AuthenticatorFactory<PostgreSQLAuthenticatorType>().newInstance(PostgreSQLAuthenticatorType.class,
 rule.getAuthenticatorType(user), rule);
     }
 }
diff --git 
a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/authenticator/PostgreSQLAuthenticatorFactory.java
 
b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/authenticator/PostgreSQLAuthenticatorFactory.java
deleted file mode 100644
index 38c5de562be..00000000000
--- 
a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/authenticator/PostgreSQLAuthenticatorFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator;
-
-import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
-
-/**
- * Authenticator factory for PostgreSQL.
- */
-public final class PostgreSQLAuthenticatorFactory extends 
AuthenticatorFactory<PostgreSQLAuthenticatorType> {
-    
-    public PostgreSQLAuthenticatorFactory() {
-        super(PostgreSQLAuthenticatorType.class);
-    }
-}

Reply via email to