Source:
<code>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."); } AtomicBoolean checkOk = new AtomicBoolean(false); final String authority = annotation.authority(); final String[] values = annotation.values(); final Supplier<Stream<String>> streamSupplier = () -> Stream.of(values); final String value = annotation.value(); if (StringUtils.isNotBlank(authority)) { <START> if (isAllowed(authority)) { <END> checkOk.set(true); } } else if (streamSupplier.get().anyMatch(StringUtils::isNotBlank)) { streamSupplier.get().filter(StringUtils::isNotBlank).forEach(currentAuthority -> { if (isAllowed(currentAuthority)) { checkOk.set(true); } }); } else if (StringUtils.isNotBlank(value)) { if (isAllowed(value)) { checkOk.set(true); } } if (!checkOk.get()) { 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(); }</code><technical_language>avoid if with: checkOk.set(isAllowed(authority));</technical_language>

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; } if (streamSupplier != null && 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(); }