Unverified Commit 26979fda authored by gaoyan's avatar gaoyan Committed by GitHub

Add ldap support (#2029)

* fix BusException logic error if BusException.msg is empty, use I18n message * add ldap ui * add ldap login support * add some i81n config * fix code style
parent 295146ef
......@@ -304,6 +304,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
</dependencies>
<build>
......
/*
*
* 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.dinky.controller;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.result.Result;
import org.dinky.service.LdapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/api/ldap")
@RequiredArgsConstructor
public class LdapController {
@Autowired LdapService ldapService;
/** Gets the LDAP configuration status */
@GetMapping("/ldapEnableStatus")
public Result<Boolean> ldapStatus() {
return Result.succeed(
SystemConfiguration.getInstances().getLdapEnable().getValue(), "获取成功");
}
// @PostMapping("/listUser")
// public ProTableResult<User> listUser(@RequestBody LdapConfig ldapConfig) {
// List<User> users = ldapService.listUsers(ldapConfig);
// return ProTableResult.<User>builder()
// .success(true)
// .data(users)
// .total((long) users.size())
//// .current(1)
//// .pageSize(1)
// .build();
// }
}
......@@ -23,7 +23,6 @@ import org.dinky.assertion.Asserts;
import org.dinky.data.dto.ModifyPasswordDTO;
import org.dinky.data.enums.Status;
import org.dinky.data.model.User;
import org.dinky.data.model.UserTenant;
import org.dinky.data.params.AssignRoleParams;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
......@@ -42,7 +41,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import cn.hutool.core.lang.Dict;
......@@ -214,16 +212,7 @@ public class UserController {
@GetMapping("/getUserListByTenantId")
public Result<Dict> getUserListByTenantId(@RequestParam("id") Integer id) {
List<User> userList = userService.list();
List<UserTenant> userTenants =
userTenantService
.getBaseMapper()
.selectList(
new LambdaQueryWrapper<UserTenant>()
.eq(UserTenant::getTenantId, id));
List<Integer> userIds = new ArrayList<>();
for (UserTenant userTenant : userTenants) {
userIds.add(userTenant.getUserId());
}
List<Integer> userIds = userService.getUserIdsByTeantId(id);
Dict result = Dict.create().set("users", userList).set("userIds", userIds);
return Result.succeed(result);
}
......
......@@ -35,4 +35,5 @@ public class LoginDTO {
private String password;
private Integer tenantId;
private boolean autoLogin;
private boolean ldapLogin;
}
/*
*
* 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.dinky.data.enums;
public enum UserType {
LDAP(0, "LDAP"),
LOCAL(1, "LOCAL");
private final int code;
private final String type;
public int getCode() {
return this.code;
}
UserType(int code, String type) {
this.code = code;
this.type = type;
}
}
/*
*
* 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.dinky.data.exception;
import org.dinky.data.enums.Status;
import lombok.Data;
/**
* AuthException About login error
*
* @since 2021/5/28 14:21
*/
@Data
public class AuthException extends Exception {
private Status status;
public AuthException(Status status) {
super(status.getMsg());
this.status = status;
}
public AuthException(Throwable cause, Status status) {
super(status.getMsg(), cause);
this.status = status;
}
}
/*
*
* 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.dinky.data.model;
import javax.naming.directory.Attributes;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LdapUserIdentification {
private String absoluteDn;
private String relativeDn;
private Attributes attributes;
}
......@@ -60,6 +60,8 @@ public class User implements Serializable {
private String nickname;
private int userType;
private String worknum;
private byte[] avatar;
......
......@@ -21,10 +21,14 @@ package org.dinky.data.params;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/** assign role params */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AssignUserToTenantParams {
Integer tenantId;
List<Integer> userIds;
......
/*
*
* 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.dinky.service;
import org.dinky.data.dto.LoginDTO;
import org.dinky.data.exception.AuthException;
import org.dinky.data.model.User;
import javax.naming.NamingException;
public interface LdapService {
// List<User> listUsers(LdapConfig ldapConfig);
/**
* Authenticates the user based on the provided login credentials. Throws AuthException if
* authentication fails.
*
* @param loginDTO The login user info
* @return ldap user
*/
User authenticate(LoginDTO userDTO) throws AuthException, NamingException;
}
......@@ -154,4 +154,11 @@ public interface UserService extends ISuperService<User> {
/** user loginout */
void outLogin();
/**
* get user ids where user in given tenant id
*
* @return role select permissions list
*/
List<Integer> getUserIdsByTeantId(int id);
}
/*
*
* 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.dinky.service.impl;
import org.dinky.data.dto.LoginDTO;
import org.dinky.data.enums.Status;
import org.dinky.data.exception.AuthException;
import org.dinky.data.model.LdapUserIdentification;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.User;
import org.dinky.service.LdapService;
import java.util.List;
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import org.springframework.ldap.AuthenticationException;
import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class LdapServiceImpl implements LdapService {
SystemConfiguration configuration = SystemConfiguration.getInstances();
/**
* Authenticates the user based on the provided login credentials. Throws AuthException if
* authentication fails.
*
* @param loginDTO The login user info
* @return ldap user
*/
@Override
public User authenticate(LoginDTO loginDTO) throws AuthException {
LdapTemplate ldapTemplate = new LdapTemplate(getLdapContext());
// Build LDAP filter, The LdapCastUsername is map to Dinky UserName
String filter =
String.format(
"(&%s(%s=%s))",
configuration.getLdapFilter().getValue(),
configuration.getLdapCastUsername().getValue(),
loginDTO.getUsername());
// Perform search operation, we have alreday config baseDn in global
// so the param base has config ""
List<LdapUserIdentification> result =
ldapTemplate.search("", filter, getControls(), new UserContextMapper());
// Only if the returned result is one is correct,
// otherwise the corresponding exception is thrown
if (result.size() == 0) {
log.info(
String.format(
"No results found for search, base: '%s'; filter: '%s'",
configuration.getLdapBaseDn(), filter));
throw new AuthException(Status.USER_NOT_EXIST);
} else if (result.size() > 1) {
log.error(
String.format(
"IncorrectResultSize, base: '%s'; filter: '%s'",
configuration.getLdapBaseDn(), filter));
throw new AuthException(Status.LDAP_USER_DUPLICAT);
} else {
LdapUserIdentification ldapUserIdentification = result.get(0);
try {
Attributes attributes = ldapUserIdentification.getAttributes();
// Validate username and password
getLdapContext()
.getContext(ldapUserIdentification.getAbsoluteDn(), loginDTO.getPassword());
// If no exception is thrown, then the login is successful,
// Build the User with cast
User user = new User();
user.setUsername(loginDTO.getUsername());
user.setNickname(
attributes
.get(configuration.getLdapCastNickname().getValue())
.get()
.toString());
return user;
} catch (Exception e) {
if (e instanceof AuthenticationException) {
throw new AuthException(e.getCause(), Status.USER_NAME_PASSWD_ERROR);
} else {
throw new RuntimeException(e);
}
}
}
}
private LdapContextSource getLdapContext() {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl(configuration.getLdapUrl().getValue());
contextSource.setBase(configuration.getLdapBaseDn().getValue());
contextSource.setUserDn(configuration.getLdapUserDn().getValue());
contextSource.setPassword(configuration.getLdapUserPassword().getValue());
contextSource.afterPropertiesSet();
return contextSource;
}
private SearchControls getControls() {
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
// controls.setCountLimit(ldapConfig.getCountLimit());
controls.setTimeLimit(configuration.getLdapTimeLimit().getValue());
return controls;
}
private static class UserContextMapper implements ContextMapper<LdapUserIdentification> {
public LdapUserIdentification mapFromContext(Object ctx) {
DirContextOperations adapter = (DirContextOperations) ctx;
return new LdapUserIdentification(
adapter.getNameInNamespace(),
adapter.getDn().toString(),
adapter.getAttributes());
}
}
}
......@@ -26,13 +26,17 @@ import org.dinky.data.dto.LoginDTO;
import org.dinky.data.dto.ModifyPasswordDTO;
import org.dinky.data.dto.UserDTO;
import org.dinky.data.enums.Status;
import org.dinky.data.enums.UserType;
import org.dinky.data.exception.AuthException;
import org.dinky.data.model.Role;
import org.dinky.data.model.RowPermissions;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.Tenant;
import org.dinky.data.model.User;
import org.dinky.data.model.UserRole;
import org.dinky.data.model.UserTenant;
import org.dinky.data.params.AssignRoleParams;
import org.dinky.data.params.AssignUserToTenantParams;
import org.dinky.data.result.Result;
import org.dinky.mapper.UserMapper;
import org.dinky.mybatis.service.impl.SuperServiceImpl;
......@@ -80,6 +84,8 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
private final RowPermissionsService roleSelectPermissionsService;
private final LdapServiceImpl ldapService;
@Override
public Result<Void> registerUser(User user) {
User userByUsername = getUserByUsername(user.getUsername());
......@@ -129,30 +135,104 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
return baseMapper.deleteById(id) > 0;
}
/**
* The user login method is to determine whether to use ldap authentication or local
* authentication according to the field isLdapLogin. After the ldap authentication is
* successful, it will automatically find the local mapped data to return
*
* @param loginDTO a user based on the provided login credentials.
* @return a Result object containing the user information if the login is successful, or an
* appropriate error status if the login fails.
*/
@Override
public Result<UserDTO> loginUser(LoginDTO loginDTO) {
User user = null;
try {
// Determine the login method (LDAP or local) based on the flag in loginDTO
user = loginDTO.isLdapLogin() ? ldapLogin(loginDTO) : localLogin(loginDTO);
} catch (AuthException e) {
// Handle authentication exceptions and return the corresponding error status
return Result.failed(e.getStatus());
}
// Check if the user is enabled
if (!user.getEnabled()) {
return Result.failed(Status.USER_DISABLED_BY_ADMIN);
}
UserDTO userInfo = refreshUserInfo(user);
if (Asserts.isNullCollection(userInfo.getTenantList())) {
return Result.failed(Status.USER_NOT_BINDING_TENANT);
}
// Perform login using StpUtil (Assuming it handles the session management)
StpUtil.login(user.getId(), loginDTO.isAutoLogin());
// Return the user information along with a success status
return Result.succeed(userInfo, Status.LOGIN_SUCCESS);
}
private User localLogin(LoginDTO loginDTO) throws AuthException {
// Get user from local database by username
User user = getUserByUsername(loginDTO.getUsername());
if (Asserts.isNull(user)) {
return Result.failed(Status.USER_NOT_EXIST);
// User doesn't exist
throw new AuthException(Status.USER_NOT_EXIST);
}
String userPassword = user.getPassword();
// Check if the provided password is null
if (Asserts.isNullString(loginDTO.getPassword())) {
return Result.failed(Status.LOGIN_PASSWORD_NOT_NULL);
throw new AuthException(Status.LOGIN_PASSWORD_NOT_NULL);
}
// Compare the hashed form of the provided password with the stored password
if (Asserts.isEquals(SaSecureUtil.md5(loginDTO.getPassword()), userPassword)) {
if (!user.getEnabled()) {
return Result.failed(Status.USER_DISABLED_BY_ADMIN);
return user;
} else {
throw new AuthException(Status.USER_NAME_PASSWD_ERROR);
}
}
private User ldapLogin(LoginDTO loginDTO) throws AuthException {
// Authenticate user against LDAP
User userFromLdap = ldapService.authenticate(loginDTO);
// Get user from local database
User userFromLocal = getUserByUsername(loginDTO.getUsername());
if (Asserts.isNull(userFromLocal)) {
// User doesn't exist locally
// Check if LDAP user autoload is enabled
if (!SystemConfiguration.getInstances().getLdapAutoload().getValue()) {
throw new AuthException(Status.LDAP_USER_AUTOLOAD_FORBAID);
}
// get user tenants and roles
UserDTO userInfo = refreshUserInfo(user);
if (Asserts.isNullCollection(userInfo.getTenantList())) {
return Result.failed(Status.USER_NOT_BINDING_TENANT);
// Get default tenant from system configuration
String defaultTeantCode =
SystemConfiguration.getInstances().getLdapDefaultTeant().getValue();
Tenant tenant = tenantService.getTenantByTenantCode(defaultTeantCode);
if (Asserts.isNull(tenant)) {
throw new AuthException(Status.LDAP_DEFAULT_TENANT_NOFOUND);
}
StpUtil.login(user.getId(), loginDTO.isAutoLogin());
return Result.succeed(userInfo, Status.LOGIN_SUCCESS);
} else {
return Result.failed(Status.LOGIN_FAILURE);
// Update LDAP user properties and save
userFromLdap.setUserType(UserType.LDAP.getCode());
userFromLdap.setEnabled(true);
userFromLdap.setIsAdmin(false);
userFromLdap.setIsDelete(false);
save(userFromLdap);
// Assign the user to the default tenant
List<Integer> userIds = getUserIdsByTeantId(tenant.getId());
User user = getUserByUsername(loginDTO.getUsername());
userIds.add(user.getId());
tenantService.assignUserToTenant(new AssignUserToTenantParams(tenant.getId(), userIds));
return user;
}
// If local database have the user and ldap login is pass,
// Return user from local database
return userFromLocal;
}
private UserDTO refreshUserInfo(User user) {
......@@ -315,4 +395,19 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
public void outLogin() {
StpUtil.logout();
}
@Override
public List<Integer> getUserIdsByTeantId(int id) {
List<UserTenant> userTenants =
userTenantService
.getBaseMapper()
.selectList(
new LambdaQueryWrapper<UserTenant>()
.eq(UserTenant::getTenantId, id));
List<Integer> userIds = new ArrayList<>();
for (UserTenant userTenant : userTenants) {
userIds.add(userTenant.getUserId());
}
return userIds;
}
}
......@@ -103,6 +103,12 @@ public enum Status {
SWITCHING_TENANT_SUCCESS(10018, "Select Tenant Success", "选择租户成功"),
// user.superadmin.cannot.disable
USER_SUPERADMIN_CANNOT_DISABLE(10019, "User SuperAdmin Cannot Disable", "超级管理员用户不能停用"),
LDAP_USER_DUPLICAT(10020, "The ldap matches to multiple user data", "ldap匹配到多个用户数据"),
LDAP_USER_AUTOLOAD_FORBAID(
10021,
"Auto-mapping LDAP users are not enabled, please contact your administrator to import",
"未开启自动映射LDAP用户,请联系管理员导入"),
LDAP_DEFAULT_TENANT_NOFOUND(10021, "The LDAP default tenant does not exist", "LDAP默认租户不存在"),
// role
ROLE_ALREADY_EXISTS(10101, "Role Already Exists", "角色已存在"),
......
......@@ -135,6 +135,58 @@ public class SystemConfiguration {
.defaultValue("Dinky")
.note("The project name specified in DolphinScheduler, case insensitive");
private final Configuration<Boolean> ldapEnable =
key("ldap.settings.enable").booleanType().defaultValue(false).note("LDAP ON-OFF");
private final Configuration<String> ldapUrl =
key("ldap.settings.url").stringType().defaultValue("").note("ldap server address");
private final Configuration<String> ldapUserDn =
key("ldap.settings.userDn")
.stringType()
.defaultValue("")
.note("ldap login dn or username");
private final Configuration<String> ldapUserPassword =
key("ldap.settings.userPassword")
.stringType()
.defaultValue("")
.note("ldap login password");
// private final Configuration<Integer> ldapCountLimit =
// key("ldap.settings.countLimit")
// .intType()
// .defaultValue(0)
// .note("");
private final Configuration<Integer> ldapTimeLimit =
key("ldap.settings.timeLimit")
.intType()
.defaultValue(30)
.note("ldap connection timeout");
private final Configuration<String> ldapBaseDn =
key("ldap.settings.baseDn").stringType().defaultValue("").note("ldap user base dn");
private final Configuration<String> ldapFilter =
key("ldap.settings.filter").stringType().defaultValue("").note("ldap user filter");
private final Configuration<Boolean> ldapAutoload =
key("ldap.settings.autoload")
.booleanType()
.defaultValue(true)
.note("Whether auto-mapping ldap users is enabled");
private final Configuration<String> ldapDefaultTeant =
key("ldap.settings.defaultTeant")
.stringType()
.defaultValue("DefaultTenant")
.note("ldap default default teant code");
private final Configuration<String> ldapCastUsername =
key("ldap.settings.castUsername").stringType().defaultValue("cn").note("");
private final Configuration<String> ldapCastNickname =
key("ldap.settings.castNickname").stringType().defaultValue("sn").note("");
/** Initialize after spring bean startup */
public void initAfterBeanStarted() {
if (StrUtil.isBlank(dinkyAddr.getDefaultValue())) {
......
......@@ -469,6 +469,7 @@ export default {
'sys.setting.flink': 'Flink Configuration',
'sys.setting.maven': 'Maven Configuration',
'sys.setting.ds': 'DolphinScheduler Configuration',
'sys.setting.ldap': 'LDAP Configuration',
'sys.setting.dinky.tooltip': 'Mainly modify system variables to ensure stable operation of basic functions',
'sys.setting.flink.tooltip': 'Dinky docking Flink main parameters',
'sys.setting.maven.tooltip': 'The main parameters of Maven compilation',
......@@ -504,6 +505,31 @@ export default {
'sys.dolphinscheduler.settings.token.note': 'DolphinScheduler‘s Token, please create a token in DolphinScheduler’s Security Center->Token Management, and fill in the configuration',
'sys.dolphinscheduler.settings.projectName': 'DolphinScheduler project name',
'sys.dolphinscheduler.settings.projectName.note': 'The project name specified in DolphinScheduler, case insensitive',
//LDAP
'sys.ldap.settings.enable': 'Whether to enable the ldap',
'sys.ldap.settings.enable.note': 'Turn the LDAP login function on',
'sys.ldap.settings.url': 'ldap address of service',
'sys.ldap.settings.url.note': 'ldap address of service,eg:ldap://192.168.111.1:389 ',
'sys.ldap.settings.userDn': 'Login User name (DN)',
'sys.ldap.settings.userDn.note': 'User name for connecting to the ldap service, or the administrator DN',
'sys.ldap.settings.userPassword': 'login password',
'sys.ldap.settings.userPassword.note': 'Password used to connect to the ldap service',
'sys.ldap.settings.timeLimit': 'Connection Timeout',
'sys.ldap.settings.timeLimit.note': 'The maximum time to connect to the ldap service is disconnected',
'sys.ldap.settings.baseDn': 'BaseDn',
'sys.ldap.settings.baseDn.note': 'Dinky will conduct a user search on this base dn,eg:ou=users,dc=dinky,dc=com',
'sys.ldap.settings.filter': 'User filtering rules',
'sys.ldap.settings.filter.note': 'User filtering by using the filter syntax of the ldap,eg: (&(objectClass=inetOrgPerson))',
'sys.ldap.settings.autoload': 'User atically map users when logging in',
'sys.ldap.settings.autoload.note': 'When turned on, when a user logs in with LDAP, if there is no corresponding Dinky user mapping, the LDAP information is automatically pulled to create a Dinky user mapping to it. If this feature is closed, you will not be able to log in for unimported LDAP users',
'sys.ldap.settings.castUsername': 'The LDAP user-name segment',
'sys.ldap.settings.castUsername.note': 'It is necessary to fill in the attribute field of the user in an LDAP to correspond to the Dinky user. Generally, cn or uid indicates the unique identity of the user',
'sys.ldap.settings.castNickname': 'The LDAP nickname field',
'sys.ldap.settings.castNickname.note': 'Need to fill in the attribute field of the user in an LDAP to correspond to the Dinky nickname, must be filled in, generally selected as sn or other identification, not required unique',
'sys.ldap.settings.defaultTeant': 'The LDAP imports the default tenant code',
'sys.ldap.settings.defaultTeant.note': 'After opening the automatic import of users, the new user login needs a default tenant code, otherwise it cannot log in',
// process
'sys.process.id': 'Process ID',
'sys.process.name': 'Process Name',
......
......@@ -29,6 +29,7 @@ export default {
'login.password.placeholder': '密码',
'login.password.required': '密码是必填项!',
'login.rememberMe': '自动登录',
'login.ldapLogin': 'LDAP登录',
'admin.subPage.title': ' 这个页面只有 admin 权限才能查看',
'about.Community': '欢迎加入 Dinky 官方社区,共建共赢',
'about.QQcode': 'QQ官方社区群',
......@@ -471,6 +472,7 @@ export default {
'sys.setting.flink': 'Flink 配置',
'sys.setting.maven': 'Maven 配置',
'sys.setting.ds': 'DolphinSchuder 配置',
'sys.setting.ldap': 'LDAP配置',
'sys.setting.dinky.tooltip': '主要以修改系统变量为主,保证基础功能稳定运行',
'sys.setting.flink.tooltip': 'Dinky对接 Flink 主要参数',
'sys.setting.maven.tooltip': 'Maven 编译的主要参数',
......@@ -507,6 +509,32 @@ export default {
'sys.dolphinscheduler.settings.projectName': 'DolphinScheduler 项目名',
'sys.dolphinscheduler.settings.projectName.note': 'DolphinScheduler 中指定的项目名称,不区分大小写',
//LDAP
'sys.ldap.settings.enable': '是否启用ldap',
'sys.ldap.settings.enable.note': '开启LDAP登录功能',
'sys.ldap.settings.url': 'ldap服务地址',
'sys.ldap.settings.url.note': 'ldap认证服务地址,例如:ldap://192.168.111.1:389 ',
'sys.ldap.settings.userDn': '登录用户名(DN)',
'sys.ldap.settings.userDn.note': '用于连接ldap服务的用户名,或者管理员DN',
'sys.ldap.settings.userPassword': '登录密码',
'sys.ldap.settings.userPassword.note': '用于连接ldap服务的密码',
// 'sys.ldap.settings.countLimit': '用于连接ldap服务的密码',
// 'sys.ldap.settings.countLimit.note': '用于连接ldap服务的密码',
'sys.ldap.settings.timeLimit': '连接超时',
'sys.ldap.settings.timeLimit.note': '连接ldap服务的最大时间,超过则断开',
'sys.ldap.settings.baseDn': '用户基础DN',
'sys.ldap.settings.baseDn.note': 'Dinky会在此基础dn下进行用户搜索,例如:ou=users,dc=dinky,dc=com',
'sys.ldap.settings.filter': '用户过滤规则',
'sys.ldap.settings.filter.note': '使用ldap的filter语法进行用户过滤,例如: (&(objectClass=inetOrgPerson))',
'sys.ldap.settings.autoload': '登录时自动映射用户',
'sys.ldap.settings.autoload.note': '开启后,当用户使用LDAP登录时,如果没有相应的Dinky用户映射,则会自动拉取LDAP信息创建一个Dinky用户与之映射,如果关闭此功能,对于未导入的LDAP用户将无法登录',
'sys.ldap.settings.castUsername': 'LDAP用户名字段',
'sys.ldap.settings.castUsername.note': '需要填写一个LDAP中用户的属性字段来与Dinky用户对应,必须填写,一般可选为 cn 或者 uid表示用户唯一标识',
'sys.ldap.settings.castNickname': 'LDAP昵称字段',
'sys.ldap.settings.castNickname.note': '需要填写一个LDAP中用户的属性字段来与Dinky昵称对应,必须填写,一般可选为 sn 或者其他标识,不要求唯一',
'sys.ldap.settings.defaultTeant': 'LDAP导入默认租户编码',
'sys.ldap.settings.defaultTeant.note': '开启自动导入用户后,新用户登录需要一个默认的租户编码,否则无法登录',
// process
'sys.process.id': '进程ID',
......
......@@ -17,7 +17,7 @@
*
*/
import React, {useState} from "react";
import React, {useEffect, useState} from "react";
import {l} from "@/utils/intl";
import {ProForm, ProFormCheckbox, ProFormText} from "@ant-design/pro-components";
import {LockOutlined, UserOutlined} from "@ant-design/icons";
......@@ -25,6 +25,9 @@ import MainWithStyle from "./MainWithStyle";
import {SubmitterProps} from "@ant-design/pro-form/es/components";
import style from "../../../../global.less";
import FadeIn from "@/components/Animation/FadeIn";
import {getData} from "@/services/api";
import {API_CONSTANTS} from "@/services/constants";
import {Col, Row} from "antd";
type LoginFormProps = {
onSubmit: (values: any) => Promise<void>;
......@@ -37,6 +40,14 @@ const LoginForm: React.FC<LoginFormProps> = (props) => {
const [form] = ProForm.useForm();
const [submitting, setSubmitting] = useState(false);
const [ldapEnabled, setLdapEnabled] = useState(false);
useEffect(() => {
getData(API_CONSTANTS.GET_LDAP_ENABLE).then(res => {
setLdapEnabled(res.datas)
form.setFieldValue("ldapLogin",res.datas)
})
}, []);
const handleClickLogin = async () => {
......@@ -76,9 +87,18 @@ const LoginForm: React.FC<LoginFormProps> = (props) => {
},
]}
/>
<ProFormCheckbox name="autoLogin">
{l("login.rememberMe")}
</ProFormCheckbox>
<Row>
<Col span={18}>
<ProFormCheckbox name="autoLogin">
{l("login.rememberMe")}
</ProFormCheckbox>
</Col>
<Col span={6}>
<ProFormCheckbox name="ldapLogin" hidden={!ldapEnabled}>
{l("login.ldapLogin")}
</ProFormCheckbox>
</Col>
</Row>
</>;
};
......
/*
* 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.
*/
import {BaseConfigProperties} from '@/types/SettingCenter/data';
import {ProCard} from '@ant-design/pro-components';
import GeneralConfig from '@/pages/SettingCenter/GlobalSetting/SettingOverView/GeneralConfig';
import {l} from '@/utils/intl';
import {Button, Space, Tag} from 'antd';
import React from 'react';
interface LdapConfigProps {
data: BaseConfigProperties[];
onSave: (data: BaseConfigProperties) => void;
}
export const LdapConfig = ({data, onSave}: LdapConfigProps) => {
const [loading, setLoading] = React.useState(false);
const onSaveHandler = (data: BaseConfigProperties) => {
setLoading(true);
onSave(data);
setTimeout(() => {
setLoading(false);
}, 1000);
};
return <>
<ProCard
title={l('sys.setting.ldap')}
tooltip={l('sys.setting.ldap.tooltip')}
size="small"
headerBordered ghost collapsible
defaultCollapsed={false}
>
<GeneralConfig
loading={loading}
onSave={onSaveHandler}
tag={<><Tag color={'default'}>{l('sys.setting.tag.integration')}</Tag></>}
data={data}
/>
</ProCard>
</>;
};
......@@ -23,6 +23,7 @@ import {EnvConfig} from '@/pages/SettingCenter/GlobalSetting/SettingOverView/Env
import {FlinkConfig} from '@/pages/SettingCenter/GlobalSetting/SettingOverView/FlinkConfig';
import {MavenConfig} from '@/pages/SettingCenter/GlobalSetting/SettingOverView/MavenConfig';
import {DSConfig} from '@/pages/SettingCenter/GlobalSetting/SettingOverView/DSConfig';
import {LdapConfig} from "@/pages/SettingCenter/GlobalSetting/SettingOverView/LdapConfig";
import {l} from '@/utils/intl';
const SettingOverView = () => {
......@@ -47,13 +48,19 @@ const SettingOverView = () => {
const renderData = () => {
if (data) {
const {env: dinkyEnv, flink: flinkConfig, maven: mavenConfig, dolphinscheduler: dsConfig} = data;
return <>
const {
env: dinkyEnv,
flink: flinkConfig,
maven: mavenConfig,
dolphinscheduler: dsConfig,
ldap: ldapConfig} = data;
return <div style={{paddingBottom:"20px"}}>
<EnvConfig onSave={handleSaveSubmit} data={dinkyEnv}/>
<FlinkConfig onSave={handleSaveSubmit} data={flinkConfig}/>
<MavenConfig onSave={handleSaveSubmit} data={mavenConfig}/>
<DSConfig onSave={handleSaveSubmit} data={dsConfig}/>
</>;
<LdapConfig onSave={handleSaveSubmit} data={ldapConfig}/>
</div>;
}
};
......
......@@ -180,8 +180,12 @@ export const API_CONSTANTS = {
// process list
PROCESS_LIST: "/api/process/listAllProcess",
// ---- devops
GET_JOB_LIST: "/api/jobInstance",
// -- LDAP
GET_LDAP_ENABLE: "/api/ldap/ldapEnableStatus"
};
......
......@@ -48,6 +48,7 @@ export type Settings = {
env: BaseConfigProperties[];
flink: BaseConfigProperties[];
maven: BaseConfigProperties[];
ldap: BaseConfigProperties[];
}
export type BaseConfigProperties = {
key: string;
......
......@@ -108,6 +108,7 @@
<spotless.ratchetFrom>origin/dev</spotless.ratchetFrom>
<spotless.version>2.27.1</spotless.version>
<spring-boot-dependencies.version>2.7.11</spring-boot-dependencies.version>
<spring.ldap.version>3.1.0</spring.ldap.version>
<target.java.version>8</target.java.version>
<testcontainers.version>1.16.2</testcontainers.version>
</properties>
......@@ -613,6 +614,12 @@
<artifactId>activation</artifactId>
<version>${javax.activation.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
<version>${spring.ldap.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment