2017-03-07 32 views
-1

我有一个关于使用spring security的问题。我有一个node.js http-server(localhost:8000)和一个spring启动项目(localhost:8090)。并且我在spring中使用spring安全启动project.Here是我的配置什么是弹簧安全的表单地址

@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服务器的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,并输入自己的用户名和密码,我alreadly曾在蒙戈,我得到了

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"; 
    } 
} 

,当我visied的login.html,提交,我得到了字符串“登录”。

我不知道为什么,以及所有关于spring security的消息都使用jsp或thylef。所以也许我缺乏有关春季安全的事情。

有谁知道我可以做到吗?多谢。

+0

不,我把所有的页面放到node.js http-server,我不知道如何去描述,它是一个所谓的前端和后端。 – Dade

回答

-1

干草我刚刚从http://stackoverflow.com/questions/21696592/disable-spring-security-for-options-http-method得到了Luc S的回答,所以我只是忽略了http选项并且让它成功。 希望这会帮助你。