Backoffice User Access Control

在Backoffice中,配置不同用户对于不同的Item的操作权限都在文件xxx-access-rights.impex中配置,例子如下:

$START_USERRIGHTS;;;;;;;;;
Type;UID;MemberOfGroups;Password;Target;read;change;create;remove;change_perm
UserGroup;productmanagergroup;cockpitgroup;;;;;;;

# Access Rights for Products & Catalog;;;;;;;;;
;;;;ItemSyncTimestamp;+;;;
;;;;SyncItemJob;+;;;
;;;;Type;+;;;
;;;;Product;+;+;+;+;+;
;;;;Category;+;+;+;+;+;
;;;;variantType;+;+;+;+;+;
;;;;Catalog;+;;;
;;;;CatalogVersion;+;+;+;+;+;
;;;;ClassificationAttributeUnit;+;;;
;;;;Media;+;+;+;+;+;
;;;;MediaContainer;+;+;+;+;+;
;;;;MediaFormat;+;+;+;+;+;
;;;;MediaFolder;+;+;+;+;+;
;;;;Vendor;+;+;+;+;+;
;;;;StockLevel;+;+;+;+;+;
;;;;Tax;+;+;+;+;+;
;;;;TaxRow;+;+;+;+;+;
;;;;PriceRow;+;+;+;+;+;
;;;;ProductFeature;+;+;+;+;+;
;;;;ProductReference;+;+;+;+;+;
;;;;Warehouse;+;+;+;+;+;
;;;;ProductTaxCode;+;+;+;+;+;
;;;;ProductOrderLimit;+;+;+;+;+;


$END_USERRIGHTS;;;;;

这里的Impex主要更新ACL Entries( (Table «aclentries»)),该表主要作用是处理用户权限相关:Access Control Lists (Permission-User-Item)

但是在处理Product的时候会发现,即使在这里配置了权限,在EditorArea中也不能编辑产品,查看源码发现,Editor是否可以编辑由EditorContext中的属性isEditable决定,所以找到isEditable的设置逻辑就可以找到此问题的根源。

具体逻辑在DefaultPlatformPermissionFacadeStrategy中实现,具体方法为canReadInstance

public boolean canReadInstance(Object instance) {
    String type = this.typeFacade.getType(instance);
    return this.canReadType(type) && this.canReadCatalogVersionAwareInstance(instance);
}

其中前一部分为上文中提到的权限配置表ACL Entries中配置,后一部分判断该Item是否具有CatalogVersion,如果有,则需要在Principal2ReadableCatalogVersionRelation中配置,例子如下:

UPDATE CatalogVersion;catalog(id)[unique=true];version[unique=true];writePrincipals(uid);
;electronicsProductCatalog;Online;productmanagergroup,productmanager;
;electronicsProductCatalog;Staged;productmanagergroup,productmanager;

这样,ProductManagerGroup和ProductManager都可以编辑产品了。

当然如果有更复杂的需求,我们还可以通过覆盖和扩展DefaultPlatformPermissionFacadeStrategy来实现,Hybris框架提供了足够灵活的扩展空间来应对权限相关的需求。

参考资料:
https://hybrismart.com/2018/05/06/explaining-hybris-database-structure

你可能感兴趣的:(Backoffice User Access Control)