@Test public void testAdditionalAdminUser() throws AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException { JackrabbitSession jackrabbitSession = (JackrabbitSession) admin; Authorizable vip = jackrabbitSession.getUserManager().getAuthorizable(TEST_USER); assertNull("test user must not exist", vip); jackrabbitSession.getUserManager().createUser(TEST_USER, TEST_USER); admin.save(); Session session = repository.login(new SimpleCredentials(TEST_USER, TEST_USER.toCharArray())); try { assertTrue( "\"" + TEST_USER + "\" is additional admin/system thus should have admin permissions", AdminPermissionChecker.hasAdministrativePermissions(session, TEST_USER)); } finally { session.logout(); } }
public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds) throws RepositoryException { String userId = session.getUserID(); if (ADMIN_USER.equals(userId) || SYSTEM_USER.equals(userId)) { return true; } List<String> additionalAdminIds = Arrays.asList(Optional.ofNullable(additionalAdminAuthorizableIds).orElse(new String[0])); if (additionalAdminIds.contains(userId)) { return true; } if (!(session instanceof JackrabbitSession)) { log.warn("could not evaluate group permissions but just user name"); return false; } JackrabbitSession jackrabbitSession = (JackrabbitSession) session; Authorizable authorizable = jackrabbitSession.getUserManager().getAuthorizable(userId); if (authorizable == null) { return false; } Iterator<Group> groupIterator = authorizable.memberOf(); while (groupIterator.hasNext()) { String groupId = groupIterator.next().getID(); if (ADMINISTRATORS_GROUP.equals(groupId)) { return true; } if (additionalAdminIds.contains(groupId)) { return true; } } return false; }
AdminPermissionChecker { public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds) throws RepositoryException { String userId = session.getUserID(); if (ADMIN_USER.equals(userId) || SYSTEM_USER.equals(userId)) { return true; } List<String> additionalAdminIds = Arrays.asList(Optional.ofNullable(additionalAdminAuthorizableIds).orElse(new String[0])); if (additionalAdminIds.contains(userId)) { return true; } if (!(session instanceof JackrabbitSession)) { log.warn("could not evaluate group permissions but just user name"); return false; } JackrabbitSession jackrabbitSession = (JackrabbitSession) session; Authorizable authorizable = jackrabbitSession.getUserManager().getAuthorizable(userId); if (authorizable == null) { return false; } Iterator<Group> groupIterator = authorizable.memberOf(); while (groupIterator.hasNext()) { String groupId = groupIterator.next().getID(); if (ADMINISTRATORS_GROUP.equals(groupId)) { return true; } if (additionalAdminIds.contains(groupId)) { return true; } } return false; } }
AdminPermissionChecker { public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds) throws RepositoryException { String userId = session.getUserID(); if (ADMIN_USER.equals(userId) || SYSTEM_USER.equals(userId)) { return true; } List<String> additionalAdminIds = Arrays.asList(Optional.ofNullable(additionalAdminAuthorizableIds).orElse(new String[0])); if (additionalAdminIds.contains(userId)) { return true; } if (!(session instanceof JackrabbitSession)) { log.warn("could not evaluate group permissions but just user name"); return false; } JackrabbitSession jackrabbitSession = (JackrabbitSession) session; Authorizable authorizable = jackrabbitSession.getUserManager().getAuthorizable(userId); if (authorizable == null) { return false; } Iterator<Group> groupIterator = authorizable.memberOf(); while (groupIterator.hasNext()) { String groupId = groupIterator.next().getID(); if (ADMINISTRATORS_GROUP.equals(groupId)) { return true; } if (additionalAdminIds.contains(groupId)) { return true; } } return false; }  }
AdminPermissionChecker { public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds) throws RepositoryException { String userId = session.getUserID(); if (ADMIN_USER.equals(userId) || SYSTEM_USER.equals(userId)) { return true; } List<String> additionalAdminIds = Arrays.asList(Optional.ofNullable(additionalAdminAuthorizableIds).orElse(new String[0])); if (additionalAdminIds.contains(userId)) { return true; } if (!(session instanceof JackrabbitSession)) { log.warn("could not evaluate group permissions but just user name"); return false; } JackrabbitSession jackrabbitSession = (JackrabbitSession) session; Authorizable authorizable = jackrabbitSession.getUserManager().getAuthorizable(userId); if (authorizable == null) { return false; } Iterator<Group> groupIterator = authorizable.memberOf(); while (groupIterator.hasNext()) { String groupId = groupIterator.next().getID(); if (ADMINISTRATORS_GROUP.equals(groupId)) { return true; } if (additionalAdminIds.contains(groupId)) { return true; } } return false; }  static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds); }
AdminPermissionChecker { public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds) throws RepositoryException { String userId = session.getUserID(); if (ADMIN_USER.equals(userId) || SYSTEM_USER.equals(userId)) { return true; } List<String> additionalAdminIds = Arrays.asList(Optional.ofNullable(additionalAdminAuthorizableIds).orElse(new String[0])); if (additionalAdminIds.contains(userId)) { return true; } if (!(session instanceof JackrabbitSession)) { log.warn("could not evaluate group permissions but just user name"); return false; } JackrabbitSession jackrabbitSession = (JackrabbitSession) session; Authorizable authorizable = jackrabbitSession.getUserManager().getAuthorizable(userId); if (authorizable == null) { return false; } Iterator<Group> groupIterator = authorizable.memberOf(); while (groupIterator.hasNext()) { String groupId = groupIterator.next().getID(); if (ADMINISTRATORS_GROUP.equals(groupId)) { return true; } if (additionalAdminIds.contains(groupId)) { return true; } } return false; }  static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds);  }