jackrabbit-oak-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Georg Henzler (JIRA)" <j...@apache.org>
Subject [jira] [Created] (OAK-3228) Delayed visibility of new groups when using PrincipalManager
Date Thu, 13 Aug 2015 13:57:45 GMT
Georg Henzler created OAK-3228:
----------------------------------

             Summary: Delayed visibility of new groups when using PrincipalManager 
                 Key: OAK-3228
                 URL: https://issues.apache.org/jira/browse/OAK-3228
             Project: Jackrabbit Oak
          Issue Type: Bug
          Components: core
    Affects Versions: 1.2.2
            Reporter: Georg Henzler


PrincipalManager does not show groups that were just created (this is causing problems in
our code). As workaround we use now UserManager.getAuthorizable().getPrincipal() which curiously
works immediately after saving a group. Also it does not seem to be index problem, as a query
{{SELECT * FROM [rep:Authorizable] WHERE [rep:principalName] = "mygroup"}} also immediately
shows a new group.

See the following servlet snippet for easy reproduction:
{code}
...
@SlingServlet(paths = "/bin/CreateGroupAndRetrievePrincipal", methods = "GET")
public class CreateGroupAndRetrievePrincipalServlet extends SlingSafeMethodsServlet {
    private static final long serialVersionUID = 1L;
    private static final Logger LOG = LoggerFactory.getLogger(CreateGroupAndRetrievePrincipalServlet.class);

    @Reference
    private SlingRepository repository;

    @Override
    @SuppressWarnings("deprecation")
    protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse
response) throws ServletException,
            IOException {
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();

        final String groupName = request.getParameter("g");

        LOG.debug("test");
        Session session = null;
        try {
            session = repository.loginAdministrative(null);
            UserManager usermanager = ((JackrabbitSession) session).getUserManager();

            Group newGroup = usermanager.createGroup(new java.security.Principal() {

                @Override
                public String getName() {
                    return groupName;
                }
            }, "principaltest");
            out.println("Created Group " + newGroup);

            session.save();

        } catch (Exception e) {
            throw new ServletException(e.getMessage(), e);
        } finally {
            if (session != null) {
                session.logout();
                session = null;
            }
        }

        out.println();

        try {
            session = repository.loginAdministrative(null);

            // No 1: PrincipalManager

            PrincipalManager principalManager = ((JackrabbitSession) session).getPrincipalManager();

            Principal principal = principalManager.getPrincipal(groupName);
            out.println("PrincipalManager: principal: " + principal);

            // No 2: UserManager

            UserManager usermanager = ((JackrabbitSession) session).getUserManager();

            Authorizable authorizable = usermanager.getAuthorizable(groupName);
            out.println("UserManager: authorizable: " + authorizable);

            // No 3: query

            QueryManager queryManager = session.getWorkspace().getQueryManager();
            final Query query = queryManager.createQuery("SELECT * FROM [rep:Authorizable]
WHERE [rep:principalName] = \"" + groupName
                    + "\"", Query.JCR_SQL2);

            QueryResult result = query.execute();

            NodeIterator nodes = result.getNodes();
            if (!nodes.hasNext()) {
                out.println("QUERY: group not found: " + groupName);
            }
            while (nodes.hasNext()) {
                Node resultNode = (Node) nodes.next();
                out.println("QUERY: node " + resultNode.getPath() + " property rep:principalName="
                        + resultNode.getProperty("rep:principalName").getString());
            }

            query.execute();

        } catch (Exception e) {
            throw new ServletException(e.getMessage(), e);
        } finally {
            if (session != null) {
                session.logout();
                session = null;
            }
        }

    }

}
{code}

Potentially the problem is that the principal manager holds its own session (even though it
was retrieved by {{((JackrabbitSession) session).getPrincipalManager()}}) and the refresh
behaviour of sessions (http://jackrabbit.apache.org/oak/docs/dos_and_donts.html)




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message