Hi Team,
I have requirement to restrict from creation of exe file.
User is creating plain text file from share UI and entering name like test.exe.
I have created rule that checks if file name ends with exe, it throws exception. But rule is not executing somehow.
Then i have created behaviour that executes on node creation, I am getting parentref using below code.
public void init() { policyComponent.bindClassBehaviour(NodeServicePolicies.BeforeCreateNodePolicy.QNAME, ContentModel.TYPE_CONTENT, new JavaBehaviour(this, "beforeCreateNode", Behaviour.NotificationFrequency.EVERY_EVENT)); } @Override public void beforeCreateNode(NodeRef parentRef, QName assocTypeQName, QName assocQName, QName nodeTypeQName) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Started executing FileCreationRestrictionBehaviour .."); LOGGER.debug("parentref --> "+parentRef); LOGGER.debug("parentref NAME --> "+nodeService.getProperty(parentRef, ContentModel.PROP_NAME)); System.out.println("parentref --> "+parentRef + "parentref NAME --> "+nodeService.getProperty(parentRef, ContentModel.PROP_NAME)); } }
So,my requirement is to restrict file creation, if users enters .exe in file name, how can i get the noderef/filename of that file, so, i can throw exception.
Thanks,
Hardik
Solved! Go to Solution.
Try : org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy
You can do something like this:
public void onCreateNode(final ChildAssociationRef childAssocRef) { final NodeRef nodeRef = childAssocRef.getChildRef();//node which is being created. if (nodeService.exists(nodeRef)) { final String fileName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); final String mimetype = mimetypeService.guessMimetype(fileName); //find mimetype by extension of the file. if (restrictedMimeList.contains(mimetype)) {// check whether the result is one of the restricted mime types from the list? throw new AlfrescoRuntimeException("Mimetype " + mimetype + " is unsupported"); } } }
Try : org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy
You can do something like this:
public void onCreateNode(final ChildAssociationRef childAssocRef) { final NodeRef nodeRef = childAssocRef.getChildRef();//node which is being created. if (nodeService.exists(nodeRef)) { final String fileName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); final String mimetype = mimetypeService.guessMimetype(fileName); //find mimetype by extension of the file. if (restrictedMimeList.contains(mimetype)) {// check whether the result is one of the restricted mime types from the list? throw new AlfrescoRuntimeException("Mimetype " + mimetype + " is unsupported"); } } }
@hardik_thakkar you can also try this add-on which covers several other scenarios while blocking blacklisted mimetypes.
https://github.com/abhinavmishra14/alfresco-mimetype-blocker/releases
originally forked from https://github.com/keensoft/alfresco-mimetype-blocker
I have configured that add-on and that works perfectly during file upload part.
Written behaviour for file creation part as per your suggestion and that's working fine.
Thanks,
Hardik
Good to hear that everything works fine for you. Good luck @hardik_thakkar
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.