0
私のapiの公開のいくつかのURLを作りたいと思います。しかし、ひとつのURLを設定すると、私のすべてのapiは許可なく公開されます。スプリングセキュリティOauth2すべてのURLが許可されています
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/books","/api/plainOffers","/api/offers","/api/public/*").permitAll();
}
ResourceServer構成:ResourceServerConfigurationクラスの私のconfigureメソッドの下
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/api/books").permitAll();
http.authorizeRequests().antMatchers("/api/plainOffers").permitAll();
http.authorizeRequests().antMatchers("/api/offers").permitAll();
http.authorizeRequests().antMatchers("/api/public/*").permitAll();
//http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
}
認証サーバ:私はあなたが必要なrestricionsを追加する必要がありますね
@CrossOrigin
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig
extends AuthorizationServerConfigurerAdapter{
@Autowired
@Qualifier("userDetailsService")
private UserDetailsService userDetailsService;
@Autowired
private AuthenticationManager authenticationManager;
@Value("${api.oauth.tokenTimeout:3600}")
private int expiration;
@Override
public void configure(AuthorizationServerEndpointsConfigurer configurer) throws Exception {
configurer.authenticationManager(authenticationManager);
configurer.userDetailsService(userDetailsService);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("api")
.secret("secret")
.accessTokenValiditySeconds(expiration)
.scopes("read", "write")
.authorizedGrantTypes("password", "refresh_token")
.resourceIds("oauth2-resource");
}
}
解決方法を試しましたが、すべてのエンドポイントが保護されました。 { "error": "unauthorized"、 "error_description": "このリソースにアクセスするには完全な認証が必要です" – Billy
'http.authorizeRequests()。antMatchers("/login ")。permitAll(); \t \t http.authorizeRequests()。antMatchers( "/ forgottenPassword")。permitAll(); http.authorizeRequests()。anyRequest()。認証済み()。()。httpBasic(); 'これは私のために働いています –
提案のためのモハメドありがとうございます。 Postmanからの – Billy