Example with Webdam REST API

Overview

This page provides an example ResourceResolver bean configuration for integrating with the Webdam REST API backend. The example demonstrates how to configure connection details, the RestTemplate object, OAuth2 authentication, the ResourceLinkResolver, and cache control.

You can apply this ResourceResolver configuration as a Spring bean definition at the following repository location for a resource space named demoWebdam:

/hippo:configuration/hippo:modules/crispregistry/hippo:moduleconfig/crisp:resourceresolvercontainer/demoWebdam/@crisp:beandefinition

ResourceResolver Configuration

brXM 16

The following example shows a bean configuration for brXM 16:

<?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:s="http://www.springframework.org/schema/security" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <bean parent="abstractCrispSimpleJacksonRestTemplateResourceResolver" class="org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver"> <property name="cacheEnabled" value="${cache.enabled}" /> <property name="baseUri" value="${webdam.baseUrl}" /> <property name="resourceDataCache"> <bean class="org.onehippo.cms7.crisp.core.resource.SpringResourceDataCache"> <constructor-arg> <bean class="org.springframework.cache.caffeine.CaffeineCache" factory-bean="caffeineCacheInstanceFactory" factory-method="createSpringCacheInstance"> <constructor-arg value="demomarketoCache" /> <constructor-arg value="initialCapacity=10,maximumSize=1000,expireAfterWrite=100s,expireAfterAccess=100s" /> </bean> </constructor-arg> </bean> </property> <property name="clientHttpRequestInterceptor"> <list value-type="org.springframework.http.client.ClientHttpRequestInterceptor"> <bean class="org.onehippo.cms7.crisp.core.interceptor.SimpleOAuth2AuthorizedClientInterceptor" autowire="constructor"> <property name="authorizedClientService" ref="authorizedClientService" /> <property name="clientRegistrationId" value="webdam-login" /> <property name="contextAttributesMap" ref="credentials" /> </bean> </list> </property> </bean> <util:map id="credentials" map-class="java.util.HashMap"> <entry key="org.springframework.security.oauth2.client.OAuth2AuthorizationContext.USERNAME"> <value>${webdam.username}</value> </entry> <entry key="org.springframework.security.oauth2.client.OAuth2AuthorizationContext.PASSWORD"> <value>${webdam.password}</value> </entry> </util:map> <s:client-registrations> <s:client-registration registration-id="webdam-login" client-id="${webdam.clientId}" client-secret="${webdam.clientSecret}" client-authentication-method="post" authorization-grant-type="password" provider-id="webdam"/> <s:provider provider-id="webdam" authorization-uri="${webdam.baseUrl}/oauth2/token" token-uri="${webdam.baseUrl}/oauth2/token"/> </s:client-registrations> <bean id="authorizedClientService" class="org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService" autowire="constructor"/> <bean id="authorizedClientRepository" class="org.springframework.security.oauth2.client.web.AuthenticatedPrincipalOAuth2AuthorizedClientRepository"> <constructor-arg ref="authorizedClientService"/> </bean> </beans>

brXM 14 & 15

Use the following configuration for brXM 14 and 15:

<?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:s="http://www.springframework.org/schema/security" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <bean parent="abstractCrispSimpleJacksonRestTemplateResourceResolver" class="org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver"> <property name="cacheEnabled" value="${cache.enabled}" /> <property name="baseUri" value="${webdam.baseUrl}" /> <property name="resourceDataCache"> <bean class="org.onehippo.cms7.crisp.core.resource.SpringResourceDataCache"> <constructor-arg> <bean class="org.springframework.cache.ehcache.EhCacheCache"> <constructor-arg> <bean parent="abstractCrispResourceEhCache"> <property name="cacheName" value="webdamCache" /> <property name="maxEntriesLocalHeap" value="1000" /> <property name="maxEntriesLocalDisk" value="0" /> <property name="timeToLiveSeconds" value="60" /> <property name="timeToIdleSeconds" value="60" /> </bean> </constructor-arg> </bean> </constructor-arg> </bean> </property> <property name="clientHttpRequestInterceptor"> <list value-type="org.springframework.http.client.ClientHttpRequestInterceptor"> <bean class="org.onehippo.cms7.crisp.core.interceptor.SimpleOAuth2AuthorizedClientInterceptor" autowire="constructor"> <property name="authorizedClientService" ref="authorizedClientService" /> <property name="clientRegistrationId" value="webdam-login" /> <property name="contextAttributesMap" ref="credentials" /> </bean> </list> </property> </bean> <util:map id="credentials" map-class="java.util.HashMap"> <entry key="org.springframework.security.oauth2.client.OAuth2AuthorizationContext.USERNAME"> <value>${webdam.username}</value> </entry> <entry key="org.springframework.security.oauth2.client.OAuth2AuthorizationContext.PASSWORD"> <value>${webdam.password}</value> </entry> </util:map> <s:client-registrations> <s:client-registration registration-id="webdam-login" client-id="${webdam.clientId}" client-secret="${webdam.clientSecret}" client-authentication-method="post" authorization-grant-type="password" provider-id="webdam"/> <s:provider provider-id="webdam" authorization-uri="${webdam.baseUrl}/oauth2/token" token-uri="${webdam.baseUrl}/oauth2/token"/> </s:client-registrations> <bean id="authorizedClientService" class="org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService" autowire="constructor"/> <bean id="authorizedClientRepository" class="org.springframework.security.oauth2.client.web.AuthenticatedPrincipalOAuth2AuthorizedClientRepository"> <constructor-arg ref="authorizedClientService"/> </bean> </beans>

Property Reference

The bean configuration uses the following properties, which you must define as crisp:propnames and crisp:propvalues pairs on the /hippo:configuration/hippo:modules/crispregistry/hippo:moduleconfig/crisp:resourceresolvercontainer/demoWebdam node for the demoWebdam resource space.

Property NameExample Value
cache.enabledtrue
webdam.clientIdsomeClientId
webdam.clientSecretsomeClientSecret
webdam.baseUrlhttps://apiv2.webdamdb.com
webdam.usernamesomeUsername
webdam.passwordsomePassword

Configuration Details

  • The cacheEnabled property enables or disables caching at the ResourceResolver level.
  • The baseUri property sets the base URI for the Webdam REST API. When you use the ResourceServiceBroker for this resource space, it combines the relative resource path with the base URI to call the Webdam backend.
  • The resourceDataCache property assigns a ResourceDataCache instance specific to this ResourceResolver. If this property is set and the resource is cacheable, ResourceServiceBroker stores resource data in the specified cache. If not set, cacheable resources are stored in a global cache by default.
  • The clientHttpRequestInterceptor property configures a SimpleOAuth2AuthorizedClientInterceptor for OAuth2 authentication. The Webdam REST API requires OAuth2, so you must register an OAuth2 client in the OAuth2AuthorizedClientRepository with the required authentication details.

Note: The spring-security-oauth2 project is deprecated, and related libraries will be removed in future releases. For an alternative approach, see the Salesforce REST API example for guidance on implementing SimpleOAuth2AuthorizedClientInterceptor.

Share Feedback
Page: /build/crisp-api/configuration/example-with-webdam-rest-api
Section: Build
Category *
Example with Webdam REST API | Bloomreach Content Documentation