+ /**
+ * Returns the home node of the user or null if none was found.
+ *
+ * @param session
+ * the session to use in order to perform the search, this can be
+ * a session with a different user ID than the one searched,
+ * typically when a system or admin session is used.
+ * @param cn
+ * the username of the user
+ */
+ public static Node getGroupHome(Session session, String cn) {
+ try {
+ QueryObjectModelFactory qomf = session.getWorkspace().getQueryManager().getQOMFactory();
+ Selector sel = qomf.selector(NodeTypes.NODE_GROUP_HOME, "sel");
+ DynamicOperand dop = qomf.propertyValue(sel.getSelectorName(), NodeNames.LDAP_CN);
+ StaticOperand sop = qomf.literal(session.getValueFactory().createValue(cn));
+ Constraint constraint = qomf.comparison(dop, QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, sop);
+ Query query = qomf.createQuery(sel, constraint, null, null);
+ return querySingleNode(query);
+ } catch (RepositoryException e) {
+ throw new RuntimeException("Cannot find home for user " + cn, e);
+ }
+ }
+