Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

AEM 6.5.10 - Assets Metadata Based Custom Restriction Provider | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

AEM 6.5.10 - Assets Metadata Based Custom Restriction Provider by Sreekanth Choudry Nalabotu

Abstract

Goal
In Assets, for dam-users group do NOT show jpg assets with metadata assetCategory is RESTRICTED, always show when assetCategory is ALLOWED and when assetCategory is missing/empty you may or may not want to show such assets( depending on admin having good day or bad day...) here is some authorization documentation

Solution
1) Add the assetCategory restriction apps.experienceaem.assets.core.acls.EAEMAssetCategoryRestriction

package apps.experienceaem.assets.core.acls;

import com.adobe.xfa.ut.StringUtils;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EAEMAssetCategoryRestriction implements RestrictionPattern {
private static final Logger log = LoggerFactory.getLogger(EAEMAssetCategoryRestriction.class);

private final String restrictedValue;
public static final String ASSET_CATEGORY = "assetCategory";

EAEMAssetCategoryRestriction(String restrictedValue) {
this.restrictedValue = restrictedValue;
}

public boolean matches(Tree tree, PropertyState propertyState) {
PropertyState property = tree.getChild(JcrConstants.JCR_CONTENT).getChild("metadata").getProperty(ASSET_CATEGORY);

if(property == null){
if(restrictedValue.equals("EMPTY")){
return true;
}
return false;
}

String value = property.getValue(Type.STRING);

if(restrictedValue.equals("EMPTY") && StringUtils.isEmpty(value)){
return true;
}

return restrictedValue.equalsIgnoreCase(value);
}

public boolean matches(String path) {
return false;
}

public boolean matches() {
return false;
}
}

Read Full Blog

AEM 6.5.10 - Assets Metadata Based Custom Restriction Provider

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
0 Replies