From 5dc42d1ce5d9be74cfa0683bbef57ddcc3e8f1bb Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Mon, 20 Feb 2017 19:27:38 +0800 Subject: [PATCH 01/13] Add User.Role --- .../common/authentication/UserPrincipal.java | 77 +++++++++ .../eagle/common/service/HadoopUser.java | 2 +- .../entity/meta/EntityDefinitionManager.java | 2 +- .../history/crawl/JHFSparkEventReader.java | 2 +- .../app/apps/jpm/partials/queue/overview.html | 2 +- .../entity/HdfsUserCommandPatternEntity.java | 2 +- .../eagle/security/hive/ql/TestParser.java | 2 +- .../eagle/server/ServerApplication.java | 3 +- .../org/apache/eagle/server/ServerConfig.java | 8 +- .../BasicAuthProviderBuilder.java | 31 ++-- .../BasicAuthenticationFilter.java | 83 +++++----- .../authenticator/LdapBasicAuthenticator.java | 14 +- .../SimpleBasicAuthenticator.java | 40 +++-- ...ettings.java => AuthenticationConfig.java} | 26 +-- .../{LdapSettings.java => LdapConfig.java} | 14 +- ...{SimpleSettings.java => SimpleConfig.java} | 49 ++++-- .../authentication/config/UserAccount.java | 61 +++++++ .../resource/AuthenticationResource.java | 40 +++++ .../src/main/resources/configuration.yml | 154 +++++++++--------- .../LdapBasicAuthenticatorTest.java | 10 +- .../SimpleBasicAuthenticatorTest.java | 22 ++- .../TestBasicAuthenticationResource.java | 6 +- .../src/test/resources/configuration.yml | 12 +- 23 files changed, 435 insertions(+), 227 deletions(-) create mode 100644 eagle-core/eagle-common/src/main/java/org/apache/eagle/common/authentication/UserPrincipal.java rename eagle-core/eagle-common/src/main/java/org/apache/eagle/common/authentication/User.java => eagle-server/src/main/java/org/apache/eagle/server/authentication/BasicAuthenticationFilter.java (53%) rename eagle-server/src/main/java/org/apache/eagle/server/authentication/config/{AuthenticationSettings.java => AuthenticationConfig.java} (75%) rename eagle-server/src/main/java/org/apache/eagle/server/authentication/config/{LdapSettings.java => LdapConfig.java} (84%) rename eagle-server/src/main/java/org/apache/eagle/server/authentication/config/{SimpleSettings.java => SimpleConfig.java} (54%) create mode 100644 eagle-server/src/main/java/org/apache/eagle/server/authentication/config/UserAccount.java create mode 100644 eagle-server/src/main/java/org/apache/eagle/server/resource/AuthenticationResource.java diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/authentication/UserPrincipal.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/authentication/UserPrincipal.java new file mode 100644 index 0000000000..489db585d9 --- /dev/null +++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/authentication/UserPrincipal.java @@ -0,0 +1,77 @@ +/* + * 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.eagle.common.authentication; + +import java.io.Serializable; +import java.security.Principal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class UserPrincipal implements Principal, Serializable { + private String username; + private List roles; + + public UserPrincipal() { + + } + + public UserPrincipal(String username) { + this.username = username; + } + + public UserPrincipal(String username, List roles) { + this.username = username; + this.roles = roles; + } + + public List getRoles() { + return roles; + } + + public String getName() { + return username; + } + + public enum Role { + ADMIN_ROLE("ADMIN"), + USER_ROLE("USER"); + + private static Map nameRoleMap = new HashMap() { + { + put(ADMIN_ROLE.roleName, ADMIN_ROLE); + put(USER_ROLE.roleName, USER_ROLE); + } + }; + + Role(String roleName) { + this.roleName = roleName; + } + + @Override + public String toString() { + return roleName; + } + + public static Role locate(String roleName) { + return nameRoleMap.get(roleName); + } + + private final String roleName; + } +} \ No newline at end of file diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java index 5c9cf8051d..094b8087a8 100644 --- a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java +++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java @@ -19,7 +19,7 @@ import java.util.List; /** - * Hadoop User. + * Hadoop UserPrincipal. * @since : 7/11/14,2014 */ public class HadoopUser { diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/meta/EntityDefinitionManager.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/meta/EntityDefinitionManager.java index 7b1010dff0..8795ba033a 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/meta/EntityDefinitionManager.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/meta/EntityDefinitionManager.java @@ -278,7 +278,7 @@ public static void load() throws IllegalAccessException, InstantiationException } /** - * User can register their own field SerDeser + * UserPrincipal can register their own field SerDeser * @param clazz class of the the SerDeser * @param entitySerDeser entity or field SerDeser * @throws IllegalArgumentException diff --git a/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/crawl/JHFSparkEventReader.java b/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/crawl/JHFSparkEventReader.java index 2ef1bd9618..d245f49ea0 100644 --- a/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/crawl/JHFSparkEventReader.java +++ b/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/crawl/JHFSparkEventReader.java @@ -169,7 +169,7 @@ private void handleAppStarted(JSONObject event) { // the second argument of getNormalizeName() is changed to null because the original code contains sensitive text // original second argument looks like: this.app.getConfig().getConfig().get("xxx"), "xxx" is the sensitive text entity.getTags().put(SparkJobTagName.SPARK_APP_NORM_NAME.toString(), this.getNormalizedName(JSONUtils.getString(event, "App Name"), null)); - entity.getTags().put(SparkJobTagName.SPARK_USER.toString(), JSONUtils.getString(event, "User")); + entity.getTags().put(SparkJobTagName.SPARK_USER.toString(), JSONUtils.getString(event, "UserPrincipal")); entity.setTimestamp(appStartTime); } diff --git a/eagle-jpm/eagle-jpm-web/src/main/webapp/app/apps/jpm/partials/queue/overview.html b/eagle-jpm/eagle-jpm-web/src/main/webapp/app/apps/jpm/partials/queue/overview.html index 732fbb2175..dfcf41c5e5 100644 --- a/eagle-jpm/eagle-jpm-web/src/main/webapp/app/apps/jpm/partials/queue/overview.html +++ b/eagle-jpm/eagle-jpm-web/src/main/webapp/app/apps/jpm/partials/queue/overview.html @@ -42,7 +42,7 @@