feat: 启用LDAP认证后才显示LDAP登录选项
This commit is contained in:
parent
ff9965b2e7
commit
5bf3f355f5
|
@ -48,6 +48,7 @@ public class ShiroConfig implements EnvironmentAware {
|
|||
filterChainDefinitionMap.put("/", "anon");
|
||||
filterChainDefinitionMap.put("/signin", "anon");
|
||||
filterChainDefinitionMap.put("/ldap/signin", "anon");
|
||||
filterChainDefinitionMap.put("/ldap/open", "anon");
|
||||
filterChainDefinitionMap.put("/isLogin", "anon");
|
||||
filterChainDefinitionMap.put("/css/**", "anon");
|
||||
filterChainDefinitionMap.put("/js/**", "anon");
|
||||
|
|
|
@ -13,10 +13,7 @@ import io.metersphere.service.UserService;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
@ -82,4 +79,9 @@ public class LdapController {
|
|||
ldapService.authenticate(request);
|
||||
}
|
||||
|
||||
@GetMapping("/open")
|
||||
public boolean isOpen() {
|
||||
return ldapService.isOpen();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -92,9 +92,7 @@ public class LdapService {
|
|||
if (result.size() == 1) {
|
||||
return result.get(0);
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
MSException.throwException(Translator.get("login_fail_ou_error"));
|
||||
} catch (InvalidNameException e) {
|
||||
} catch (NameNotFoundException | InvalidNameException e) {
|
||||
MSException.throwException(Translator.get("login_fail_ou_error"));
|
||||
} catch (InvalidSearchFilterException e) {
|
||||
MSException.throwException(Translator.get("login_fail_filter_error"));
|
||||
|
@ -125,9 +123,7 @@ public class LdapService {
|
|||
MSException.throwException(Translator.get("ldap_ou_is_null"));
|
||||
}
|
||||
|
||||
String[] arr = ou.split("\\|");
|
||||
|
||||
return arr;
|
||||
return ou.split("\\|");
|
||||
}
|
||||
|
||||
private static class MsContextMapper extends AbstractContextMapper<DirContextOperations> {
|
||||
|
@ -217,4 +213,11 @@ public class LdapService {
|
|||
return result;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
String open = service.getValue(ParamConstants.LDAP.OPEN.getValue());
|
||||
if (StringUtils.isBlank(open)) {
|
||||
return false;
|
||||
}
|
||||
return StringUtils.equals(Boolean.TRUE.toString(), open);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<div class="form">
|
||||
<el-form-item v-slot:default>
|
||||
<el-radio-group v-model="form.authenticate">
|
||||
<el-radio label="LDAP" size="mini">LDAP</el-radio>
|
||||
<el-radio label="LDAP" size="mini" v-if="openLdap">LDAP</el-radio>
|
||||
<el-radio label="LOCAL" size="mini">普通登录</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
@ -81,7 +81,8 @@
|
|||
]
|
||||
},
|
||||
msg: '',
|
||||
ready: false
|
||||
ready: false,
|
||||
openLdap: false
|
||||
}
|
||||
},
|
||||
beforeCreate() {
|
||||
|
@ -92,6 +93,9 @@
|
|||
window.location.href = "/"
|
||||
}
|
||||
});
|
||||
this.$get("/ldap/open", response => {
|
||||
this.openLdap = response.data;
|
||||
})
|
||||
},
|
||||
created: function () {
|
||||
// 主页添加键盘事件,注意,不能直接在焦点事件上添加回车
|
||||
|
@ -145,7 +149,7 @@
|
|||
if (!language) {
|
||||
this.$get("language", response => {
|
||||
language = response.data;
|
||||
localStorage.setItem(DEFAULT_LANGUAGE, language)
|
||||
localStorage.setItem(DEFAULT_LANGUAGE, language);
|
||||
window.location.href = "/"
|
||||
})
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue