forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat](Authenticator) Pluginization of Authenticator (apache#40113)
## abstract introduces the pluginization of the Authenticator component, enabling greater flexibility and modularity within the authentication system. By refactoring the Authenticator into a pluggable SPI (Service Provider Interface), we allow for custom authentication mechanisms to be seamlessly integrated and managed. ## Key Changes AuthenticatorFactory Interface: This interface defines the create method, which is used to create an Authenticator instance based on initialization properties, enabling support for various authentication mechanisms. The factoryIdentifier method provides an identifier for the factory, allowing differentiation between various AuthenticatorFactory implementations (e.g., LDAP, default). Implemented Specific Authentication Factories: We have implemented factories for different authentication mechanisms (such as LDAP), providing the necessary configuration support for each. ## eg In your Maven pom.xml, add the fe-core dependency: ``` <dependency> <groupId>org.apache.doris</groupId> <artifactId>fe-core</artifactId> <version>1.2-SNAPSHOT</version> <scope>provided</scope> </dependency> ``` ``` import org.apache.doris.common.ConfigBase; public class LocalAuthenticatorFactory implements AuthenticatorFactory { @OverRide public LocalAuthenticator create(Properties initProps) { return new LocalAuthenticator(); } @OverRide public String factoryIdentifier() { return "local"; } } import java.util.HashMap; import java.util.Map; public class LocalAuthenticator implements Authenticator { private Map<String, String> userStore = new HashMap<>(); public LocalAuthenticator() { // Hardcoded usernames and passwords userStore.put("user1", "password1"); userStore.put("user2", "password2"); userStore.put("admin", "adminpass"); } @OverRide public boolean authenticate(String username, String password) { // Authenticate by checking the hardcoded user store String storedPassword = userStore.get(username); return storedPassword != null && storedPassword.equals(password); } } ``` To integrate with the SPI (Service Provider Interface) mechanism, we created a file at **src/main/resources/META-INF/services/org.apache.doris.mysql.authenticate.AuthenticatorFactory** containing **org.example.LocalAuthenticatorFactory,** which allows the system to dynamically load and utilize the LocalAuthenticatorFactory implementation. Your plugin needs to include all necessary dependencies, and it is generally recommended to package them into an Uber JAR (also known as a Fat JAR) to ensure that the plugin can run independently without additional dependency management. Once packaged, this JAR can be placed directly in the **fe/custom_lib** directory.
- Loading branch information
1 parent
4e0362e
commit 121960f
Showing
8 changed files
with
199 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
fe/fe-core/src/main/java/org/apache/doris/mysql/authenticate/AuthenticatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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.doris.mysql.authenticate; | ||
|
||
import java.util.Properties; | ||
|
||
public interface AuthenticatorFactory { | ||
/** | ||
* Creates a new instance of Authenticator. | ||
* | ||
* @return an instance of Authenticator | ||
*/ | ||
Authenticator create(Properties initProps); | ||
|
||
/** | ||
* Returns the identifier for the factory, such as "ldap" or "default". | ||
* | ||
* @return the factory identifier | ||
*/ | ||
String factoryIdentifier(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...e-core/src/main/java/org/apache/doris/mysql/authenticate/DefaultAuthenticatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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.doris.mysql.authenticate; | ||
|
||
import java.util.Properties; | ||
|
||
public class DefaultAuthenticatorFactory implements AuthenticatorFactory { | ||
@Override | ||
public DefaultAuthenticator create(Properties initProps) { | ||
return new DefaultAuthenticator(); | ||
} | ||
|
||
@Override | ||
public String factoryIdentifier() { | ||
return "default"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...core/src/main/java/org/apache/doris/mysql/authenticate/ldap/LdapAuthenticatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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.doris.mysql.authenticate.ldap; | ||
|
||
import org.apache.doris.mysql.authenticate.AuthenticatorFactory; | ||
|
||
import java.util.Properties; | ||
|
||
public class LdapAuthenticatorFactory implements AuthenticatorFactory { | ||
|
||
|
||
@Override | ||
public LdapAuthenticator create(Properties initProps) { | ||
return new LdapAuthenticator(); | ||
} | ||
|
||
@Override | ||
public String factoryIdentifier() { | ||
return "ldap"; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...main/resources/META-INF/services/org.apache.doris.mysql.authenticate.AuthenticatorFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# 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. | ||
# | ||
# | ||
org.apache.doris.mysql.authenticate.DefaultAuthenticatorFactory | ||
org.apache.doris.mysql.authenticate.ldap.LdapAuthenticatorFactory |