0
我已經在Java中使用Spring安全Oauth2創建了一個RESTEasy服務,用於身份驗證和令牌生成。每一件事情都適合我,但是當我嘗試訪問我的服務以從瀏覽器REST客戶端生成令牌時,它會要求憑證,但它同時失敗,但同時如果我通過Java中的HTTPClient訪問同一服務,它對我有用,瀏覽器REST客戶端請求憑證,並且RESTEasy服務失敗
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://localhost:80/my-rest-application/oauth/token");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("client_id","myclientid"));
nameValuePairs.add(new BasicNameValuePair("client_secret","myclientsecret"));
nameValuePairs.add(new BasicNameValuePair("username","someuser"));
nameValuePairs.add(new BasicNameValuePair("password","somepassword"));
nameValuePairs.add(new BasicNameValuePair("grant_type","password"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
HTTP客戶端在我,但在其他瀏覽器的Java客戶端的工作要求它爲憑據,並返回錯誤的請求
任何想法,爲什麼會發生?
我的配置,
<http pattern="/oauth/token" create-session="stateless"
authentication-manager-ref="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security" >
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<!-- include this only if you need to authenticate clients via request parameters -->
<custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<authentication-manager id="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<bean id="clientDetails" class="my own client details implementation"/>
<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<!-- <property name="realmName" value="springsec/client" /> -->
<property name="realmName" value="test/client" />
<property name="typeName" value="Basic" />
</bean>
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="clientAuthenticationManager" />
</bean>
<authentication-manager id="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
日誌?你的迴應的內容長度是1061字節。它包含什麼?當使用您的休息客戶端時,您的*請求的內容類型是什麼? –
我的內容類型是application/json –
這聽起來不對,它應該是'application/x-www-form-urlencoded' –