Skip to content

Commit

Permalink
make authentication providers configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatsai committed Jan 16, 2025
1 parent e65a18c commit 34bbc07
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
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.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<String> providers = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jwt:
secretKey:
algorithm: HS256

seatunnel:
authentication:
providers:
- DB
#- LDAP # LDAP authentication is disabled by default

---
spring:
config:
Expand Down

0 comments on commit 34bbc07

Please sign in to comment.