Я пытаюсь настроить клиент Spring OAuth2, который проходит проверку подлинности на моем собственном провайдере и сервере ресурсов. Поставщик и сервер ресурсов - это одно приложение в моем случае.Ошибка клиента OAuth2 Spring: не установлен URI перенаправления
У меня возникли проблемы с настройкой клиента OAuth с пружиной 3.2. Когда я называю OAuth2RestTemplate в контроллере (путем получения веб-страницы), я получаю эту ошибку:
java.lang.IllegalStateException: No redirect URI has been established for the current request. at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.getRedirectForAuthorization(AuthorizationCodeAccessTokenProvider.java:283) at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.obtainAccessToken(AuthorizationCodeAccessTokenProvider.java:159) at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainNewAccessTokenInternal(AccessTokenProviderChain.java:142) at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainAccessToken(AccessTokenProviderChain.java:118) at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:216) ...
Как я понимаю редирект автоматически устанавливается из текущего запроса URI. Во всяком случае, я попытался установить oauth: resource атрибут pre-installed-redirect-uri = "http: // localhost: 8080/myresourcesercer /". Затем я получаю эту ошибку:
org.springframework.security.oauth2.client.resource.UserRedirectRequiredException: A redirect is required to get the users approval ...
Как правильно настроить перенаправление uri или что мне не хватает?
Спасибо!
Вот мой конфиг:
web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
весна-security.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<oauth:client id="my-client" />
<oauth:resource id="security" type="authorization_code" client-id="my-client" client-secret="secret" access-token-uri="http://localhost:8080/provider/oauth/token"
scope="read,write" user-authorization-uri="http://localhost:8080/provider/oauth/authorize" authentication-scheme="query"/>
<bean id="fooService" class="com.mypackage.serviceImpl.FooServiceImpl">
<property name="secureRestTemplate">
<oauth:rest-template resource="security" />
</property>
</bean>
</beans>
MVC-диспетчерская-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<mvc:default-servlet-handler />
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
...
</mvc:message-converters>
</mvc:annotation-driven>
<context:component-scan base-package="com.mypackage.controller" />
<context:component-scan base-package="com.mypackage.serviceImpl" />
<mvc:resources mapping="/css/**" location="/css/"/>
<bean id="viewResolver"
class=" org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
…
</beans>
Вы когда-нибудь это выясняли? Я столкнулся с той же проблемой – acvcu
Я понял, что второе сообщение об ошибке вводит в заблуждение. Не уверен, что актуальная проблема была, но вы не могли догадаться об этом из сообщения об ошибке.Моя текущая (и работает) конфигурация клиента выглядит следующим образом: ' \t \t \t OAuth: клиент-деталь-сервис> 'ли это помочь тебе? –
Mirko
Какой тип гранта вы используете? Получаете ли вы запрос типа «Хотели бы вы предоставить доступ ...»? У меня такая же проблема, и решения все еще нет. К сожалению, мой поставщик OAuth разрешает только разрешение authorization_code. –