我创建了一个授权服务,如下所示
@SpringBootApplication
@EnableAuthorizationServer
public class AuthorizationApplication {
...
}
有了这个application.properties
.
server.port=9000
security.oauth2.client.client-id=monederobingo
security.oauth2.client.client-secret=monederobingosecret
security.oauth2.client.authorized-grant-types=authorization_code,refresh_token,password,client_credentials
security.oauth2.client.scope=company,client
然后,在一个单独的 Spring Boot 项目中,我创建了一个资源服务器。
@SpringBootApplication
@EnableResourceServer
public class App {
...
}
有了这个application.properties
.
server.port=9090
spring.application.name=app
security.oauth2.resource.user-info-uri=http://localhost:9000/user
现在,如果我发送这样的请求,一切都会正常localhost:9090/api
使用授权服务检索到的适当令牌。
但是,我不想在发送请求时发送此令牌localhost:9090/login
.
为此,我在我的资源服务器 Spring Boot 应用程序中创建了此类。
@Configuration
public class SpringConfig extends WebSecurityConfigurerAdapter {
@Override protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/login")
.permitAll()
.antMatchers("/api/**")
.authenticated();
}
}
现在我不需要发送任何令牌来发送请求/login
.
但是,当我向以下地址发送请求时,现在收到以下消息/api
使用有效的令牌。
{
"timestamp": 1496027102659,
"status": 403,
"error": "Forbidden",
"message": "Access Denied",
"path": "/api/v1/points_configuration/314"
}
如何在 Spring Security OAuth2 中仅配置少数 URL 模式的安全性?