Source:
public Object requires(ProceedingJoinPoint pjp) throws Throwable { final Authentication authentication = ofNullable(getContext().getAuthentication()).orElse(ANONYMOUS); LOGGER.debug("Checking @Required access on for user {}.", pjp, authentication); final MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); final Method method = methodSignature.getMethod(); final RequiresAuthority annotation = method.getAnnotation(RequiresAuthority.class); if (annotation == null) { throw new IllegalArgumentException("Missing @RequiresAuthority annotation."); } final String[] authorityArray = annotation.authority(); final Supplier<Stream<String>> authorityStreamSupplier = () -> Stream.of(authorityArray).filter(StringUtils::isNotBlank); final String[] valueArray = annotation.value(); final Supplier<Stream<String>> valueStreamSupplier = () -> Stream.of(valueArray).filter(StringUtils::isNotBlank); Supplier<Stream<String>> streamSupplier = null; if (authorityStreamSupplier.get().count() > 0) { streamSupplier = authorityStreamSupplier; } else if (valueStreamSupplier.get().count() > 0) { streamSupplier = valueStreamSupplier; } final Class<? extends Supplier<Boolean>> activeIf = annotation.activeIf(); final boolean isActive = activeIf.equals(RequiresAuthorityConditionDefaults.AlwaysTrue.class); if (streamSupplier != null && !isActive && streamSupplier.get().noneMatch(RequiresAuthorityAspect::isAllowed)) { LOGGER.debug("Access denied for user on {}.", authentication, method); final Class<? extends AccessDenied> onDeny = annotation.onDeny(); final AccessDenied accessDenied; try { accessDenied = onDeny.newInstance(); return accessDenied.onDeny(annotation, method, pjp.getArgs()); } catch (InstantiationException noInstance) { LOGGER.error("Unable to use on deny custom class {}", onDeny.getName(), noInstance); throw new AccessDeniedException("Access denied for " + method.getName() + ".", noInstance); } } LOGGER.debug("Access allowed for user on {}.", authentication, method); return pjp.proceed(); }

Target:
public Object requires(ProceedingJoinPoint pjp) throws Throwable { final Authentication authentication = ofNullable(getContext().getAuthentication()).orElse(ANONYMOUS); LOGGER.debug("Checking @Required access on for user {}.", pjp, authentication); final MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); final Method method = methodSignature.getMethod(); final RequiresAuthority annotation = method.getAnnotation(RequiresAuthority.class); if (annotation == null) { throw new IllegalArgumentException("Missing @RequiresAuthority annotation."); } final String[] authorityArray = annotation.authority(); final Supplier<Stream<String>> authorityStreamSupplier = () -> Stream.of(authorityArray).filter(StringUtils::isNotBlank); final String[] valueArray = annotation.value(); final Supplier<Stream<String>> valueStreamSupplier = () -> Stream.of(valueArray).filter(StringUtils::isNotBlank); Supplier<Stream<String>> streamSupplier = null; if (authorityStreamSupplier.get().count() > 0) { streamSupplier = authorityStreamSupplier; } else if (valueStreamSupplier.get().count() > 0) { streamSupplier = valueStreamSupplier; } final Class<? extends Function<ApplicationContext, Boolean>> activeIf = annotation.activeIf(); final Boolean isActive = activeIf.newInstance().apply(applicationContext); if (streamSupplier != null && isActive && streamSupplier.get().noneMatch(RequiresAuthorityAspect::isAllowed)) { LOGGER.debug("Access denied for user on {}.", authentication, method); final Class<? extends AccessDenied> onDeny = annotation.onDeny(); final AccessDenied accessDenied; try { accessDenied = onDeny.newInstance(); return accessDenied.onDeny(annotation, method, pjp.getArgs()); } catch (InstantiationException noInstance) { LOGGER.error("Unable to use on deny custom class {}", onDeny.getName(), noInstance); throw new AccessDeniedException("Access denied for " + method.getName() + ".", noInstance); } } LOGGER.debug("Access allowed for user on {}.", authentication, method); return pjp.proceed(); }