DescribeQueryServiceCommand extends GfshCommand { void addMethodAuthorizerToResultModel(QueryConfigService queryConfigurationService, ResultModel result) { QueryConfigService.MethodAuthorizer methodAuthorizer = queryConfigurationService.getMethodAuthorizer(); DataResultModel dataResultModel = result.addData(QUERY_SERVICE_DATA_SECTION); if (methodAuthorizer != null) { if (isSecurityEnabled()) { dataResultModel .addData(AUTHORIZER_CLASS_NAME, methodAuthorizer.getClassName()); } else { dataResultModel .addData(AUTHORIZER_CLASS_NAME, ALL_METHODS_ALLOWED); } } }  @CliCommand(value = COMMAND_NAME, help = COMMAND_HELP) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.READ) ResultModel execute(); static final String ALL_METHODS_ALLOWED; static final String FUNCTION_FAILED_ON_ALL_MEMBERS; static final String NO_CLUSTER_CONFIG_AND_NO_MEMBERS; static final String AUTHORIZER_CLASS_NAME; }
@Test public void addMethodAuthorizerToResultModelPopulatesResultWithCorrectValuesAndSectionsWhenAuthorizerIsFoundAndSecurityIsEnabled() { final int numberOfParameters = 2; String methodAuthClassName = "Class.Package.Name"; QueryConfigService.MethodAuthorizer methodAuthorizer = new QueryConfigService.MethodAuthorizer(); methodAuthorizer.setClassName(methodAuthClassName); List<QueryConfigService.MethodAuthorizer.Parameter> params = new ArrayList<>(); for (int i = 0; i < numberOfParameters; i++) { QueryConfigService.MethodAuthorizer.Parameter param = new QueryConfigService.MethodAuthorizer.Parameter(); param.setParameterValue("param" + i); params.add(param); } methodAuthorizer.setParameters(params); queryConfigService.setMethodAuthorizer(methodAuthorizer); ResultModel result = new ResultModel(); command.addMethodAuthorizerToResultModel(queryConfigService, result); assertThat(result.getDataSection(QUERY_SERVICE_DATA_SECTION)).isNotNull(); assertThat(result.getDataSection(QUERY_SERVICE_DATA_SECTION).getContent().size()) .isEqualTo(1); assertThat(result.getDataSection(QUERY_SERVICE_DATA_SECTION).getContent()) .containsValue(methodAuthClassName); }