AMBARI-21366. Create property descriptions for internal Log Search configs (oleewere)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b5e40f9b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b5e40f9b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b5e40f9b Branch: refs/heads/feature-branch-AMBARI-21307 Commit: b5e40f9b22b30fdd21911cd7aef7ed2d09846de8 Parents: 979a07b Author: oleewere <oleew...@gmail.com> Authored: Thu Jun 15 15:44:32 2017 +0200 Committer: oleewere <oleew...@gmail.com> Committed: Mon Jul 3 11:31:47 2017 +0200 ---------------------------------------------------------------------- .../api/LogSearchPropertyDescription.java | 59 +++++++++ .../config/zookeeper/LogSearchConfigZK.java | 29 +++++ .../org/apache/ambari/logsearch/LogSearch.java | 11 +- .../ambari/logsearch/common/ApiDocStorage.java | 90 ++++++++++++++ .../logsearch/common/LogSearchConstants.java | 2 + .../logsearch/common/PropertiesHelper.java | 17 --- .../common/PropertyDescriptionStorage.java | 101 +++++++++++++++ .../ambari/logsearch/conf/ApiDocConfig.java | 6 - .../logsearch/conf/ApplicationConfig.java | 4 +- .../ambari/logsearch/conf/AuthPropsConfig.java | 122 +++++++++++++++++++ .../conf/LogSearchHttpHeaderConfig.java | 31 +++++ .../ambari/logsearch/conf/SecurityConfig.java | 1 + .../logsearch/conf/SolrAuditLogPropsConfig.java | 76 ++++++++++++ .../conf/SolrConnectionPropsConfig.java | 28 +++++ .../conf/SolrEventHistoryPropsConfig.java | 56 +++++++-- .../logsearch/conf/SolrKerberosConfig.java | 17 +++ .../conf/SolrServiceLogPropsConfig.java | 38 ++++++ .../ambari/logsearch/doc/DocConstants.java | 4 +- .../ambari/logsearch/manager/InfoManager.java | 59 +++++++++ .../ambari/logsearch/manager/PublicManager.java | 48 -------- .../model/response/PropertyDescriptionData.java | 62 ++++++++++ .../ambari/logsearch/rest/InfoResource.java | 69 +++++++++++ .../ambari/logsearch/rest/PublicResource.java | 48 -------- .../ambari/logsearch/rest/SwaggerResource.java | 56 +++++++++ .../apache/ambari/logsearch/util/SSLUtil.java | 25 ++++ .../LogsearchKRBAuthenticationFilter.java | 69 ++++++++++- ...rchExternalServerAuthenticationProvider.java | 23 +--- .../src/main/resources/default.properties | 2 - .../src/main/resources/logsearch.properties | 3 - ...xternalServerAuthenticationProviderTest.java | 4 + .../src/main/webapp/login.html | 19 ++- .../logsearch/logsearch-https.properties | 4 - 32 files changed, 1011 insertions(+), 172 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-config-api/src/main/java/org/apache/ambari/logsearch/config/api/LogSearchPropertyDescription.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-config-api/src/main/java/org/apache/ambari/logsearch/config/api/LogSearchPropertyDescription.java b/ambari-logsearch/ambari-logsearch-config-api/src/main/java/org/apache/ambari/logsearch/config/api/LogSearchPropertyDescription.java new file mode 100644 index 0000000..330ef5c --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-config-api/src/main/java/org/apache/ambari/logsearch/config/api/LogSearchPropertyDescription.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.config.api; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marker for describe static application level properties (e.g.: logsearch.properties/logfeeder.properties) + * Can be used to generate documentation about the internal configs. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD}) +public @interface LogSearchPropertyDescription { + + /** + * Name of the property inside the application level property file. + */ + String name(); + + /** + * Describe what the property used for. + */ + String description(); + + /** + * An example value for the property. + */ + String[] examples(); + + /** + * Default value of the property, emtpy by default. + */ + String defaultValue() default ""; + + /** + * Name of the property files where the configurations located + */ + String[] sources(); + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-config-zookeeper/src/main/java/org/apache/ambari/logsearch/config/zookeeper/LogSearchConfigZK.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-config-zookeeper/src/main/java/org/apache/ambari/logsearch/config/zookeeper/LogSearchConfigZK.java b/ambari-logsearch/ambari-logsearch-config-zookeeper/src/main/java/org/apache/ambari/logsearch/config/zookeeper/LogSearchConfigZK.java index 26375e1..1926efa 100644 --- a/ambari-logsearch/ambari-logsearch-config-zookeeper/src/main/java/org/apache/ambari/logsearch/config/zookeeper/LogSearchConfigZK.java +++ b/ambari-logsearch/ambari-logsearch-config-zookeeper/src/main/java/org/apache/ambari/logsearch/config/zookeeper/LogSearchConfigZK.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.TreeMap; import org.apache.ambari.logsearch.config.api.LogSearchConfig; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.apache.ambari.logsearch.config.api.model.loglevelfilter.LogLevelFilter; import org.apache.ambari.logsearch.config.api.model.loglevelfilter.LogLevelFilterMap; import org.apache.ambari.logsearch.config.api.model.inputconfig.InputConfig; @@ -68,9 +69,37 @@ public class LogSearchConfigZK implements LogSearchConfig { private static final long WAIT_FOR_ROOT_SLEEP_SECONDS = 10; private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; + @LogSearchPropertyDescription( + name = "cluster.name", + description = "Cluster name for Log Feeder. (added into zk path of the shipper configs)", + examples = {"cl1"}, + sources = {"logfeeder.properties"} + ) private static final String CLUSTER_NAME_PROPERTY = "cluster.name"; + + @LogSearchPropertyDescription( + name = "logsearch.config.zk_connect_string", + description = "ZooKeeper connection string.", + examples = {"localhost1:2181,localhost2:2181/znode"}, + sources = {"logsearch.properties", "logfeeder.properties"} + ) private static final String ZK_CONNECT_STRING_PROPERTY = "logsearch.config.zk_connect_string"; + + @LogSearchPropertyDescription( + name = "logsearch.config.zk_acls", + description = "ZooKeeper ACLs for handling configs. (read & write)", + examples = {"world:anyone:r,sasl:solr:cdrwa,sasl:logsearch:cdrwa"}, + sources = {"logsearch.properties", "logfeeder.properties"}, + defaultValue = "world:anyone:cdrwa" + ) private static final String ZK_ACLS_PROPERTY = "logsearch.config.zk_acls"; + + @LogSearchPropertyDescription( + name = "logsearch.config.zk_root", + description = "ZooKeeper root node where the shippers are stored. (added to the connection string)", + examples = {"/logsearch"}, + sources = {"logsearch.properties", "logfeeder.properties"} + ) private static final String ZK_ROOT_NODE_PROPERTY = "logsearch.config.zk_root"; private Map<String, String> properties; http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java index 45281b6..b1517df 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java @@ -26,6 +26,7 @@ import java.util.EnumSet; import org.apache.ambari.logsearch.common.ManageStartEndTime; import org.apache.ambari.logsearch.common.PropertiesHelper; import org.apache.ambari.logsearch.conf.ApplicationConfig; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.apache.ambari.logsearch.util.SSLUtil; import org.apache.ambari.logsearch.util.WebUtil; import org.apache.ambari.logsearch.web.listener.LogSearchSessionListener; @@ -55,11 +56,19 @@ import org.springframework.web.filter.DelegatingFilterProxy; import javax.servlet.DispatcherType; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_SESSION_ID; public class LogSearch { private static final Logger LOG = LoggerFactory.getLogger(LogSearch.class); + @LogSearchPropertyDescription( + name = "logsearch.protocol", + description = "Log Search Protocol (http or https)", + examples = {"http", "https"}, + defaultValue = "http", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String LOGSEARCH_PROTOCOL_PROP = "logsearch.protocol"; private static final String HTTPS_PROTOCOL = "https"; private static final String HTTP_PROTOCOL = "http"; @@ -149,7 +158,7 @@ public class LogSearch { // Configure Jersey ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/api/v1/*"); jerseyServlet.setInitOrder(1); - jerseyServlet.setInitParameter("jersey.config.server.provider.packages","org.apache.ambari.logsearch.rest,io.swagger.jaxrs.listing"); + jerseyServlet.setInitParameter("jersey.config.server.provider.packages","org.apache.ambari.logsearch.rest"); context.getSessionHandler().getSessionManager().setMaxInactiveInterval(SESSION_TIMEOUT); context.getSessionHandler().getSessionManager().getSessionCookieConfig().setName(LOGSEARCH_SESSION_ID); http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ApiDocStorage.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ApiDocStorage.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ApiDocStorage.java new file mode 100644 index 0000000..d7b8666 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ApiDocStorage.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.common; + +import io.swagger.jaxrs.config.BeanConfig; +import io.swagger.models.Swagger; +import io.swagger.util.Yaml; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Named +public class ApiDocStorage { + + private static final Logger LOG = LoggerFactory.getLogger(ApiDocStorage.class); + + private final Map<String, Object> swaggerMap = new ConcurrentHashMap<>(); + + @Inject + private BeanConfig beanConfig; + + @PostConstruct + private void postConstruct() { + Thread loadApiDocThread = new Thread("load_swagger_api_doc") { + @Override + public void run() { + LOG.info("Start thread to scan REST API doc from endpoints."); + Swagger swagger = beanConfig.getSwagger(); + beanConfig.configure(swagger); + beanConfig.scanAndRead(); + setSwagger(swagger); + try { + if (swagger != null) { + String yaml = Yaml.mapper().writeValueAsString(swagger); + StringBuilder b = new StringBuilder(); + String[] parts = yaml.split("\n"); + for (String part : parts) { + b.append(part); + b.append("\n"); + } + setSwaggerYaml(b.toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + LOG.info("Scanning REST API endpoints and generating docs has been successful."); + } + }; + loadApiDocThread.setDaemon(true); + loadApiDocThread.start(); + } + + public Swagger getSwagger() { + return (Swagger) swaggerMap.get("swaggerObject"); + } + + public void setSwagger(final Swagger swagger) { + swaggerMap.put("swaggerObject", swagger); + } + + public void setSwaggerYaml(final String swaggerYaml) { + swaggerMap.put("swaggerYaml", swaggerYaml); + } + + public String getSwaggerYaml() { + return (String) swaggerMap.get("swaggerYaml"); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java index 3a74918..a018dda 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java @@ -21,6 +21,8 @@ package org.apache.ambari.logsearch.common; public class LogSearchConstants { + public static final String LOGSEARCH_PROPERTIES_FILE = "logsearch.properties"; + public static final String LOGSEARCH_SESSION_ID = "LOGSEARCHSESSIONID"; // Log Levels http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java index a2a7f5e..3505fe2 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java @@ -111,23 +111,6 @@ public class PropertiesHelper extends PropertyPlaceholderConfigurer { return propertiesMap.get(key); } - public static String[] getPropertyStringList(String key) { - if (key == null) { - return null; - } - String value = propertiesMap.get(key); - if (value == null || value.trim().equals("")) { - return new String[0]; - } else { - String[] splitValues = value.split(","); - String[] returnValues = new String[splitValues.length]; - for (int i = 0; i < splitValues.length; i++) { - returnValues[i] = splitValues[i].trim(); - } - return returnValues; - } - } - public static boolean getBooleanProperty(String key, boolean defaultValue) { if (key == null) { return defaultValue; http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertyDescriptionStorage.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertyDescriptionStorage.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertyDescriptionStorage.java new file mode 100644 index 0000000..bb40a91 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertyDescriptionStorage.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.common; + +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; +import org.apache.ambari.logsearch.model.response.PropertyDescriptionData; +import org.reflections.Reflections; +import org.reflections.scanners.FieldAnnotationsScanner; +import org.reflections.scanners.MethodAnnotationsScanner; +import org.springframework.beans.factory.annotation.Value; + +import javax.annotation.PostConstruct; +import javax.inject.Named; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + +@Named +public class PropertyDescriptionStorage { + + private final Map<String, List<PropertyDescriptionData>> propertyDescriptions = new ConcurrentHashMap<>(); + + @Value("#{'${logsearch.doc.scan.prop.packages:org.apache.ambari.logsearch,org.apache.ambari.logfeeder}'.split(',')}") + @LogSearchPropertyDescription( + name = "logsearch.doc.scan.prop.packages", + description = "Comma separated list of packages for scanning @LogSearchPropertyDescription annotations.", + examples = {"org.apache.ambari.logsearch.mypackage"}, + defaultValue = "org.apache.ambari.logsearch,org.apache.ambari.logfeeder", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + private List<String> packagesToScan; + + @PostConstruct + public void postConstruct() { + Thread loadPropertyDescriptionsThread = new Thread("load_property_descriptions") { + @Override + public void run() { + fillPropertyDescriptions(); + } + }; + loadPropertyDescriptionsThread.setDaemon(true); + loadPropertyDescriptionsThread.start(); + } + + public Map<String, List<PropertyDescriptionData>> getPropertyDescriptions() { + return propertyDescriptions; + } + + private void fillPropertyDescriptions() { + List<PropertyDescriptionData> propertyDescriptionsList = getPropertyDescriptions(packagesToScan); + Map<String, List<PropertyDescriptionData>> mapToAdd = propertyDescriptionsList.stream() + .sorted((o1, o2) -> o1.getName().compareTo(o2.getName())) + .collect(Collectors.groupingBy(PropertyDescriptionData::getSource)); + propertyDescriptions.putAll(mapToAdd); + } + + private List<PropertyDescriptionData> getPropertyDescriptions(List<String> packagesToScan) { + List<PropertyDescriptionData> result = new ArrayList<>(); + for (String packageToScan : packagesToScan) { + Reflections reflections = new Reflections(packageToScan, new FieldAnnotationsScanner(), new MethodAnnotationsScanner()); + Set<Field> fields = reflections.getFieldsAnnotatedWith(LogSearchPropertyDescription.class); + for (Field field : fields) { + LogSearchPropertyDescription propDescription = field.getAnnotation(LogSearchPropertyDescription.class); + for (String source : propDescription.sources()) { + result.add(new PropertyDescriptionData(propDescription.name(), propDescription.description(), propDescription.examples(), propDescription.defaultValue(), source)); + } + } + Set<Method> methods = reflections.getMethodsAnnotatedWith(LogSearchPropertyDescription.class); + for (Method method : methods) { + LogSearchPropertyDescription propDescription = method.getAnnotation(LogSearchPropertyDescription.class); + for (String source : propDescription.sources()) { + result.add(new PropertyDescriptionData(propDescription.name(), propDescription.description(), propDescription.examples(), propDescription.defaultValue(), source)); + } + } + } + return result; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java index 9d4e96e..1e61f22 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java @@ -19,7 +19,6 @@ package org.apache.ambari.logsearch.conf; import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; import io.swagger.jaxrs.listing.SwaggerSerializers; import io.swagger.models.Info; @@ -39,11 +38,6 @@ public class ApiDocConfig { private static final String BASE_PATH = "/api/v1"; @Bean - public ApiListingResource apiListingResource() { - return new ApiListingResource(); - } - - @Bean public SwaggerSerializers swaggerSerializers() { return new SwaggerSerializers(); } http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java index 82a09b2..756252d 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java @@ -29,9 +29,11 @@ import org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean; import java.io.IOException; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + @Configuration @ComponentScan("org.apache.ambari.logsearch") -@PropertySource(value = {"classpath:default.properties", "classpath:logsearch.properties"}) +@PropertySource(value = {"classpath:default.properties", "classpath:"+ LOGSEARCH_PROPERTIES_FILE}) public class ApplicationConfig { @Bean http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java index 54cc10c..2bcdebc 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java @@ -18,41 +18,155 @@ */ package org.apache.ambari.logsearch.conf; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import java.util.List; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + @Configuration public class AuthPropsConfig { @Value("${logsearch.auth.file.enabled:true}") + @LogSearchPropertyDescription( + name = "logsearch.auth.file.enabled", + description = "Enable file based authentication (in json file at logsearch configuration folder).", + examples = {"true", "false"}, + defaultValue = "true", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) boolean authFileEnabled; + @Value("${logsearch.auth.ldap.enabled:false}") + @LogSearchPropertyDescription( + name = "logsearch.auth.ldap.enabled", + description = "Enable LDAP based authentication (currenty not supported).", + examples = {"true", "false"}, + defaultValue = "false", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) boolean authLdapEnabled; + @Value("${logsearch.auth.simple.enabled:false}") + @LogSearchPropertyDescription( + name = "logsearch.auth.simple.enabled", + description = "Enable simple authentication. That means you won't require password to log in.", + examples = {"true", "false"}, + defaultValue = "false", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) boolean authSimpleEnabled; + @Value("${logsearch.auth.external_auth.enabled:false}") + @LogSearchPropertyDescription( + name = "logsearch.auth.external_auth.enabled", + description = "Enable external authentication (currently Ambari acts as an external authentication server).", + examples = {"true", "false"}, + defaultValue = "false", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) boolean authExternalEnabled; + @Value("${logsearch.auth.external_auth.host_url:'http://ip:port'}") + @LogSearchPropertyDescription( + name = "logsearch.auth.external_auth.host_url", + description = "External authentication server URL (host and port).", + examples = {"https://c6401.ambari.apache.org:8080"}, + defaultValue = "http://ip:port", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String externalAuthHostUrl; + @Value("${logsearch.auth.external_auth.login_url:/api/v1/users/$USERNAME/privileges?fields=*}") + @LogSearchPropertyDescription( + name = "logsearch.auth.external_auth.login_url", + description = "Login URL for external authentication server ($USERNAME parameter is replaced with the Login username).", + examples = {"/api/v1/users/$USERNAME/privileges?fields=*"}, + defaultValue = "/api/v1/users/$USERNAME/privileges?fields=*", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String externalAuthLoginUrl; + @Value("${logsearch.login.credentials.file:user_pass.json}") + @LogSearchPropertyDescription( + name = "logsearch.login.credentials.file", + description = "Name of the credential file which contains the users for file authentication (see: logsearch.auth.file.enabled).", + examples = {"logsearch-admin.json"}, + defaultValue = "user_pass.json", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String credentialsFile; + @Value("${logsearch.auth.jwt.enabled:false}") + @LogSearchPropertyDescription( + name = "logsearch.auth.jwt.enabled", + description = "Enable JWT based authentication (e.g.: for KNOX).", + examples = {"true", "false"}, + defaultValue = "false", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private boolean authJwtEnabled; @Value("${logsearch.auth.jwt.provider_url:}") + @LogSearchPropertyDescription( + name = "logsearch.auth.jwt.provider_url", + description = "URL to the JWT authentication server.", + examples = {"https://c6401.ambari.apache.org:8443/mypath"}, + defaultValue = "", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String providedUrl; + @Value("${logsearch.auth.jwt.public_key:}") + @LogSearchPropertyDescription( + name = "logsearch.auth.jwt.public_key", + description = "PEM formatted public key for JWT token without the header and the footer.", + examples = {"MIGfMA0GCSqGSIb3DQEBA..."}, + defaultValue = "", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String publicKey; + @Value("${logsearch.auth.jwt.cookie.name:hadoop-jwt}") + @LogSearchPropertyDescription( + name = "logsearch.auth.jwt.cookie.name", + description = "The name of the cookie that contains the JWT token.", + examples = {"hadoop-jwt"}, + defaultValue = "hadoop-jwt", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String cookieName; @Value("${logsearch.auth.jwt.query.param.original_url:originalUrl=}") + @LogSearchPropertyDescription( + name = "logsearch.auth.jwt.query.param.original_url", + description = "Name of the original request URL which is used to redirect to Log Search Portal.", + examples = {"myUrl"}, + defaultValue = "originalUrl", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String originalUrlQueryParam; + @Value("#{'${logsearch.auth.jwt.audiances:}'.split(',')}") + @LogSearchPropertyDescription( + name = "logsearch.auth.jwt.audiances", + description = "Comma separated list of acceptable audiences for the JWT token.", + examples = {"audiance1,audiance2"}, + defaultValue = "", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private List<String> audiences; + @Value("#{'${logsearch.roles.allowed:AMBARI.ADMINISTRATOR,CLUSTER.ADMINISTRATOR}'.split(',')}") + @LogSearchPropertyDescription( + name = "logsearch.roles.allowed", + description = "Comma separated roles for external authentication.", + examples = {"AMBARI.ADMINISTRATOR"}, + defaultValue = "AMBARI.ADMINISTRATOR,CLUSTER.ADMINISTRATOR", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + private List<String> allowedRoles; + public boolean isAuthFileEnabled() { return authFileEnabled; } @@ -156,4 +270,12 @@ public class AuthPropsConfig { public void setAudiences(List<String> audiences) { this.audiences = audiences; } + + public List<String> getAllowedRoles() { + return allowedRoles; + } + + public void setAllowedRoles(List<String> allowedRoles) { + this.allowedRoles = allowedRoles; + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java index cb8c097..8d4f760 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java @@ -18,22 +18,53 @@ */ package org.apache.ambari.logsearch.conf; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + @Configuration public class LogSearchHttpHeaderConfig { @Value("${logsearch.http.header.access-control-allow-origin:*}") + @LogSearchPropertyDescription( + name = "logsearch.http.header.access-control-allow-origin", + description = "Access-Control-Allow-Origin header for Log Search Server.", + examples = {"*", "http://c6401.ambari.apache.org"}, + defaultValue = "*", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String accessControlAllowOrigin; @Value("${logsearch.http.header.access-control-allow-headers:origin, content-type, accept, authorization}") + @LogSearchPropertyDescription( + name = "logsearch.http.header.access-control-allow-headers", + description = "Access-Control-Allow-Headers header for Log Search Server.", + examples = {"content-type, authorization"}, + defaultValue = "origin, content-type, accept, authorization", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String accessControlAllowHeaders; @Value("${logsearch.http.header.access-control-allow-credentials:true}") + @LogSearchPropertyDescription( + name = "logsearch.http.header.access-control-allow-credentials", + description = "Access-Control-Allow-Credentials header for Log Search Server.", + examples = {"true", "false"}, + defaultValue = "true", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String accessControlAllowCredentials; @Value("${logsearch.http.header.access-control-allow-methods:GET, POST, PUT, DELETE, OPTIONS, HEAD}") + @LogSearchPropertyDescription( + name = "logsearch.http.header.access-control-allow-methods", + description = "Access-Control-Allow-Methods header for Log Search Server.", + examples = {"GET, POST"}, + defaultValue = "GET, POST, PUT, DELETE, OPTIONS, HEAD", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String accessControlAllowMethods; public String getAccessControlAllowOrigin() { http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java index 441b628..5207dd0 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java @@ -199,6 +199,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { matchers.add(new AntPathRequestMatcher("/templates/**")); matchers.add(new AntPathRequestMatcher("/images/**")); matchers.add(new AntPathRequestMatcher("/favicon.ico")); + matchers.add(new AntPathRequestMatcher("/api/v1/info/**")); matchers.add(new AntPathRequestMatcher("/api/v1/public/**")); matchers.add(new AntPathRequestMatcher("/api/v1/swagger.json")); matchers.add(new AntPathRequestMatcher("/api/v1/swagger.yaml")); http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java index 5981bcc..c569a27 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java @@ -18,46 +18,122 @@ */ package org.apache.ambari.logsearch.conf; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.apache.zookeeper.data.ACL; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import java.util.List; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + @Configuration public class SolrAuditLogPropsConfig implements SolrPropsConfig { @Value("${logsearch.solr.audit.logs.url:}") + @LogSearchPropertyDescription( + name = "logsearch.solr.audit.logs.url", + description = "URL of Solr (non cloud mode) - currently unsupported.", + examples = {"localhost1:8868"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String solrUrl; @Value("${logsearch.solr.audit.logs.zk_connect_string:}") + @LogSearchPropertyDescription( + name = "logsearch.solr.audit.logs.zk_connect_string", + description = "Zookeeper connection string for Solr (used for audit log collection).", + examples = {"localhost1:2181,localhost2:2181/mysolr_znode"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String zkConnectString; @Value("${logsearch.solr.collection.audit.logs:audit_logs}") + @LogSearchPropertyDescription( + name = "logsearch.solr.collection.audit.logs", + description = "Name of Log Search audit collection.", + examples = {"audit_logs"}, + defaultValue = "audit_logs", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String collection; @Value("${logsearch.ranger.audit.logs.collection.name:}") + @LogSearchPropertyDescription( + name = "logsearch.ranger.audit.logs.collection.name", + description = "Name of Ranger audit collections (can be used if ranger audits managed by the same Solr which is used for Log Search).", + examples = {"ranger_audits"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String rangerCollection; @Value("${logsearch.solr.audit.logs.config.name:audit_logs}") + @LogSearchPropertyDescription( + name = "logsearch.solr.audit.logs.config.name", + description = "Solr configuration name of the audit collection.", + examples = {"audit_logs"}, + defaultValue = "audit_logs", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String configName; @Value("${logsearch.solr.audit.logs.alias.name:audit_logs_alias}") + @LogSearchPropertyDescription( + name = "logsearch.solr.audit.logs.alias.name", + description = "Alias name for audit log collection (can be used for Log Search audit collection and ranger collection as well).", + examples = {"audit_logs_alias"}, + defaultValue = "audit_logs_alias", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String aliasNameIn; @Value("${logsearch.audit.logs.split.interval.mins:none}") + @LogSearchPropertyDescription( + name = "logsearch.audit.logs.split.interval.mins", + description = "Will create multiple collections and use alias. (not supported right now, use implicit routingif the value is not none)", + examples = {"none", "15"}, + defaultValue = "none", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String splitInterval; @Value("${logsearch.collection.audit.logs.numshards:1}") + @LogSearchPropertyDescription( + name = "logsearch.collection.audit.logs.numshards", + description = "Number of Solr shards for audit collection (bootstrapping).", + examples = {"2"}, + defaultValue = "1", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private Integer numberOfShards; @Value("${logsearch.collection.audit.logs.replication.factor:1}") + @LogSearchPropertyDescription( + name = "logsearch.collection.audit.logs.replication.factor", + description = "Solr replication factor for audit collection (bootstrapping).", + examples = {"2"}, + defaultValue = "1", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private Integer replicationFactor; @Value("#{ACLPropertiesSplitter.parseAcls('${logsearch.solr.audit.logs.zk.acls:}')}") + @LogSearchPropertyDescription( + name = "logsearch.solr.audit.logs.zk.acls", + description = "List of Zookeeper ACLs for Log Search audit collection (Log Search and Solr must be able to read/write collection details)", + examples = {"world:anyone:r,sasl:solr:cdrwa,sasl:logsearch:cdrwa"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private List<ACL> zkAcls; @Value("${logsearch.solr.audit.logs.config_set.folder:/etc/ambari-logsearch-portal/conf/solr_configsets}") + @LogSearchPropertyDescription( + name = "logsearch.solr.audit.logs.config_set.folder", + description = "Location of Log Search audit collection configs for Solr.", + examples = {"/etc/ambari-logsearch-portal/conf/solr_configsets"}, + defaultValue = "/etc/ambari-logsearch-portal/conf/solr_configsets", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String configSetFolder; @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java index 7d37efd..af47a17 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java @@ -18,22 +18,50 @@ */ package org.apache.ambari.logsearch.conf; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.apache.zookeeper.data.ACL; import org.springframework.beans.factory.annotation.Value; import java.util.List; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + public abstract class SolrConnectionPropsConfig implements SolrPropsConfig { @Value("${logsearch.solr.url:}") + @LogSearchPropertyDescription( + name = "logsearch.solr.url", + description = "URL of Solr (non cloud mode) - currently unsupported.", + examples = {"localhost1:8868"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String solrUrl; @Value("${logsearch.solr.zk_connect_string:}") + @LogSearchPropertyDescription( + name = "logsearch.solr.zk_connect_string", + description = "Zookeeper connection string for Solr.", + examples = {"localhost1:2181,localhost2:2181/mysolr_znode"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String zkConnectString; @Value("#{ACLPropertiesSplitter.parseAcls('${logsearch.solr.zk.acls:}')}") + @LogSearchPropertyDescription( + name = "logsearch.solr.zk.acls", + description = "List of Zookeeper ACLs for Log Search Collections (Log Search and Solr must be able to read/write collection details)", + examples = {"world:anyone:r,sasl:solr:cdrwa,sasl:logsearch:cdrwa"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private List<ACL> zkAcls; @Value("${logsearch.solr.config_set.folder:/etc/ambari-logsearch-portal/conf/solr_configsets}") + @LogSearchPropertyDescription( + name = "logsearch.solr.config_set.folder", + description = "Location of Solr collection configs.", + examples = {"/etc/ambari-logsearch-portal/conf/solr_configsets"}, + defaultValue = "/etc/ambari-logsearch-portal/conf/solr_configsets", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String configSetFolder; @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrEventHistoryPropsConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrEventHistoryPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrEventHistoryPropsConfig.java index a117501..975e6a7 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrEventHistoryPropsConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrEventHistoryPropsConfig.java @@ -18,33 +18,73 @@ */ package org.apache.ambari.logsearch.conf; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -import java.util.List; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; @Configuration public class SolrEventHistoryPropsConfig extends SolrConnectionPropsConfig { @Value("${logsearch.solr.collection.history:history}") + @LogSearchPropertyDescription( + name = "logsearch.solr.collection.history", + description = "Name of Log Search event history collection.", + examples = {"history"}, + defaultValue = "history", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String collection; @Value("${logsearch.history.split.interval.mins:none}") + @LogSearchPropertyDescription( + name = "logsearch.history.split.interval.mins", + description = "Will create multiple collections and use alias. (not supported right now, use implicit routingif the value is not none)", + examples = {"none", "15"}, + defaultValue = "none", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String splitInterval; @Value("${logsearch.solr.history.config.name:history}") + @LogSearchPropertyDescription( + name = "logsearch.solr.history.config.name", + description = "Solr configuration name of the event history collection.", + examples = {"history"}, + defaultValue = "history", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String configName; @Value("${logsearch.collection.history.numshards:1}") + @LogSearchPropertyDescription( + name = "logsearch.collection.history.numshards", + description = "Number of Solr shards for event history collection (bootstrapping).", + examples = {"2"}, + defaultValue = "1", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private Integer numberOfShards; @Value("${logsearch.collection.history.replication.factor:2}") + @LogSearchPropertyDescription( + name = "logsearch.collection.history.replication.factor", + description = "Solr replication factor for event history collection (bootstrapping).", + examples = {"3"}, + defaultValue = "2", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private Integer replicationFactor; - @Value("#{'${logsearch.logfeeder.include.default.level:FATAL,ERROR,WARN,INFO,DEBUG,TRACE,UNKNOWN}'.split(',')}") - private List<String> logLevels; - @Value("${logsearch.schema.fields.populate.interval.mins:1}") + @LogSearchPropertyDescription( + name = "logsearch.schema.fields.populate.interval.mins", + description = "Interval in minutes for populating schema fiels for event history collections.", + examples = {"10"}, + defaultValue = "1", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private Integer populateIntervalMins; @Override @@ -96,14 +136,6 @@ public class SolrEventHistoryPropsConfig extends SolrConnectionPropsConfig { public void setReplicationFactor(Integer replicationFactor) { this.replicationFactor = replicationFactor; } - - public List<String> getLogLevels() { - return logLevels; - } - - public void setLogLevels(List<String> logLevels) { - this.logLevels = logLevels; - } public Integer getPopulateIntervalMins() { http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java index 7cf79b0..5140d28 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java @@ -18,16 +18,33 @@ */ package org.apache.ambari.logsearch.conf; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + @Configuration public class SolrKerberosConfig { @Value("${logsearch.solr.jaas.file:/usr/lib/ambari-logsearch-portal/logsearch_solr_jaas.conf}") + @LogSearchPropertyDescription( + name = "logsearch.solr.jaas.file", + description = "Path of the JAAS file for Kerberos based Solr Cloud authentication.", + examples = {"/my/path/jaas_file.conf"}, + defaultValue = "/usr/lib/ambari-logsearch-portal/logsearch_solr_jaas.conf", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String jaasFile; @Value("${logsearch.solr.kerberos.enable:false}") + @LogSearchPropertyDescription( + name = "logsearch.solr.kerberos.enable", + description = "Enable Kerberos Authentication for Solr Cloud.", + examples = {"true", "false"}, + defaultValue = "false", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private boolean enabled; public String getJaasFile() { http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrServiceLogPropsConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrServiceLogPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrServiceLogPropsConfig.java index 482438a..e5039d5 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrServiceLogPropsConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrServiceLogPropsConfig.java @@ -18,25 +18,63 @@ */ package org.apache.ambari.logsearch.conf; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + @Configuration public class SolrServiceLogPropsConfig extends SolrConnectionPropsConfig { @Value("${logsearch.solr.collection.service.logs:hadoop_logs}") + @LogSearchPropertyDescription( + name = "logsearch.solr.collection.service.logs", + description = "Name of Log Search service log collection.", + examples = {"hadoop_logs"}, + defaultValue = "hadoop_logs", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String collection; @Value("${logsearch.service.logs.split.interval.mins:none}") + @LogSearchPropertyDescription( + name = "logsearch.service.logs.split.interval.mins", + description = "Will create multiple collections and use alias. (not supported right now, use implicit routingif the value is not none)", + examples = {"none", "15"}, + defaultValue = "none", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String splitInterval; @Value("${logsearch.solr.service.logs.config.name:hadoop_logs}") + @LogSearchPropertyDescription( + name = "logsearch.solr.service.logs.config.name", + description = "Solr configuration name of the service log collection.", + examples = {"hadoop_logs"}, + defaultValue = "hadoop_logs", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private String configName; @Value("${logsearch.collection.service.logs.numshards:1}") + @LogSearchPropertyDescription( + name = "logsearch.collection.service.logs.numshards", + description = "Number of Solr shards for service log collection (bootstrapping).", + examples = {"2"}, + defaultValue = "1", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private Integer numberOfShards; @Value("${logsearch.collection.service.logs.replication.factor:1}") + @LogSearchPropertyDescription( + name = "logsearch.collection.service.logs.replication.factor", + description = "Solr replication factor for service log collection (bootstrapping).", + examples = {"2"}, + defaultValue = "1", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private Integer replicationFactor; @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java index 73de0ee..6d1382d 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java @@ -101,7 +101,9 @@ public class DocConstants { } public class PublicOperationDescriptions { - public static final String OBTAIN_GENERAL_CONFIG_OD = "Obtain general config"; + public static final String GET_AUTH_DETAILS_OD = "Get authentication details."; + public static final String GET_ALL_PROPERTIES_INFO_OD = "List all available properties for Log Search and Log Feeder"; + public static final String GET_LOGSEARCH_PROPERTIES_INFO_OD = "List all available properties for Log Search property file (e.g: logsearch.properties/logfeeder.properties)"; } public class EventHistoryDescriptions { http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java new file mode 100644 index 0000000..f6d0449 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ambari.logsearch.manager; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.ambari.logsearch.conf.AuthPropsConfig; +import org.apache.ambari.logsearch.common.PropertyDescriptionStorage; +import org.apache.ambari.logsearch.model.response.PropertyDescriptionData; + +import javax.inject.Inject; +import javax.inject.Named; + +@Named +public class InfoManager extends JsonManagerBase { + + @Inject + private AuthPropsConfig authPropsConfig; + + @Inject + private PropertyDescriptionStorage propertyDescriptionStore; + + public Map<String, Boolean> getAuthMap() { + Map<String, Boolean> authMap = new HashMap<>(); + authMap.put("external", authPropsConfig.isAuthExternalEnabled()); + authMap.put("file", authPropsConfig.isAuthFileEnabled()); + authMap.put("jwt", authPropsConfig.isAuthJwtEnabled()); + authMap.put("ldap", authPropsConfig.isAuthLdapEnabled()); + authMap.put("simple", authPropsConfig.isAuthSimpleEnabled()); + return authMap; + } + + public Map<String, List<PropertyDescriptionData>> getPropertyDescriptions() { + return propertyDescriptionStore.getPropertyDescriptions(); + } + + public List<PropertyDescriptionData> getLogSearchPropertyDescriptions(String propertiesFile) { + return getPropertyDescriptions().get(propertiesFile); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/PublicManager.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/PublicManager.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/PublicManager.java deleted file mode 100644 index cbab651..0000000 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/PublicManager.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.ambari.logsearch.manager; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.ambari.logsearch.conf.AuthPropsConfig; -import org.apache.ambari.logsearch.model.response.NameValueData; -import org.apache.ambari.logsearch.model.response.NameValueDataListResponse; - -import javax.inject.Inject; -import javax.inject.Named; - -@Named -public class PublicManager extends JsonManagerBase { - - @Inject - private AuthPropsConfig authPropsConfig; - - public String getGeneralConfig() { - NameValueDataListResponse nameValueList = new NameValueDataListResponse(); - List<NameValueData> nameValues = new ArrayList<>(); - NameValueData nameValue = new NameValueData(); - nameValue.setName("simpleAuth"); - nameValue.setValue("" + authPropsConfig.isAuthSimpleEnabled()); - nameValues.add(nameValue); - nameValueList.setvNameValues(nameValues); - return convertObjToString(nameValueList); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/PropertyDescriptionData.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/PropertyDescriptionData.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/PropertyDescriptionData.java new file mode 100644 index 0000000..6da8403 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/PropertyDescriptionData.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.model.response; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class PropertyDescriptionData { + private final String name; + + private final String description; + + private final String[] examples; + + private final String defaultValue; + + @JsonIgnore + private final String source; + + public PropertyDescriptionData(String name, String description, String[] examples, String defaultValue, String source) { + this.name = name; + this.description = description; + this.examples = examples; + this.defaultValue = defaultValue; + this.source = source; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String[] getExamples() { + return examples; + } + + public String getDefaultValue() { + return defaultValue; + } + + public String getSource() { + return source; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java new file mode 100644 index 0000000..f085678 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.rest; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.ambari.logsearch.manager.InfoManager; +import org.apache.ambari.logsearch.model.response.PropertyDescriptionData; +import org.springframework.context.annotation.Scope; + +import java.util.List; +import java.util.Map; + +import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_ALL_PROPERTIES_INFO_OD; +import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_LOGSEARCH_PROPERTIES_INFO_OD; +import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_AUTH_DETAILS_OD; + +@Api(value = "info", description = "General configuration information") +@Path("info") +@Named +@Scope("request") +public class InfoResource { + + @Inject + private InfoManager infoManager; + + @GET + @Path("/auth") + @ApiOperation(GET_AUTH_DETAILS_OD) + public Map<String, Boolean> getAuthInfo() { + return infoManager.getAuthMap(); + } + + @GET + @Path("/properties") + @ApiOperation(GET_ALL_PROPERTIES_INFO_OD) + public Map<String, List<PropertyDescriptionData>> getPropertyDescriptions() { + return infoManager.getPropertyDescriptions(); + } + + @GET + @Path("/properties/{propertyFile}") + @ApiOperation(GET_LOGSEARCH_PROPERTIES_INFO_OD) + public List<PropertyDescriptionData> getPropertyFileDescription(@PathParam("propertyFile") String propertyFile) { + return infoManager.getLogSearchPropertyDescriptions(propertyFile); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/PublicResource.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/PublicResource.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/PublicResource.java deleted file mode 100644 index df83d44..0000000 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/PublicResource.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.ambari.logsearch.rest; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.apache.ambari.logsearch.manager.PublicManager; -import org.springframework.context.annotation.Scope; - -import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.OBTAIN_GENERAL_CONFIG_OD; - -@Api(value = "public", description = "Public operations") -@Path("public") -@Named -@Scope("request") -public class PublicResource { - - @Inject - private PublicManager publicManager; - - @GET - @Path("/config") - @ApiOperation(OBTAIN_GENERAL_CONFIG_OD) - public String getGeneralConfig() { - return publicManager.getGeneralConfig(); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/SwaggerResource.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/SwaggerResource.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/SwaggerResource.java new file mode 100644 index 0000000..36dc5bd --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/SwaggerResource.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.rest; + +import io.swagger.annotations.ApiOperation; +import org.apache.ambari.logsearch.common.ApiDocStorage; +import org.springframework.context.annotation.Scope; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Path("swagger.{type:json|yaml}") +@Named +@Scope("request") +public class SwaggerResource { + + @Inject + private ApiDocStorage apiDocStorage; + + @GET + @Produces({MediaType.APPLICATION_JSON, "application/yaml"}) + @ApiOperation(value = "The swagger definition in either JSON or YAML", hidden = true) + public Response swaggerDefinitionResponse(@PathParam("type") String type) { + Response response = Response.status(404).build(); + if (apiDocStorage.getSwagger() != null) { + if ("yaml".equalsIgnoreCase(type)) { + response = Response.ok().entity(apiDocStorage.getSwaggerYaml()).type("application/yaml").build(); + } else { + response = Response.ok().entity(apiDocStorage.getSwagger()).build(); + } + } + return response; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/util/SSLUtil.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/util/SSLUtil.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/util/SSLUtil.java index d4b6544..b0b893f 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/util/SSLUtil.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/util/SSLUtil.java @@ -22,6 +22,7 @@ package org.apache.ambari.logsearch.util; import javax.net.ssl.SSLContext; import org.apache.ambari.logsearch.common.PropertiesHelper; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ArrayUtils; @@ -68,6 +69,8 @@ import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.util.Date; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + public class SSLUtil { private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class); @@ -83,9 +86,31 @@ public class SSLUtil { private static final String TRUSTSTORE_PASSWORD_PROPERTY_NAME = "logsearch_truststore_password"; private static final String KEYSTORE_PASSWORD_FILE = "ks_pass.txt"; private static final String TRUSTSTORE_PASSWORD_FILE = "ts_pass.txt"; + + @LogSearchPropertyDescription( + name = "hadoop.security.credential.provider.path", + description = "Path to interrogate for protected credentials. (see: https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/CredentialProviderAPI.html)", + examples = {"localjceks://file/home/mypath/my.jceks"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String CREDENTIAL_STORE_PROVIDER_PATH = "hadoop.security.credential.provider.path"; + @LogSearchPropertyDescription( + name = "logsearch.cert.folder.location", + description = "Folder where the generated certificates (SSL) will be located. Make sure the user of Log Search Server can access it.", + examples = {"/etc/mypath/keys"}, + defaultValue = "/etc/ambari-logsearch-portal/conf/keys", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String LOGSEARCH_CERT_FOLDER_LOCATION = "logsearch.cert.folder.location"; + + @LogSearchPropertyDescription( + name = "logsearch.cert.algorithm", + description = "Algorithm to generate certificates for SSL (if needed).", + examples = {"sha256WithRSA"}, + defaultValue = "sha256WithRSA", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String LOGSEARCH_CERT_ALGORITHM = "logsearch.cert.algorithm"; private static final String LOGSEARCH_CERT_FILENAME = "logsearch.crt"; http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchKRBAuthenticationFilter.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchKRBAuthenticationFilter.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchKRBAuthenticationFilter.java index 1b77753..ec3075c 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchKRBAuthenticationFilter.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchKRBAuthenticationFilter.java @@ -40,6 +40,7 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.authentication.AbstractAuthenticationToken; @@ -62,18 +63,84 @@ import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHand import org.apache.hadoop.security.authentication.util.KerberosName; import org.springframework.security.web.authentication.WebAuthenticationDetails; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + public class LogsearchKRBAuthenticationFilter extends LogsearchKrbFilter { private static final Logger logger = LoggerFactory.getLogger(LogsearchKRBAuthenticationFilter.class); - private static final String NAME_RULES = "hadoop.security.auth_to_local"; + @LogSearchPropertyDescription( + name = "logsearch.hadoop.security.auth_to_local", + description = "Rules that will be applied on authentication names and map them into local usernames.", + examples = {"RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//", "DEFAULT"}, + defaultValue = "DEFAULT", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + private static final String NAME_RULES = "logsearch.hadoop.security.auth_to_local"; + + @LogSearchPropertyDescription( + name = "logsearch.admin.kerberos.token.valid.seconds", + description = "Kerberos token validity in seconds.", + examples = {"30"}, + defaultValue = "30", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String TOKEN_VALID = "logsearch.admin.kerberos.token.valid.seconds"; + + @LogSearchPropertyDescription( + name = "logsearch.admin.kerberos.cookie.domain", + description = "Domain for Kerberos cookie.", + examples = {"c6401.ambari.apache.org", "localhost"}, + defaultValue = "localhost", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String COOKIE_DOMAIN = "logsearch.admin.kerberos.cookie.domain"; + + @LogSearchPropertyDescription( + name = "logsearch.admin.kerberos.cookie.path", + description = "Cookie path of the kerberos cookie", + examples = {"/"}, + defaultValue = "/", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String COOKIE_PATH = "logsearch.admin.kerberos.cookie.path"; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.principal", + description = "Principal for SPNEGO authentication for Http requests", + examples = {"myu...@example.com"}, + defaultValue = "", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String PRINCIPAL = "logsearch.spnego.kerberos.principal"; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.keytab", + description = "Keytab for SPNEGO authentication for Http requests.", + examples = {"/etc/security/keytabs/mykeytab.keytab"}, + defaultValue = "", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String KEYTAB = "logsearch.spnego.kerberos.keytab"; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.host", + description = "", + examples = {"c6401.ambari.apache.org", "localhost"}, + defaultValue = "localhost", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String HOST_NAME = "logsearch.spnego.kerberos.host"; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.enabled", + description = "Enable SPNEGO based authentication for Log Search Server.", + examples = {"true", "false"}, + defaultValue = "false", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) private static final String KERBEROS_ENABLED = "logsearch.spnego.kerberos.enabled"; + private static final String NAME_RULES_PARAM = "kerberos.name.rules"; private static final String TOKEN_VALID_PARAM = "token.validity"; private static final String COOKIE_DOMAIN_PARAM = "cookie.domain"; http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java index 1dab126..4449da1 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java @@ -25,7 +25,6 @@ import javax.inject.Inject; import javax.inject.Named; import org.apache.ambari.logsearch.common.ExternalServerClient; -import org.apache.ambari.logsearch.common.PropertiesHelper; import org.apache.ambari.logsearch.conf.AuthPropsConfig; import org.apache.ambari.logsearch.util.JSONUtil; import org.apache.commons.lang.StringEscapeUtils; @@ -46,8 +45,6 @@ public class LogsearchExternalServerAuthenticationProvider extends LogsearchAbst private static Logger LOG = Logger.getLogger(LogsearchExternalServerAuthenticationProvider.class); - private static final String ALLOWED_ROLE_PROP = "logsearch.roles.allowed"; - private static enum PrivilegeInfo { PERMISSION_LABEL("permission_label"), PERMISSION_NAME("permission_name"), @@ -118,23 +115,13 @@ public class LogsearchExternalServerAuthenticationProvider extends LogsearchAbst * Return true/false based on PEMISSION NAME return boolean */ private boolean isAllowedRole(String responseJson) { - String allowedRoleList[] = PropertiesHelper.getPropertyStringList(ALLOWED_ROLE_PROP); - List<String> values = new ArrayList<>(); - JSONUtil.getValuesOfKey(responseJson, PrivilegeInfo.PERMISSION_NAME.toString(), values); - if (values.isEmpty()) { + List<String> permissionNames = new ArrayList<>(); + JSONUtil.getValuesOfKey(responseJson, PrivilegeInfo.PERMISSION_NAME.toString(), permissionNames); + List<String> allowedRoleList = authPropsConfig.getAllowedRoles(); + if (permissionNames.isEmpty() || allowedRoleList.size() < 1 || responseJson == null) { return false; } - - if (allowedRoleList.length > 0 && responseJson != null) { - for (String allowedRole : allowedRoleList) { - for (String role : values) { - if (role.equals(allowedRole)) { - return true; - } - } - } - } - return false; + return permissionNames.stream().anyMatch(allowedRoleList::contains); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/resources/default.properties ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/resources/default.properties b/ambari-logsearch/ambari-logsearch-server/src/main/resources/default.properties index cbfe157..cd1f22a 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/resources/default.properties +++ b/ambari-logsearch/ambari-logsearch-server/src/main/resources/default.properties @@ -19,8 +19,6 @@ logsearch.auth.file.enable=true logsearch.auth.ldap.enable=false logsearch.auth.simple.enable=false -logsearch.logfeeder.include.default.level=FATAL,ERROR,WARN,INFO,DEBUG,TRACE - #login config logsearch.login.credentials.file=user_pass.json logsearch.login.ldap.config=logsearch-admin-site.xml http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/main/resources/logsearch.properties ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/resources/logsearch.properties b/ambari-logsearch/ambari-logsearch-server/src/main/resources/logsearch.properties index b6cc4a5..3e59163 100755 --- a/ambari-logsearch/ambari-logsearch-server/src/main/resources/logsearch.properties +++ b/ambari-logsearch/ambari-logsearch-server/src/main/resources/logsearch.properties @@ -34,9 +34,6 @@ logsearch.audit.logs.split.interval.mins=none logsearch.collection.audit.logs.numshards=1 logsearch.collection.audit.logs.replication.factor=1 -#Logfeeder Settings -logsearch.logfeeder.include.default.level=fatal,error,warn - #Authentication settings #Note: Simple will be supported only if file ,ldap and external_auth all three are disabled. logsearch.auth.file.enable=true http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProviderTest.java b/ambari-logsearch/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProviderTest.java index d6247a1..b6464c2 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProviderTest.java +++ b/ambari-logsearch/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProviderTest.java @@ -18,6 +18,7 @@ */ package org.apache.ambari.logsearch.web.security; +import com.google.common.collect.Lists; import org.apache.ambari.logsearch.common.ExternalServerClient; import org.apache.ambari.logsearch.conf.AuthPropsConfig; import org.junit.Before; @@ -36,6 +37,7 @@ import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import java.lang.reflect.Field; +import java.util.Arrays; public class LogsearchExternalServerAuthenticationProviderTest { @@ -147,6 +149,7 @@ public class LogsearchExternalServerAuthenticationProviderTest { public void testAuthenticationUnsuccessful() throws Exception { expect(mockAuthPropsConfig.isAuthExternalEnabled()).andReturn(true); expect(mockAuthPropsConfig.getExternalAuthLoginUrl()).andReturn("http://server.com?userName=$USERNAME"); + expect(mockAuthPropsConfig.getAllowedRoles()).andReturn(Arrays.asList("AMBARI.ADMINISTRATOR")); expect(mockExternalServerClient.sendGETRequest("http://server.com?userName=principal", String.class, "principal", "credentials")) .andReturn("{\"permission_name\": \"NOT.AMBARI.ADMINISTRATOR\" }"); @@ -167,6 +170,7 @@ public class LogsearchExternalServerAuthenticationProviderTest { public void testAuthenticationSuccessful() throws Exception { expect(mockAuthPropsConfig.isAuthExternalEnabled()).andReturn(true); expect(mockAuthPropsConfig.getExternalAuthLoginUrl()).andReturn("http://server.com?userName=$USERNAME"); + expect(mockAuthPropsConfig.getAllowedRoles()).andReturn(Arrays.asList("AMBARI.ADMINISTRATOR")); expect(mockExternalServerClient.sendGETRequest("http://server.com?userName=principal", String.class, "principal", "credentials")) .andReturn("{\"permission_name\": \"AMBARI.ADMINISTRATOR\" }"); http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e40f9b/ambari-logsearch/ambari-logsearch-web/src/main/webapp/login.html ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web/src/main/webapp/login.html b/ambari-logsearch/ambari-logsearch-web/src/main/webapp/login.html index f2cb2c7..0f63d8b 100644 --- a/ambari-logsearch/ambari-logsearch-web/src/main/webapp/login.html +++ b/ambari-logsearch/ambari-logsearch-web/src/main/webapp/login.html @@ -35,20 +35,19 @@ var passDiv = $('#passCont'); $.ajax({ - url : "/api/v1/public/config", + url : "/api/v1/info/auth", type: "GET", async: true, dataType: 'json', - success:function(results,status) + success:function(result,status) { - for(var i in results.vNameValues){ - if ((results.vNameValues[i].name === "simpleAuth") && (results.vNameValues[i].value === "true")){ - $("#password").val(""); - passDiv.hide(); - } - if (passDiv.is(':hidden')) - $("#password").prop('required',false); - } + if (result != null && result.simple == "true") { + $("#password").val(""); + passDiv.hide(); + } + if (passDiv.is(':hidden')) { + $("#password").prop('required', false); + } }, error: function(errorThrown) {