私はSpring 3.1とRESTEasyプロジェクト用にOAuth 2.0を実装したいと思います。このプロジェクトは、JSONベースのRESTサービスです。私は、Spring Security 3.1とspring-security-oauth2 version 1.0.0.RC2(最新のはずです)を使用しています。これまでのところ私は春のセキュリティ設定をデフォルト設定で行っています。 OAuth 2.0の基本設定(デフォルト)もあります。oauth2プロバイダーエンドポイントのハンドラーエラーのアダプターがありません
以前はRESTサービスを使用していましたが、完璧に動作します。春のセキュリティもうまくいくようです。 RESTサービスへのリンクを開くと、ログインページにリダイレクトされます。ログイン後、私は期待される結果を与えるREST呼び出しを行うことができます。
私はHetはOAuthのをテストするために、localhost:8080/tools-service/oauth/token
またはlocalhost:8080/tools-service/oauth/error
をURLを開くと、私は次のエラーが、私は/oauth/token
にアクセスするときに表示されるエラー500 を取得します。 /oauth/error
のエラーはsimularです。私が正しいだ場合
HTTP Status 500 - No adapter for handler [public org.springframework.http.ResponseEntity org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.getAccessToken(java.security.Principal,java.lang.String,java.util.Map)]: Does your handler implement a supported interface like Controller?
これはTokenEndpoint.getAccessToken
機能にエラーがあることを意味しますか?そのクラスはSpringフレームワークの一部であるため(実際には上手く見えるコードを参照しています)、問題は実際にそれらのクラスに関連しているとは思われません。それは私を無知にしてしまいます。
今、私はこれがなぜ起こり、どのようにこれを解決できるかを知りたいと思います。 私はおそらく、私はおそらく、ブラウザのURLを訪問することは許されていないと考えました。しかし、私はSparklr2(the Spring OAuth 2.0 sample application)で同じものを試してみると、XMLメッセージ(/ oauth2/token用)とエラー・ページ(/ 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>
私のアプリケーションコンテキストは、私が作成した次のセキュリティ-config.xmlファイルをロードします。
<?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>
CollectorClientDetails実装が唯一のダミーですコード:
@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;
}
}
私はこのような自分の疑問に答えることができてうれしいです。これは、あなたの問題がどれほど曖昧であっても、常に同じことを経験している他のユーザーが少なくとも1人いる場合の良い例です。 – Joe
Vertongen、私は同じ問題を抱えていましたが、すべての関連するGoogleの結果が読み込まれていましたが、自分の問題のみが解決されました。 が私のコードから抜けていました。あなた自身の質問に答えると私を助けてくれてありがとう! –
szpetip
ようこそ。私はこれがすべての時間の後にまだ有用であることを嬉しく思う。 – Vertongen