test_class.declarator: namespaceSecurityAdvice
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private NamespaceSecurityAdvice namespaceSecurityAdvice;
test_class.type: NamespaceSecurityAdvice
test_class.var_name: namespaceSecurityAdvice
test_class.declarator: businessObjectDefinitionServiceImpl
test_class.modifier: @Autowired
      @Qualifier(value = "businessObjectDefinitionServiceImpl")
      private
test_class.original_string: @Autowired
      @Qualifier(value = "businessObjectDefinitionServiceImpl")
      private BusinessObjectDefinitionService businessObjectDefinitionServiceImpl;
test_class.type: BusinessObjectDefinitionService
test_class.var_name: businessObjectDefinitionServiceImpl
test_class.file: herd-code/herd-service/src/test/java/org/finra/herd/service/advice/NamespaceSecurityAdviceTest.java
test_class.identifier: NamespaceSecurityAdviceTest
test_class.superclass: extends AbstractServiceTest
test_case.body: @Test
      public void checkPermissionAssertMultipleAccessDeniedExceptionsAreGatheredIntoSingleMessageWhenCollections() throws Exception
      {
          // Mock a join point of the method call
          // mockMethod({"", ""})
          JoinPoint joinPoint = mock(JoinPoint.class);
          MethodSignature methodSignature = mock(MethodSignature.class);
          Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", List.class);
          when(methodSignature.getParameterNames()).thenReturn(new String[] {"namespaces"});
          when(methodSignature.getMethod()).thenReturn(method);
          when(joinPoint.getSignature()).thenReturn(methodSignature);
          when(joinPoint.getArgs()).thenReturn(new Object[] {Arrays.asList("foo", "bar")});
  
          String userId = "userId";
          ApplicationUser applicationUser = new ApplicationUser(getClass());
          applicationUser.setUserId(userId);
          applicationUser.setNamespaceAuthorizations(new HashSet<>());
          // User has no permissions
          SecurityContextHolder.getContext().setAuthentication(
              new TestingAuthenticationToken(new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null));
  
          try
          {
              namespaceSecurityAdvice.checkPermission(joinPoint);
              fail();
          }
          catch (Exception e)
          {
              assertEquals(AccessDeniedException.class, e.getClass());
              assertEquals(String.format("User \"%s\" does not have \"[READ]\" permission(s) to the namespace \"foo\"%n" +
                  "User \"%s\" does not have \"[READ]\" permission(s) to the namespace \"bar\"", userId, userId), e.getMessage());
          }
      }
test_case.class_method_signature: NamespaceSecurityAdviceTest.checkPermissionAssertMultipleAccessDeniedExceptionsAreGatheredIntoSingleMessageWhenCollections()
test_case.full_signature: @Test public void checkPermissionAssertMultipleAccessDeniedExceptionsAreGatheredIntoSingleMessageWhenCollections()
test_case.identifier: checkPermissionAssertMultipleAccessDeniedExceptionsAreGatheredIntoSingleMessageWhenCollections
test_case.invocations: mock mock getDeclaredMethod thenReturn when getParameterNames thenReturn when getMethod thenReturn when getSignature thenReturn when getArgs asList getClass setUserId setNamespaceAuthorizations setAuthentication getContext asList checkPermission fail assertEquals getClass assertEquals format getMessage
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void checkPermissionAssertMultipleAccessDeniedExceptionsAreGatheredIntoSingleMessageWhenCollections()
focal_class.declarator: spelExpressionHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private SpelExpressionHelper spelExpressionHelper;
focal_class.type: SpelExpressionHelper
focal_class.var_name: spelExpressionHelper
focal_class.declarator: namespaceSecurityHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private NamespaceSecurityHelper namespaceSecurityHelper;
focal_class.type: NamespaceSecurityHelper
focal_class.var_name: namespaceSecurityHelper
focal_class.file: herd-code/herd-service/src/main/java/org/finra/herd/service/advice/NamespaceSecurityAdvice.java
focal_class.identifier: NamespaceSecurityAdvice
focal_class.class_method_signature: NamespaceSecurityAdvice.checkPermission(JoinPoint joinPoint)
focal_class.full_signature: @Before("serviceMethods()") public void checkPermission(JoinPoint joinPoint)
focal_class.identifier: checkPermission
focal_class.modifiers: @Before("serviceMethods()") public
focal_class.parameters: (JoinPoint joinPoint)
focal_class.return: void
focal_class.signature: void checkPermission(JoinPoint joinPoint)
focal_class.superclass: extends AbstractServiceAdvice
focal_method.body: @Before("serviceMethods()")
      public void checkPermission(JoinPoint joinPoint)
      {
  
          MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
          Method method = methodSignature.getMethod();
  
          List<NamespacePermission> namespacePermissions = new ArrayList<>();
          if (method.isAnnotationPresent(NamespacePermissions.class))
          {
              namespacePermissions.addAll(Arrays.asList(method.getAnnotation(NamespacePermissions.class).value()));
          }
          else if (method.isAnnotationPresent(NamespacePermission.class))
          {
              namespacePermissions.add(method.getAnnotation(NamespacePermission.class));
          }
  
          if (!namespacePermissions.isEmpty())
          {
              String[] parameterNames = methodSignature.getParameterNames();
              Object[] args = joinPoint.getArgs();
  
              Map<String, Object> variables = new HashMap<>();
              for (int i = 0; i < parameterNames.length; i++)
              {
                  variables.put(parameterNames[i], args[i]);
              }
  
              List<AccessDeniedException> accessDeniedExceptions = new ArrayList<>();
              for (NamespacePermission namespacePermission : namespacePermissions)
              {
                  for (String field : namespacePermission.fields())
                  {
                      try
                      {
                          namespaceSecurityHelper.checkPermission(spelExpressionHelper.evaluate(field, Object.class, variables), namespacePermission
                              .permissions());
                      }
                      catch (AccessDeniedException accessDeniedException)
                      {
                          accessDeniedExceptions.add(accessDeniedException);
                      }
                  }
              }
              if (!accessDeniedExceptions.isEmpty())
              {
                  throw namespaceSecurityHelper.getAccessDeniedException(accessDeniedExceptions);
              }
          }
      }
focal_method.class_method_signature: NamespaceSecurityAdvice.checkPermission(JoinPoint joinPoint)
focal_method.full_signature: @Before("serviceMethods()") public void checkPermission(JoinPoint joinPoint)
focal_method.identifier: checkPermission
focal_method.invocations: getSignature getMethod isAnnotationPresent addAll asList value getAnnotation isAnnotationPresent add getAnnotation isEmpty getParameterNames getArgs put fields checkPermission evaluate permissions add isEmpty getAccessDeniedException
focal_method.modifiers: @Before("serviceMethods()") public
focal_method.parameters: (JoinPoint joinPoint)
focal_method.return: void
focal_method.signature: void checkPermission(JoinPoint joinPoint)