test_class.declarator: TEST_USER = "testUser"
test_class.modifier: private static final
test_class.original_string: private static final String TEST_USER = "testUser";
test_class.type: String
test_class.var_name: TEST_USER
test_class.file: vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/impl/AdminPermissionCheckerTest.java
test_class.identifier: AdminPermissionCheckerTest
test_class.superclass: extends IntegrationTestBase
test_case.body: @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();
          }
      }
test_case.class_method_signature: AdminPermissionCheckerTest.testAdditionalAdminUser()
test_case.full_signature: @Test public void testAdditionalAdminUser()
test_case.identifier: testAdditionalAdminUser
test_case.invocations: getAuthorizable getUserManager assertNull createUser getUserManager save login toCharArray assertTrue hasAdministrativePermissions logout
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAdditionalAdminUser()
focal_class.declarator: log = LoggerFactory.getLogger(AdminPermissionChecker.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(AdminPermissionChecker.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: ADMIN_USER = "admin"
focal_class.modifier: private static final
focal_class.original_string: private static final String ADMIN_USER = "admin";
focal_class.type: String
focal_class.var_name: ADMIN_USER
focal_class.declarator: SYSTEM_USER = "system"
focal_class.modifier: private static final
focal_class.original_string: private static final String SYSTEM_USER = "system";
focal_class.type: String
focal_class.var_name: SYSTEM_USER
focal_class.declarator: ADMINISTRATORS_GROUP = "administrators"
focal_class.modifier: private static final
focal_class.original_string: private static final String ADMINISTRATORS_GROUP = "administrators";
focal_class.type: String
focal_class.var_name: ADMINISTRATORS_GROUP
focal_class.file: vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/AdminPermissionChecker.java
focal_class.identifier: AdminPermissionChecker
focal_class.class_method_signature: AdminPermissionChecker.hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds)
focal_class.full_signature: public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds)
focal_class.identifier: hasAdministrativePermissions
focal_class.modifiers: public static
focal_class.parameters: (@NotNull Session session, String... additionalAdminAuthorizableIds)
focal_class.return: boolean
focal_class.signature: boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds)
focal_method.body: 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;
      }
focal_method.class_method_signature: AdminPermissionChecker.hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds)
focal_method.full_signature: public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds)
focal_method.identifier: hasAdministrativePermissions
focal_method.invocations: getUserID equals equals asList orElse ofNullable contains warn getAuthorizable getUserManager memberOf hasNext getID next equals contains
focal_method.modifiers: public static
focal_method.parameters: (@NotNull Session session, String... additionalAdminAuthorizableIds)
focal_method.return: boolean
focal_method.signature: boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds)