private Availability availability(String name, boolean defaultValue) { String property = "management.endpoint." + name + ".enabled"; if (!environment.getProperty(property, Boolean.TYPE, defaultValue)) { return Availability.unavailable("endpoint '" + name + "' deactivated (please check property '" + property + "')"); } else if (properties.getActuator().getExcludes().contains(name)) { return Availability.unavailable("command is present in exclusion (please check property '" + SshShellProperties.SSH_SHELL_PREFIX + ".actuator.excludes')"); } return Availability.available(); }
private Supplier<Availability> bridgeAvailabilityIndicator(String commandKey, Object bean) { Class<?> clazz = bean.getClass(); Set<Method> candidates = new HashSet<>(); ReflectionUtils.doWithMethods(clazz, candidates::add, method -> method.getAnnotation(CliAvailabilityIndicator.class) != null && Arrays.asList(method.getAnnotation(CliAvailabilityIndicator.class).value()).contains(commandKey)); switch (candidates.size()) { case 0: return null; case 1: return () -> { boolean available = (Boolean) ReflectionUtils.invokeMethod(candidates.iterator().next(), bean); return available ? Availability.available() : Availability.unavailable("[Unknown reason]"); }; default: throw new IllegalStateException("Looks like there are several @" + CliAvailabilityIndicator.class.getSimpleName() + " for '" + commandKey + "'. Found " + candidates); } }
private Availability availability(String name, Class<?> clazz, boolean defaultValue) { if (!"info".equals(name)) { SshAuthentication auth = SshShellCommandFactory.SSH_THREAD_CONTEXT.get().getAuthentication(); List<String> authorities = auth != null ? auth.getAuthorities() : null; if (!helper.checkAuthorities(properties.getActuator().getAuthorizedRoles(), authorities, properties.getAuthentication() == SshShellProperties.AuthenticationType.simple)) { return Availability.unavailable("actuator commands are forbidden for current user"); } } String property = "management.endpoint." + name + ".enabled"; if (!environment.getProperty(property, Boolean.TYPE, defaultValue)) { return Availability.unavailable("endpoint '" + name + "' deactivated (please check property '" + property + "')"); } else if (properties.getActuator().getExcludes().contains(name)) { return Availability.unavailable("command is present in exclusion (please check property '" + SSH_SHELL_PREFIX + ".actuator.excludes')"); } try { applicationContext.getBean(clazz); } catch (NoSuchBeanDefinitionException e) { return Availability.unavailable(clazz.getName() + " is not in application context"); } return Availability.available(); }