<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic User not getting saved in MongoDb using UserManager service in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/user-not-getting-saved-in-mongodb-using-usermanager-service/m-p/323979#M10980</link>
    <description>&lt;P&gt;I have made a custom login plugin, where for the time being I am testing user creation in the handleRetrieveIdentity() method of the Authenticator.&lt;/P&gt;
&lt;P&gt;I am currently doing the following to save a user.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;UserManager userManager = Framework.getService(UserManager.class);
NuxeoPrincipal principal = userManager.getPrincipal(user.getEmail());
if (principal == null) {
    logger.debug("principal was null. creating a new user for email id {}",user.getEmail());
    DocumentModel userDocModel = userManager.getBareUserModel();
    userDocModel.setProperty("user", "username", user.getEmail());
    userDocModel.setProperty("user", "email", user.getEmail());
    userDocModel.setProperty("user", "password", "fakepassword" + new Random().nextInt());
    //userDocModel.setProperty("user", "groups", groups);
    userManager.createUser(userDocModel);
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But this is not saving the user in the mongo collection userDirectory where the other predefined users reside. What could I be doing wrong here?&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;I debugged the code and saw that the error was at &lt;CODE&gt;createUser(userDocModel)&lt;/CODE&gt; call. To create a user the &lt;CODE&gt;MongoDbSession&lt;/CODE&gt;'s inherited method &lt;CODE&gt;createEntry()&lt;/CODE&gt; checks for permission with the call &lt;CODE&gt;checkPermission(SecurityConstants.WRITE);&lt;/CODE&gt;, which goes to this piece of code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;public void checkPermission(String permission) {    
	if (hasPermission(permission)) {       
		 return;    
	}    
	if (permission.equals(SecurityConstants.WRITE) &amp;amp;&amp;amp; isReadOnly()) { 
	       throw new DirectorySecurityException("Directory is read-only");    
	} else {        
		NuxeoPrincipal user = ClientLoginModule.getCurrentPrincipal();    
	        throw new DirectorySecurityException("User " + user + " does not    have " + permission + " permission");    
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In my case, the control goes to the line &lt;CODE&gt;NuxeoPrincipal user = ClientLoginModule.getCurrentPrincipal();&lt;/CODE&gt; which returns null and then exception is thrown. Thus, since the &lt;CODE&gt;null&lt;/CODE&gt; user is denied to create any user entry. So, now I know the problem, but how do I fix it. Since I am trying to login, I wont have any user logged-in in the first place. Any help is highly appreciated.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Mar 2019 09:04:47 GMT</pubDate>
    <dc:creator>Ritesh_Kumar</dc:creator>
    <dc:date>2019-03-28T09:04:47Z</dc:date>
    <item>
      <title>User not getting saved in MongoDb using UserManager service</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/user-not-getting-saved-in-mongodb-using-usermanager-service/m-p/323979#M10980</link>
      <description>&lt;P&gt;I have made a custom login plugin, where for the time being I am testing user creation in the handleRetrieveIdentity() method of the Authenticator.&lt;/P&gt;
&lt;P&gt;I am currently doing the following to save a user.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;UserManager userManager = Framework.getService(UserManager.class);
NuxeoPrincipal principal = userManager.getPrincipal(user.getEmail());
if (principal == null) {
    logger.debug("principal was null. creating a new user for email id {}",user.getEmail());
    DocumentModel userDocModel = userManager.getBareUserModel();
    userDocModel.setProperty("user", "username", user.getEmail());
    userDocModel.setProperty("user", "email", user.getEmail());
    userDocModel.setProperty("user", "password", "fakepassword" + new Random().nextInt());
    //userDocModel.setProperty("user", "groups", groups);
    userManager.createUser(userDocModel);
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But this is not saving the user in the mongo collection userDirectory where the other predefined users reside. What could I be doing wrong here?&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;I debugged the code and saw that the error was at &lt;CODE&gt;createUser(userDocModel)&lt;/CODE&gt; call. To create a user the &lt;CODE&gt;MongoDbSession&lt;/CODE&gt;'s inherited method &lt;CODE&gt;createEntry()&lt;/CODE&gt; checks for permission with the call &lt;CODE&gt;checkPermission(SecurityConstants.WRITE);&lt;/CODE&gt;, which goes to this piece of code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;public void checkPermission(String permission) {    
	if (hasPermission(permission)) {       
		 return;    
	}    
	if (permission.equals(SecurityConstants.WRITE) &amp;amp;&amp;amp; isReadOnly()) { 
	       throw new DirectorySecurityException("Directory is read-only");    
	} else {        
		NuxeoPrincipal user = ClientLoginModule.getCurrentPrincipal();    
	        throw new DirectorySecurityException("User " + user + " does not    have " + permission + " permission");    
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In my case, the control goes to the line &lt;CODE&gt;NuxeoPrincipal user = ClientLoginModule.getCurrentPrincipal();&lt;/CODE&gt; which returns null and then exception is thrown. Thus, since the &lt;CODE&gt;null&lt;/CODE&gt; user is denied to create any user entry. So, now I know the problem, but how do I fix it. Since I am trying to login, I wont have any user logged-in in the first place. Any help is highly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 09:04:47 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/user-not-getting-saved-in-mongodb-using-usermanager-service/m-p/323979#M10980</guid>
      <dc:creator>Ritesh_Kumar</dc:creator>
      <dc:date>2019-03-28T09:04:47Z</dc:date>
    </item>
  </channel>
</rss>

