我想在我的rest API中整合Spring Security。我有問題,因爲我的移民阻礙了所有路線。Spring Security禁用默認登錄頁面
我的配置:
@Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers(HttpMethod.POST,"/api/getNews").hasRole("ADMIN");
}
}
當我想GET
上春回登錄表單
<html>
<head>
<title>Login Page</title>
</head>
<body onload='document.f.username.focus();'>
<h3>Login with Username and Password</h3>
<form name='f' action='/login' method='POST'>
<table>
<tr><td>User:</td><td><input type='text' name='username' value=''></td></tr>
<tr><td>Password:</td><td><input type='password' name='password'/></td></tr>
<tr><td colspan='2'><input name="submit" type="submit" value="Login"/></td></tr>
<input name="_csrf" type="hidden" value="5453a3c5-2573-4861-b777-d008b04863c3" />
</table>
</form>
</body>
</html>
但我有/
允許的規則。爲什麼我無法訪問我的API?
也許嘗試手動寫入獲取請求的權限'.antMatchers(HttpMethod.GET,「/」)。permitAll()' –
不適用於此。 – lukassz
而'.antMatchers(HttpMethod.GET,「/ *」)。permitAll()'? –