List of usage examples for org.aspectj.lang.reflect MethodSignature getParameterNames
String[] getParameterNames();
From source file:org.finra.herd.service.advice.NamespaceSecurityAdviceTest.java
License:Apache License
@Test public void checkPermissionAssertNoExceptionWhenHasPermissionsNamespaceIgnoreCase() throws Exception { // Mock a join point of the method call // mockMethod("foo"); JoinPoint joinPoint = mock(JoinPoint.class); MethodSignature methodSignature = mock(MethodSignature.class); Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", String.class); when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace" }); when(methodSignature.getMethod()).thenReturn(method); when(joinPoint.getSignature()).thenReturn(methodSignature); when(joinPoint.getArgs()).thenReturn(new Object[] { "foo" }); String userId = "userId"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(userId);//from ww w . jav a 2 s.c o m applicationUser.setNamespaceAuthorizations(new HashSet<>()); // user has permission to capital "FOO" and needs permission to lowercase "foo" applicationUser.getNamespaceAuthorizations() .add(new NamespaceAuthorization("FOO", Arrays.asList(NamespacePermissionEnum.READ))); SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken( new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null)); try { namespaceSecurityAdvice.checkPermission(joinPoint); } catch (AccessDeniedException e) { fail(); } }
From source file:org.finra.herd.service.advice.NamespaceSecurityAdviceTest.java
License:Apache License
@Test public void checkPermissionAssertNoExceptionWhenNamespaceBlank() 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", String.class); when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace" }); when(methodSignature.getMethod()).thenReturn(method); when(joinPoint.getSignature()).thenReturn(methodSignature); when(joinPoint.getArgs()).thenReturn(new Object[] { BLANK_TEXT }); String userId = "userId"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(userId);/* w ww . j a v a 2 s . c o m*/ applicationUser.setNamespaceAuthorizations(new HashSet<>()); SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken( new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null)); try { namespaceSecurityAdvice.checkPermission(joinPoint); } catch (AccessDeniedException e) { fail(); } }
From source file:org.finra.herd.service.advice.NamespaceSecurityAdviceTest.java
License:Apache License
@Test public void checkPermissionAssertNoExceptionWhenHasPermissionsNamespaceTrimmed() throws Exception { // Mock a join point of the method call // mockMethod(" foo "); JoinPoint joinPoint = mock(JoinPoint.class); MethodSignature methodSignature = mock(MethodSignature.class); Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", String.class); when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace" }); when(methodSignature.getMethod()).thenReturn(method); when(joinPoint.getSignature()).thenReturn(methodSignature); when(joinPoint.getArgs()).thenReturn(new Object[] { BLANK_TEXT + "foo" + BLANK_TEXT }); String userId = "userId"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(userId);//from ww w . ja v a 2s.c o m applicationUser.setNamespaceAuthorizations(new HashSet<>()); // User has permission to "foo" but the actual namespace given is " foo " applicationUser.getNamespaceAuthorizations() .add(new NamespaceAuthorization("foo", Arrays.asList(NamespacePermissionEnum.READ))); SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken( new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null)); try { namespaceSecurityAdvice.checkPermission(joinPoint); } catch (AccessDeniedException e) { fail(); } }
From source file:org.finra.herd.service.advice.NamespaceSecurityAdviceTest.java
License:Apache License
@Test public void checkPermissionAssertAccessDeniedWhenNoPermissionsNamespaceTrimmed() throws Exception { // Mock a join point of the method call // mockMethod(" foo "); JoinPoint joinPoint = mock(JoinPoint.class); MethodSignature methodSignature = mock(MethodSignature.class); Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", String.class); when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace" }); when(methodSignature.getMethod()).thenReturn(method); when(joinPoint.getSignature()).thenReturn(methodSignature); when(joinPoint.getArgs()).thenReturn(new Object[] { BLANK_TEXT + "foo" + BLANK_TEXT }); String userId = "userId"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(userId);/*from w w w . j av a 2 s. com*/ applicationUser.setNamespaceAuthorizations(new HashSet<>()); // User has permission to "bar" but the actual namespace given is " foo " applicationUser.getNamespaceAuthorizations() .add(new NamespaceAuthorization("bar", Arrays.asList(NamespacePermissionEnum.READ))); 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\"", userId), e.getMessage()); } }
From source file:org.finra.herd.service.advice.NamespaceSecurityAdviceTest.java
License:Apache License
@Test public void checkPermissionAssertMultipleAccessDeniedExceptionsAreGatheredIntoSingleMessageWhenMultipleAnnotations() throws Exception { // Mock a join point of the method call // mockMethodMultipleAnnotations("namespace1", "namespace2"); JoinPoint joinPoint = mock(JoinPoint.class); MethodSignature methodSignature = mock(MethodSignature.class); Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethodMultipleAnnotations", String.class, String.class); when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace1", "namespace2" }); when(methodSignature.getMethod()).thenReturn(method); when(joinPoint.getSignature()).thenReturn(methodSignature); when(joinPoint.getArgs()).thenReturn(new Object[] { "foo", "bar" }); String userId = "userId"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(userId);/*from w w w . j av a2 s . co m*/ 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 \"[WRITE]\" permission(s) to the namespace \"bar\"", userId, userId), e.getMessage()); } }
From source file:org.finra.herd.service.advice.NamespaceSecurityAdviceTest.java
License:Apache License
@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);/*from ww w .j a v a 2s .c om*/ 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()); } }
From source file:org.finra.herd.service.advice.NamespaceSecurityAdviceTest.java
License:Apache License
/** * Assert no access denied exception when parameter value is null. *///from www .j ava 2 s .c o m @Test public void checkPermissionAssertNoExceptionWhenNull() throws Exception { // Mock a join point of the method call // mockMethod(null); JoinPoint joinPoint = mock(JoinPoint.class); MethodSignature methodSignature = mock(MethodSignature.class); Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", String.class); when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace" }); when(methodSignature.getMethod()).thenReturn(method); when(joinPoint.getSignature()).thenReturn(methodSignature); when(joinPoint.getArgs()).thenReturn(new Object[] { null }); String userId = "userId"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(userId); applicationUser.setNamespaceAuthorizations(new HashSet<>()); SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken( new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null)); try { namespaceSecurityAdvice.checkPermission(joinPoint); } catch (AccessDeniedException e) { fail(); } }
From source file:org.hsweb.web.core.utils.AopUtils.java
License:Apache License
public static final String getMethodName(ProceedingJoinPoint pjp) { StringBuilder methodName = new StringBuilder(pjp.getSignature().getName()).append("("); MethodSignature signature = (MethodSignature) pjp.getSignature(); String[] names = signature.getParameterNames(); Class[] args = signature.getParameterTypes(); for (int i = 0, len = args.length; i < len; i++) { if (i != 0) methodName.append(","); methodName.append(args[i].getSimpleName()).append(" ").append(names[i]); }//w ww . j a v a 2 s.c o m return methodName.append(")").toString(); }
From source file:org.hswebframework.web.AopUtils.java
License:Apache License
public static String getMethodBody(JoinPoint pjp) { StringBuilder methodName = new StringBuilder(pjp.getSignature().getName()).append("("); MethodSignature signature = (MethodSignature) pjp.getSignature(); String[] names = signature.getParameterNames(); Class[] args = signature.getParameterTypes(); for (int i = 0, len = args.length; i < len; i++) { if (i != 0) { methodName.append(","); }// w w w . j av a2 s .com methodName.append(args[i].getSimpleName()).append(" ").append(names[i]); } return methodName.append(")").toString(); }
From source file:org.hswebframework.web.AopUtils.java
License:Apache License
public static Map<String, Object> getArgsMap(JoinPoint pjp) { MethodSignature signature = (MethodSignature) pjp.getSignature(); Map<String, Object> args = new LinkedHashMap<>(); String names[] = signature.getParameterNames(); for (int i = 0, len = names.length; i < len; i++) { args.put(names[i], pjp.getArgs()[i]); }/*from w ww . j a va2 s.c o m*/ return args; }