抢占先机
VMware 提供培训和认证,以加速您的进步。
了解更多Spring Security OAuth 2.0.0.RC1 现在可以从 Spring Repo 获取。 这对于 Spring 上的 OAuth 服务器和客户端应用程序的现代化和易用性来说是向前迈出的一大步。
最主要的功能是支持 @Configuration
(仅适用于 OAuth2),如果您使用 Spring Boot 编写您的应用程序,您可以用大约 25 行代码来提供令牌并保护 API 资源。
@Configuration
@EnableAutoConfiguration
@EnableResourceServer
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@RequestMapping("/")
public String home() {
return "Hello World";
}
@Configuration
@EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("my-trusted-client")
.authorizedGrantTypes("password", "authorization_code", "refresh_token")
.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
.scopes("read", "write", "trust")
.resourceIds("oauth2-resource")
.secret("secret");
}
}
}
我们现在开箱即用地支持 JSON Web Token (JWT) 令牌,并且还有一个显式的 Approvals 域,用于管理和持久化用户批准。 这些功能在很大程度上借鉴了 CloudFoundry UAA 的工作。
Authorization Server API 已经进行了大量重构,以便可以轻松添加新的用例:例如,OpenID Connect (OIDC)、MAC 令牌或新的令牌撤销标准都很容易添加。 我知道至少有一个 OIDC 实现已经在使用 Spring OAuth2 2.0。
非常感谢很多人在这项工作中提供的帮助,但我们自己的 Rob Winch 值得大声称赞,因为他启动了 @Configuration
工作。 在 2.0 的开发过程中,我们将包括问题跟踪在内的所有内容都移到了 github,我认为结果是更多的社区参与,所以这次的许多贡献者都直接来自使用该软件的人,这很棒。 感谢所有提供帮助的人!