Spring security oauth2提供程序终结点的处理程序没有适配器错误
我想为我的Spring3.1和项目实现OAuth2.0。该项目是一个基于JSON的REST服务。我使用Spring Security 3.1和Spring-Security-oauth2版本1.0.0.RC2(应该是最新的)。到目前为止,我已经有了带有默认设置的spring安全设置。我还为OAuth2.0提供了非常基本(默认)的配置 我以前用过REST服务,效果很好。Spring security似乎也能正常工作。如果我打开REST服务的链接,我将被重定向到登录页面。登录后,我可以进行REST调用,以获得预期的结果 当我打开het URLSpring security oauth2提供程序终结点的处理程序没有适配器错误,spring-security,oauth-2.0,resteasy,oauth-provider,Spring Security,Oauth 2.0,Resteasy,Oauth Provider,我想为我的Spring3.1和项目实现OAuth2.0。该项目是一个基于JSON的REST服务。我使用Spring Security 3.1和Spring-Security-oauth2版本1.0.0.RC2(应该是最新的)。到目前为止,我已经有了带有默认设置的spring安全设置。我还为OAuth2.0提供了非常基本(默认)的配置 我以前用过REST服务,效果很好。Spring security似乎也能正常工作。如果我打开REST服务的链接,我将被重定向到登录页面。登录后,我可以进行REST调
localhost:8080/tools service/oauth/token
或localhost:8080/tools service/oauth/error
来测试oauth时,我得到一个错误500。
当我访问/oauth/token
时显示以下错误。/oauth/error
的错误是相同的
HTTP状态500-处理程序没有适配器[public org.springframework.HTTP.ResponseEntity org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.getAccessToken(java.security.Principal,java.lang.String,java.util.Map)]:您的处理程序是否实现了类似控制器的受支持接口?
如果我是正确的,这意味着TokenEndpoint.getAccessToken
函数中有错误?由于该类是Spring框架的一部分(我查阅了代码,看起来不错),我认为问题实际上与这些类无关。这让我不知所措
现在我想知道为什么会发生这种情况,以及我如何解决这个问题。
我考虑了一个事实,也许我不被允许在浏览器中访问这些URL。但是,如果我对Sparklr2()进行同样的尝试,我会得到一条XML消息(for/oauth2/token)和一个错误页面(for/oauth2/error),这与预期的一样
任何帮助或提示都将不胜感激
web.xml中与安全相关的代码段:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在让这个问题冷静了几天后,我做了一个新的谷歌搜索。这让我想到了Spring源代码论坛: 在这里,我发现巴尼福也有同样的问题。Dave Syer回答了这样的问题: 看起来您已从中删除了
香草汽水。我想如果你把它放回处理器适配器里
将为您定义
SpringSecurity依赖于SpringMVC框架来处理请求和响应。因此,需要包括MVC框架并正确设置,以使SpringSecurityOAuth正常工作
解决方案是,我在应用程序上下文中添加了2个标记:
公共类TokenEndpoint
中使用的后一个,给出了错误500
,则会出现这种情况。(引用Spring文档。)
更多信息可在此处找到:
,
我很高兴还有其他人这样回答自己的问题。这是一个很好的例子,说明无论您的问题多么模糊,总有至少一个其他用户遇到相同的问题。如果我能给你买一杯啤酒,我会的,但至少有一个投票权:-)Vertongen,我也有同样的问题,所有相关的谷歌搜索结果都被读取了,但只有你解决了我的问题,我的代码中缺少了。谢谢你回答自己的问题并帮助我!欢迎光临。我很高兴经过这么长时间,这仍然有用。
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2.xsd">
<sec:http auto-config="true">
<sec:intercept-url pattern="/**" access="ROLE_USER" />
</sec:http>
<sec:authentication-manager>
<sec:authentication-provider>
<sec:user-service>
<sec:user name="user1" password="test123" authorities="ROLE_USER" />
<sec:user name="user2" password="hello123" authorities="ROLE_USER" />
</sec:user-service>
</sec:authentication-provider>
</sec:authentication-manager>
<sec:global-method-security pre-post-annotations="enabled" proxy-target-class="true">
<sec:expression-handler ref="oauthExpressionHandler" />
</sec:global-method-security>
<bean id="clientDetailsService" class="be.collectortools.rest.service.security.CollectorDetailsServiceImpl" />
<bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore" />
<bean id="tokenServices" class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
<property name="clientDetailsService" ref="clientDetailsService"/>
</bean>
<oauth:authorization-server
client-details-service-ref="clientDetailsService"
token-services-ref="tokenServices">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password />
</oauth:authorization-server>
<oauth:expression-handler id="oauthExpressionHandler" />
</beans>
@Service
public class CollectorDetailsServiceImpl implements ClientDetailsService {
@Resource
private CollectorClientDetailsRepository collectorClientDetailsRepository;
@Override
public ClientDetails loadClientByClientId(final String clientId) throws OAuth2Exception {
CollectorClientDetails dummyClient = new CollectorClientDetails();
dummyClient.setClientId(clientId);
return dummyClient;
}
}
<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:component-scan base-package="be.collectortools.rest"/>
<context:annotation-config/>
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<import resource="classpath:springmvc-resteasy.xml"/>
<import resource="mongo-config.xml"/>
<import resource="security-config.xml"/>
</beans>