我想设置一个带有0-legged(因此没有请求或访问令牌)OAuth 1.0的spring boot应用程序.我一直在寻找一个例子,我一直在努力寻找如何使用新风格(没有xml)配置东西.
现在我只想得到一个简单的用例,其中只有1个路径(/ oauth)受OAuth保护(其他一切都只是大开),并且它使用自定义ConsumerDetailsService(请参阅下面的代码的简单版本).
这是我的WebSecurityConfigurerAdapter(我的Application.java旁边的SecurityConfiguration.java,我认为这是在spring启动应用程序中配置这种东西的正确方法).我很确定我错过了提供程序配置(如http://projects.spring.io/spring-security-oauth/docs/oauth1.html中提到的那样),但我的反复试验并没有产生结果.
@Configuration @EnableWebMvcSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { // 0-Legged OAuth on the /oauth and /lti paths only http.requestMatchers().antMatchers("/oauth"); // .and().... what? // ??? something must be missing here - provider? } }
我在maven pom.xml中也有这个:
org.springframework.boot spring-boot-starter-security org.springframework.security.oauth spring-security-oauth 2.0.2.RELEASE
我的自定义ConsumerDetailsService
@Component public class LTIConsumerDetailsService implements ConsumerDetailsService { @Override public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException { BaseConsumerDetails cd; // TODO really lookup the key and related consumer details, for sample here we just hardcoded if ("key".equals(consumerKey)) { cd = new BaseConsumerDetails(); cd.setConsumerKey(consumerKey); cd.setSignatureSecret(new SharedConsumerSecretImpl("secret")); cd.setConsumerName("Sample consumerName"); cd.setRequiredToObtainAuthenticatedToken(false); // no token required (0-legged) cd.setResourceDescription("Sample consumer details - AZ"); cd.setResourceName("Sample resourceName"); } else { throw new OAuthException("For this example, key must be 'key'"); } return cd; } }
任何有关如何使用此工作的建议或指向spring boot OAuth 1.0代码的建议都将不胜感激.请注意,我已经尝试查看单独的spring boot安全性和OAuth指南,但无法成功合并它们.