The workflow is the following :
RESThub uses Spring Security OAuth2 implementation on the server-side.
To use it, add this dependency in your pom.xml :
<dependency>
<groupId>org.resthub</groupId>
<artifactId>resthub-oauth2-spring-security</artifactId>
<version>1.1</version>
</dependency>
And here is a sample configuration to be added in your applicationContext.xml :
<security:authentication-manager>
<security:authentication-provider user-service-ref="myUserDetailsService" />
</security:authentication-manager>
<security:http entry-point-ref="oauth2ProcessingFilterEntryPoint" create-session="never">
<security:access-denied-handler ref="oauth2AccessDeniedHandler" />
<security:intercept-url pattern="api/**"/>
</security:http>
<bean id="oauth2AccessDeniedHandler" class="org.springframework.security.web.access.AccessDeniedHandlerImpl"/>
<bean id="tokenServices" class="org.springframework.security.oauth2.provider.token.InMemoryOAuth2ProviderTokenServices" />
<oauth2:provider client-details-service-ref="clientDetails" token-services-ref="tokenServices" >
<oauth2:verification-code disabled="true"/>
</oauth2:provider>
<oauth2:client-details-service id="clientDetails" >
<oauth2:client clientId="myClientID" authorizedGrantTypes="password" />
</oauth2:client-details-service>
You will also have to add these lines to your web.xml, below the contextConfigLocation context-param block :
<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>
<filter>
<filter-name>JpaFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
You can have a look to Booking or Identity manager sample applications to see how it works.
You will certainly have communications between protected resource services. If you choose to use tokens between your protected service, as described in the (TODO) server-to-server profile, we offer you some utilities to do that.
In your “client” resource server:
This class stores in memory tokens you may need to access as many protected resource as you want. You have to configure it:
WARNING - For this first release, client id/secret ARE end-user credential, so you need a “Technical user” in your authorization service that will represent your java clients
You can use in many ways this utility class:
Some example? Spring bean definition
<bean name="tokenRepository" class="org.resthub.oauth2.client.TokenRepository">
<property name="clientId" value="foo"/>
<property name="clientSecret" value="bar"/>
<property name="authorizationEndPoints">
<list>
<value>http://XXX.XXX.XXX.XXX:YYY/oauth/authorize</value>
</list>
</property>
</bean>
Java code:
@Inject
protected TokenRepository tokenRepository;
// Enrich and trigger a request.
String resourceName = "/myResource";
HttpClient httpClient = ClientFactory.create();
XXX result = tokenRepository.enrich(httpClient.path(resourceName)).get(XXX.class);