Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Issue while creating user with profile image

Avatar

Community Advisor

I am using AccountManager API to create users. It works just fine when I dont use profile image in registration form and user gets registered but when I use profile image, I get following error:

Caused by: javax.jcr.nodetype.ConstraintViolationException: No matching property definition: jcr:primaryType = sling:Folder
at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1308)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1297)
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:293)
at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1297)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:340)
at org.apache.sling.jcr.resource.JcrModifiablePropertyMap.save(JcrModifiablePropertyMap.java:180)
... 145 more
 
There is a hidden field to create this folder 
 <hidden
                jcr:primaryType="nt:unstructured"
                sling:resourceSuperType="foundation/components/form/defaults/field"
                sling:resourceType="foundation/components/form/hidden"
                defaultValue="sling:Folder"
                name="photos/jcr:primaryType"/>
 
Any inputs?
1 Accepted Solution

Avatar

Correct answer by
Level 10

The best practice to working with users in AEM is to use APIs located in the
org.apache.jackrabbit.api.security.user Java package. For example - to create a user use UserManager. 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

The best practice to working with users in AEM is to use APIs located in the
org.apache.jackrabbit.api.security.user Java package. For example - to create a user use UserManager. 

Avatar

Community Advisor

But AccountManager has utilities to manage everything automatically. By simply passing a map, it creates user with profile properties. In UserManager it just creates a user but account information still needs to be persisted manually.

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/security/AccountManager.html

It seems to be better than UserManger when it comes to persisting profile info along with registration.