diff --git a/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/config/SeatunnelAuthenticationProvidersConfig.java b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/config/SeatunnelAuthenticationProvidersConfig.java new file mode 100644 index 000000000..7f2244839 --- /dev/null +++ b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/config/SeatunnelAuthenticationProvidersConfig.java @@ -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.seatunnel.app.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@Configuration +@ConfigurationProperties(prefix = "seatunnel.authentication") +public class SeatunnelAuthenticationProvidersConfig { + private List providers = new ArrayList<>(); +} diff --git a/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/service/impl/UserServiceImpl.java b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/service/impl/UserServiceImpl.java index 47bf35278..c32c8f1ea 100644 --- a/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/service/impl/UserServiceImpl.java +++ b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/service/impl/UserServiceImpl.java @@ -19,6 +19,7 @@ import org.apache.seatunnel.app.common.Constants; import org.apache.seatunnel.app.common.UserTokenStatusEnum; +import org.apache.seatunnel.app.config.SeatunnelAuthenticationProvidersConfig; import org.apache.seatunnel.app.dal.dao.IUserDao; import org.apache.seatunnel.app.dal.entity.User; import org.apache.seatunnel.app.domain.dto.user.ListUserDto; @@ -74,10 +75,21 @@ public class UserServiceImpl implements IUserService { @Autowired private LDAPAuthenticationStrategy ldapAuthenticationStrategy; + @Autowired + private SeatunnelAuthenticationProvidersConfig seatunnelAuthenticationProvidersConfig; + @PostConstruct public void init() { - strategies.put(Constants.AUTHENTICATION_PROVIDER_DB, dbAuthenticationStrategy); - strategies.put(Constants.AUTHENTICATION_PROVIDER_LDAP, ldapAuthenticationStrategy); + if (seatunnelAuthenticationProvidersConfig + .getProviders() + .contains(Constants.AUTHENTICATION_PROVIDER_DB)) { + strategies.put(Constants.AUTHENTICATION_PROVIDER_DB, dbAuthenticationStrategy); + } + if (seatunnelAuthenticationProvidersConfig + .getProviders() + .contains(Constants.AUTHENTICATION_PROVIDER_LDAP)) { + strategies.put(Constants.AUTHENTICATION_PROVIDER_LDAP, ldapAuthenticationStrategy); + } } @Override diff --git a/seatunnel-server/seatunnel-app/src/main/resources/application.yml b/seatunnel-server/seatunnel-app/src/main/resources/application.yml index fbfbe5612..bebf274ab 100644 --- a/seatunnel-server/seatunnel-app/src/main/resources/application.yml +++ b/seatunnel-server/seatunnel-app/src/main/resources/application.yml @@ -44,6 +44,12 @@ jwt: secretKey: algorithm: HS256 +seatunnel: + authentication: + providers: + - DB + #- LDAP # LDAP authentication is disabled by default + --- spring: config: