@Test public void testGetAuthorizableByPrincipal() throws Exception { UserProvider up = createUserProvider(); up.createUser("uid", null); TreeBasedPrincipal tbp = new TreeBasedPrincipal("uid", "/path", NamePathMapper.DEFAULT) { @Override @NotNull String getOakPath() { return "/path"; } }; assertNotNull(up.getAuthorizableByPrincipal(tbp)); }
@Nullable Tree getAuthorizableByPrincipal(@NotNull Principal principal) { if (principal instanceof TreeBasedPrincipal) { try { return root.getTree(((TreeBasedPrincipal) principal).getOakPath()); } catch (RepositoryException e) { log.debug(e.getMessage()); } } try { StringBuilder stmt = new StringBuilder(); stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']'); stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName"); stmt.append(QueryEngine.INTERNAL_SQL2_QUERY); Result result = root.getQueryEngine().executeQuery(stmt.toString(), Query.JCR_SQL2, 1, 0, Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())), NO_MAPPINGS); Iterator<? extends ResultRow> rows = result.getRows().iterator(); if (rows.hasNext()) { String path = rows.next().getPath(); return root.getTree(path); } } catch (ParseException ex) { log.error("Failed to retrieve authorizable by principal", ex); } return null; }
UserProvider extends AuthorizableBaseProvider { @Nullable Tree getAuthorizableByPrincipal(@NotNull Principal principal) { if (principal instanceof TreeBasedPrincipal) { try { return root.getTree(((TreeBasedPrincipal) principal).getOakPath()); } catch (RepositoryException e) { log.debug(e.getMessage()); } } try { StringBuilder stmt = new StringBuilder(); stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']'); stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName"); stmt.append(QueryEngine.INTERNAL_SQL2_QUERY); Result result = root.getQueryEngine().executeQuery(stmt.toString(), Query.JCR_SQL2, 1, 0, Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())), NO_MAPPINGS); Iterator<? extends ResultRow> rows = result.getRows().iterator(); if (rows.hasNext()) { String path = rows.next().getPath(); return root.getTree(path); } } catch (ParseException ex) { log.error("Failed to retrieve authorizable by principal", ex); } return null; } }
UserProvider extends AuthorizableBaseProvider { @Nullable Tree getAuthorizableByPrincipal(@NotNull Principal principal) { if (principal instanceof TreeBasedPrincipal) { try { return root.getTree(((TreeBasedPrincipal) principal).getOakPath()); } catch (RepositoryException e) { log.debug(e.getMessage()); } } try { StringBuilder stmt = new StringBuilder(); stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']'); stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName"); stmt.append(QueryEngine.INTERNAL_SQL2_QUERY); Result result = root.getQueryEngine().executeQuery(stmt.toString(), Query.JCR_SQL2, 1, 0, Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())), NO_MAPPINGS); Iterator<? extends ResultRow> rows = result.getRows().iterator(); if (rows.hasNext()) { String path = rows.next().getPath(); return root.getTree(path); } } catch (ParseException ex) { log.error("Failed to retrieve authorizable by principal", ex); } return null; } UserProvider(@NotNull Root root, @NotNull ConfigurationParameters config); }
UserProvider extends AuthorizableBaseProvider { @Nullable Tree getAuthorizableByPrincipal(@NotNull Principal principal) { if (principal instanceof TreeBasedPrincipal) { try { return root.getTree(((TreeBasedPrincipal) principal).getOakPath()); } catch (RepositoryException e) { log.debug(e.getMessage()); } } try { StringBuilder stmt = new StringBuilder(); stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']'); stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName"); stmt.append(QueryEngine.INTERNAL_SQL2_QUERY); Result result = root.getQueryEngine().executeQuery(stmt.toString(), Query.JCR_SQL2, 1, 0, Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())), NO_MAPPINGS); Iterator<? extends ResultRow> rows = result.getRows().iterator(); if (rows.hasNext()) { String path = rows.next().getPath(); return root.getTree(path); } } catch (ParseException ex) { log.error("Failed to retrieve authorizable by principal", ex); } return null; } UserProvider(@NotNull Root root, @NotNull ConfigurationParameters config);  }
UserProvider extends AuthorizableBaseProvider { @Nullable Tree getAuthorizableByPrincipal(@NotNull Principal principal) { if (principal instanceof TreeBasedPrincipal) { try { return root.getTree(((TreeBasedPrincipal) principal).getOakPath()); } catch (RepositoryException e) { log.debug(e.getMessage()); } } try { StringBuilder stmt = new StringBuilder(); stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']'); stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName"); stmt.append(QueryEngine.INTERNAL_SQL2_QUERY); Result result = root.getQueryEngine().executeQuery(stmt.toString(), Query.JCR_SQL2, 1, 0, Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())), NO_MAPPINGS); Iterator<? extends ResultRow> rows = result.getRows().iterator(); if (rows.hasNext()) { String path = rows.next().getPath(); return root.getTree(path); } } catch (ParseException ex) { log.error("Failed to retrieve authorizable by principal", ex); } return null; } UserProvider(@NotNull Root root, @NotNull ConfigurationParameters config);   }