use of org.aspectj.lang.JoinPoint in project herd by FINRAOS.
the class NamespaceSecurityAdviceTest method checkPermissionAssertAccessDeniedWhenCurrentUserHasWrongPermissionType.
/**
* Test the case where user has the namespace but does not have the permission
*/
@Test
public void checkPermissionAssertAccessDeniedWhenCurrentUserHasWrongPermissionType() 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);
applicationUser.setNamespaceAuthorizations(new HashSet<>());
// User has WRITE permissions, but the method requires READ
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("foo", Arrays.asList(NamespacePermissionEnum.WRITE)));
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());
}
}
use of org.aspectj.lang.JoinPoint in project herd by FINRAOS.
the class NamespaceSecurityAdvice method checkPermission.
/**
* Check permission on the service methods before the execution. The method is expected to throw AccessDeniedException if current user does not have the
* permissions.
*
* @param joinPoint The join point
*/
@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);
}
}
}
use of org.aspectj.lang.JoinPoint in project frodo by android10.
the class LogSubscriberTest method annotatedClassMustCheckTargetType.
@Test
public void annotatedClassMustCheckTargetType() {
final JoinPoint joinPoint = mock(JoinPoint.class);
given(joinPoint.getTarget()).willReturn(subscriber);
assertThat(LogSubscriber.classAnnotatedWithRxLogSubscriber(joinPoint)).isTrue();
verify(joinPoint).getTarget();
verifyNoMoreInteractions(joinPoint);
}
use of org.aspectj.lang.JoinPoint in project paascloud-master by paascloud.
the class MqProducerStoreAspect method processMqProducerStoreJoinPoint.
/**
* Add exe time method object.
*
* @param joinPoint the join point
*
* @return the object
*/
@Around(value = "mqProducerStoreAnnotationPointcut()")
public Object processMqProducerStoreJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("processMqProducerStoreJoinPoint - 线程id={}", Thread.currentThread().getId());
Object result;
Object[] args = joinPoint.getArgs();
MqProducerStore annotation = getAnnotation(joinPoint);
MqSendTypeEnum type = annotation.sendType();
int orderType = annotation.orderType().orderType();
DelayLevelEnum delayLevelEnum = annotation.delayLevel();
if (args.length == 0) {
throw new TpcBizException(ErrorCodeEnum.TPC10050005);
}
MqMessageData domain = null;
for (Object object : args) {
if (object instanceof MqMessageData) {
domain = (MqMessageData) object;
break;
}
}
if (domain == null) {
throw new TpcBizException(ErrorCodeEnum.TPC10050005);
}
domain.setOrderType(orderType);
domain.setProducerGroup(producerGroup);
if (type == MqSendTypeEnum.WAIT_CONFIRM) {
if (delayLevelEnum != DelayLevelEnum.ZERO) {
domain.setDelayLevel(delayLevelEnum.delayLevel());
}
mqMessageService.saveWaitConfirmMessage(domain);
}
result = joinPoint.proceed();
if (type == MqSendTypeEnum.SAVE_AND_SEND) {
mqMessageService.saveAndSendMessage(domain);
} else if (type == MqSendTypeEnum.DIRECT_SEND) {
mqMessageService.directSendMessage(domain);
} else {
final MqMessageData finalDomain = domain;
taskExecutor.execute(() -> mqMessageService.confirmAndSendMessage(finalDomain.getMessageKey()));
}
return result;
}
use of org.aspectj.lang.JoinPoint in project PhotoNoter by yydcdut.
the class PermissionAspect method afterPermissionRequestBack4Fragment.
@After("execution(* android.app.Fragment.onRequestPermissionsResult(..))")
public void afterPermissionRequestBack4Fragment(JoinPoint joinPoint) {
Object[] objects = joinPoint.getArgs();
Object object = joinPoint.getTarget();
if (objects.length >= 1 && objects[0] instanceof Integer && object != null && object instanceof IView && ((IView) object).getPresenter() != null) {
int requestCode = (int) objects[0];
invokeMethod(((IView) object).getPresenter(), requestCode);
} else {
YLog.i(TAG, "afterPermissionRequestBack4Fragment --> bad");
}
}
Aggregations