Use restrictions in SAP Hybris
1. Overview
A restriction in Hybris is a set of rules applied to flexible searches in order to limit the search results based on certain specific conditions.
This is a simplified version of how restrictions work in Hybris.
By default, restrictions are not applied on admingroup members, admin will always get the full results.
This article will guide through how to create and use restrictions in Hybris.
2. Restrictions in action
2.1. Create restriction
First of all, you will need to create an instance of the SearchRestrictionModel
using impex or HMC/Backoffice as shown below.
INSERT_UPDATE SearchRestriction ;code[unique=true] ;name[lang=en] ;principal(UID) ;restrictedType(code) ;active ;generate ;query
;customerWithoutAnonymous ;Customer Anonymous Restriction ;employeegroup ;Customer ;true ;true ;{uid} NOT LIKE 'anonymous'
- code: Unique id code of the restriction.
- name: Name of the restriction.
- principal: User/user group to whom the restriction will be applied.
- restrictedType: Item type to which the restriction will be applied on.
- active: true means the restriction is enabled, false is disabled.
- query: conditions to be added to the WHERE clause of the flexible search.
2.2. Use restriction
When you run a flexible search query on CustomerModel
as a User who belongs to the employeegroup.
SELECT {pk}, {uid} FROM {Customer}
The restriction query will systematically be added to the flexible search.
SELECT {pk}, {uid} FROM {Customer} WHERE {uid} NOT LIKE 'anonymous'
2.3. Test restriction on hac (hybris administration console)
Navigate to hac -> Console -> FlexibleSearch, add your flexibleSearch, employee account uid and run.
Software Craftsmanship, Stackextend author and Full Stack developer with 6+ years of experience in Java/Kotlin, Java EE, Angular and Hybris…
I’m Passionate about Microservice architectures, Hexagonal architecture, Event Driven architecture, Event Sourcing and Domain Driven design (DDD)…
Huge fan of Clean Code school, SOLID, GRASP principles, Design Patterns, TDD and BDD.
Please tell me whether Hybris applies restrictions for types used in subqueries. Thanks
Good work Could you please create one post on how to use referenceSearchCondition in tag in *backoffice-config.xml The requirement is I want to filter the products in search dropdown in wizet based on user level brands for extracting selected products in excel file. I have written code for getting list of brands brands in backend list of as List and returned from custom service but need to know how to map service returned List with ProductModel in which having one attribute as set getBrands() and in BrandModel having one attribute brandCode as String where I want to do exact match,… Read more »