[英]Spring Security LDAP Auth from Ionic
我使用 Java Spring 開發了一個后端,並通過擴展 WebSecurityConfigurerAdapter 添加了 LDAP 身份驗證。 我可以從 POSTMAN 獲得身份驗證,但不能從 Ionic 獲得身份驗證。
我的春天的一面;
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//TODO: add other endpoints like /events in order to permit un-authenticated users
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login**").anonymous()
.antMatchers("/resources/**").permitAll()
.antMatchers("/assets/**").permitAll()
.antMatchers("/").authenticated()
.antMatchers("/home").authenticated()
.antMatchers("/events/**").authenticated()
.and()
.formLogin()
.and()
.logout()
.permitAll()
.and()
.cors()
.and()
.csrf()
.disable();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.contextSource()
.url("ldap://ldap.forumsys.com/dc=example,dc=com")
.and()
.userSearchFilter("(uid={0})")
.userSearchBase("ou=mathematicians")
.userDnPatterns("uid={0}");
}
登錄控制器;
@RequestMapping(value = "/")
public String home() throws NamingException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String currentPrincipalName = authentication.getName();
return "hey, nice! = " + currentPrincipalName;
}
還有我的郵遞員登錄; 郵遞員截圖
最后,我的客戶端(離子)端身份驗證代碼;
authenticate(event) {
event.preventDefault();
const data = new URLSearchParams();
data.append("username",this.state.username);
data.append("password",this.state.password);
fetch(host + "/login", {
mode: 'no-cors',
method: 'POST',
body: data,
redirect :"follow",
headers: {
'Accept': '*/*'
},
keepalive: true
})
}
但是從我的 Ionic 方面來看,我無法從 POSTMAN 那里得到“嘿,不錯!= euler”的回應。 我認為我處理了 CORS,但我沒有弄清楚問題出在哪里。
我回答了我的問題。
我在 package.json 中添加了代理並添加了憑據:“include”以在前端發布請求標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.