什么是带有弹簧安全性的表单地址



我有一个有关使用Spring Security的问题。我有一个Node.js HTTP-Server(LocalHost:8000)和一个Spring Boot项目(LocalHost:8090)。我使用Spring Security。在Spring Boot Project。我的配置

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
HunterUserRepository repository;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
    auth.userDetailsService(new HunterUserSecurityServices(repository));
}
@Override
protected void configure(HttpSecurity http) throws Exception{
    http
            .authorizeRequests().anyRequest().permitAll()
            .and()
            .authorizeRequests()
            .antMatchers("/api/private/**").authenticated()
            .and().formLogin().loginPage("/login").permitAll();
    http.csrf().disable();
 }
}

这是我在http-server中的login.html:

<form class="form-signin" action="http://localhost:8090/login" method="POST">  
    <h2>请登录<div class="pull-right"><small><a href="#">注册</a></small></div></h2>
    <label for="username" class="sr-only">用户名</label>  
    <input name="username" type="text" id="username" class="form-control" placeholder="用户名" required autofocus style="margin-bottom: 10px">
    <label for="inputPassword" class="sr-only">密码</label>  
    <input name="password" type="password" id="inputPassword" class="form-control" placeholder="密码" required style="margin-bottom: 10px">  
    <button class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="Login">登录</button>  
  </form>

当我访问http://localhost:8000/login.html并输入我在Mongo中使用的用户名和密码时,我得到了

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Mar 07 20:30:15 CST 2017
There was an unexpected error (type=Not Found, status=404). 
No message available

我想这可能是春季安全的问题,因为当我在春季启动中添加控制器时:

@RestController
//@CrossOrigin 
public class LoginController {
    @RequestMapping("/login")
    String login(){
        return "login";
    }
}

,当我访问login.html时,提交,我得到了字符串"登录"。

我不知道为什么,我能找到的有关弹簧安全性的所有消息都使用JSP或Thylef。因此,也许我缺乏有关春季安全的一些事情。

有人知道我怎么能做到吗?很多。

hay我刚刚通过 Luc Shttp://stackoverflow.com/questions/21696592/disable-spring-security-for-options-http-method得到答案,所以我只是忽略了http选项,然后做到了。希望这对您有帮助。

最新更新