如何解决来自Ionic的Spring Security LDAP Auth
我使用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;
}
我的邮递员登录名; Postman Screenshot
最后,我的客户(离子)端身份验证代码;
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
})
}
但是从我的离子方面,我无法像从POSTMAN上得到“嘿,好!=欧拉”的响应。我认为我处理了CORS,但是我不知道是什么问题。
解决方法
我回答了我的问题。
我在我的package.json中添加了代理,并添加了凭据:“ include”以在前端发布请求标头。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。