Spring Security OAuth2简单配置

Spring Security OAuth2简单配置,第1张

Spring Security OAuth2简单配置

不要让sparklr样本使您感到困惑(它所做的远远超出您的预期)。就是这个简单的够吗?

@ComponentScan@EnableAutoConfigurationpublic class Application {public static void main(String[] args) {    SpringApplication.run(Application.class, args);}@Configuration@Order(Ordered.LOWEST_PRECEDENCE - 100)protected static class OAuth2Config extends OAuth2AuthorizationServerConfigurerAdapter {    @Override    protected void configure(AuthenticationManagerBuilder auth) throws Exception {        // @formatter:off        auth.apply(new InMemoryClientDetailsServiceConfigurer()) .withClient("my-trusted-client")     .authorizedGrantTypes("password", "authorization_pre", "refresh_token", "implicit")     .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")     .scopes("read", "write", "trust")     .accessTokenValiditySeconds(60)        .and() .withClient("my-client-with-secret")     .authorizedGrantTypes("client_credentials")     .authorities("ROLE_CLIENT")     .scopes("read")     .secret("secret");    // @formatter:on    }}}

那就是认证服务器。客户端也很容易(例如Spring OAuth项目中的客户端)。PS这是Spring
OAuth 2.0的全部内容(尚未发布),但是我们正在努力(而XML配置的1.0功能确实没有那么重)。

注意:这种方式击败了OAuth2的对象(Webapp客户端
应该收集用户凭据)。您应该考虑使用

grant_type=authorization_pre



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5676036.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存