[10/17] ambari git commit: AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case sensitiveness option (/L) depending on the case_insensitive_username_rules. (amagyar)

2017-08-14 Thread jonathanhurley
AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case 
sensitiveness option (/L) depending on the case_insensitive_username_rules. 
(amagyar)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cfa29988
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cfa29988
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cfa29988

Branch: refs/heads/branch-feature-AMBARI-21450
Commit: cfa299883cdf3f5ada93dfd72138b3b407f9bec5
Parents: 78684fb
Author: Attila Magyar 
Authored: Fri Aug 11 17:54:19 2017 +0200
Committer: Attila Magyar 
Committed: Fri Aug 11 17:54:19 2017 +0200

--
 .../server/controller/AuthToLocalBuilder.java   | 338 +++
 .../controller/AuthToLocalBuilderTest.java  |  45 +++
 2 files changed, 246 insertions(+), 137 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/cfa29988/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
--
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
index 7e706ff..e6a4f62 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
@@ -18,8 +18,6 @@
 
 package org.apache.ambari.server.controller;
 
-import org.apache.commons.lang.StringUtils;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -30,6 +28,12 @@ import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
 /**
  * AuthToLocalBuilder helps to create auth_to_local rules for use in 
configuration files like
  * core-site.xml.  No duplicate rules will be generated.
@@ -60,7 +64,7 @@ public class AuthToLocalBuilder implements Cloneable {
   /**
* Ordered set of rules which have been added to the builder.
*/
-  private Set setRules = new TreeSet();
+  private Set setRules = new TreeSet<>();
 
   /**
* The default realm.
@@ -105,7 +109,7 @@ public class AuthToLocalBuilder implements Cloneable {
 
 this.additionalRealms = (additionalRealms == null)
 ? Collections.emptySet()
-: Collections.unmodifiableSet(new HashSet(additionalRealms));
+: Collections.unmodifiableSet(new HashSet<>(additionalRealms));
 
 this.caseInsensitiveUser = caseInsensitiveUserSupport;
   }
@@ -115,7 +119,7 @@ public class AuthToLocalBuilder implements Cloneable {
 AuthToLocalBuilder copy = (AuthToLocalBuilder) super.clone();
 
 /*  Copy mutable members  */
-copy.setRules = new TreeSet(setRules);
+copy.setRules = new TreeSet<>(setRules);
 
 return copy;
   }
@@ -126,20 +130,22 @@ public class AuthToLocalBuilder implements Cloneable {
*
* @param authToLocalRules config property value containing the existing 
rules
*/
-  public void addRules(String authToLocalRules) {
+  public AuthToLocalBuilder addRules(String authToLocalRules) {
 if (!StringUtils.isEmpty(authToLocalRules)) {
   String[] rules = authToLocalRules.split("RULE:|DEFAULT");
   for (String r : rules) {
 r = r.trim();
 if (!r.isEmpty()) {
   Rule rule = createRule(r);
-  setRules.add(rule);
+  if (!setRules.contains(rule.caseSensitivityInverted())) {
+setRules.add(rule);
+  }
 }
   }
 }
+return this;
   }
 
-
   /**
* Adds a rule for the given principal and local user.
* The principal must contain a realm component.
@@ -157,7 +163,7 @@ public class AuthToLocalBuilder implements Cloneable {
* @param localUsername a string declaring that local username to map the 
principal to
* @throws IllegalArgumentException if the provided principal doesn't 
contain a realm element
*/
-  public void addRule(String principal, String localUsername) {
+  public AuthToLocalBuilder addRule(String principal, String localUsername) {
 if (!StringUtils.isEmpty(principal) && 
!StringUtils.isEmpty(localUsername)) {
   Principal p = new Principal(principal);
   if (p.getRealm() == null) {
@@ -168,6 +174,7 @@ public class AuthToLocalBuilder implements Cloneable {
   Rule rule = createHostAgnosticRule(p, localUsername);
   setRules.add(rule);
 }
+return this;
   }
 
   /**
@@ -264,10 +271,10 @@ public class AuthToLocalBuilder implements Cloneable {
   private Rule createHostAgnosticRul

ambari git commit: AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case sensitiveness option (/L) depending on the case_insensitive_username_rules. (amagyar)

2017-08-11 Thread amagyar
Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 78684fb7c -> cfa299883


AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case 
sensitiveness option (/L) depending on the case_insensitive_username_rules. 
(amagyar)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cfa29988
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cfa29988
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cfa29988

Branch: refs/heads/branch-2.6
Commit: cfa299883cdf3f5ada93dfd72138b3b407f9bec5
Parents: 78684fb
Author: Attila Magyar 
Authored: Fri Aug 11 17:54:19 2017 +0200
Committer: Attila Magyar 
Committed: Fri Aug 11 17:54:19 2017 +0200

--
 .../server/controller/AuthToLocalBuilder.java   | 338 +++
 .../controller/AuthToLocalBuilderTest.java  |  45 +++
 2 files changed, 246 insertions(+), 137 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/cfa29988/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
--
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
index 7e706ff..e6a4f62 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
@@ -18,8 +18,6 @@
 
 package org.apache.ambari.server.controller;
 
-import org.apache.commons.lang.StringUtils;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -30,6 +28,12 @@ import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
 /**
  * AuthToLocalBuilder helps to create auth_to_local rules for use in 
configuration files like
  * core-site.xml.  No duplicate rules will be generated.
@@ -60,7 +64,7 @@ public class AuthToLocalBuilder implements Cloneable {
   /**
* Ordered set of rules which have been added to the builder.
*/
-  private Set setRules = new TreeSet();
+  private Set setRules = new TreeSet<>();
 
   /**
* The default realm.
@@ -105,7 +109,7 @@ public class AuthToLocalBuilder implements Cloneable {
 
 this.additionalRealms = (additionalRealms == null)
 ? Collections.emptySet()
-: Collections.unmodifiableSet(new HashSet(additionalRealms));
+: Collections.unmodifiableSet(new HashSet<>(additionalRealms));
 
 this.caseInsensitiveUser = caseInsensitiveUserSupport;
   }
@@ -115,7 +119,7 @@ public class AuthToLocalBuilder implements Cloneable {
 AuthToLocalBuilder copy = (AuthToLocalBuilder) super.clone();
 
 /*  Copy mutable members  */
-copy.setRules = new TreeSet(setRules);
+copy.setRules = new TreeSet<>(setRules);
 
 return copy;
   }
@@ -126,20 +130,22 @@ public class AuthToLocalBuilder implements Cloneable {
*
* @param authToLocalRules config property value containing the existing 
rules
*/
-  public void addRules(String authToLocalRules) {
+  public AuthToLocalBuilder addRules(String authToLocalRules) {
 if (!StringUtils.isEmpty(authToLocalRules)) {
   String[] rules = authToLocalRules.split("RULE:|DEFAULT");
   for (String r : rules) {
 r = r.trim();
 if (!r.isEmpty()) {
   Rule rule = createRule(r);
-  setRules.add(rule);
+  if (!setRules.contains(rule.caseSensitivityInverted())) {
+setRules.add(rule);
+  }
 }
   }
 }
+return this;
   }
 
-
   /**
* Adds a rule for the given principal and local user.
* The principal must contain a realm component.
@@ -157,7 +163,7 @@ public class AuthToLocalBuilder implements Cloneable {
* @param localUsername a string declaring that local username to map the 
principal to
* @throws IllegalArgumentException if the provided principal doesn't 
contain a realm element
*/
-  public void addRule(String principal, String localUsername) {
+  public AuthToLocalBuilder addRule(String principal, String localUsername) {
 if (!StringUtils.isEmpty(principal) && 
!StringUtils.isEmpty(localUsername)) {
   Principal p = new Principal(principal);
   if (p.getRealm() == null) {
@@ -168,6 +174,7 @@ public class AuthToLocalBuilder implements Cloneable {
   Rule rule = createHostAgnosticRule(p, localUsername);
   setRules.add(rule);
 }
+return this;
   }
 
   /**
@@ -264,10 +271,10 @@ public class AuthToLoca

[48/50] [abbrv] ambari git commit: AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case sensitiveness option (/L) depending on the case_insensitive_username_rules. (amagyar)

2017-07-24 Thread ncole
AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case 
sensitiveness option (/L) depending on the case_insensitive_username_rules. 
(amagyar)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bfe772be
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bfe772be
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bfe772be

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: bfe772be2858dbf488aa940b0e513141fb018dc1
Parents: 95e7719
Author: Attila Magyar 
Authored: Mon Jul 24 14:55:50 2017 +0200
Committer: Attila Magyar 
Committed: Mon Jul 24 14:55:50 2017 +0200

--
 .../server/controller/AuthToLocalBuilder.java   | 328 +++
 .../controller/AuthToLocalBuilderTest.java  |  45 +++
 2 files changed, 241 insertions(+), 132 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/bfe772be/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
--
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
index 1d4abdd..b301ed2 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
@@ -28,7 +28,11 @@ import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.annotation.Nullable;
+
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
 
 /**
  * AuthToLocalBuilder helps to create auth_to_local rules for use in 
configuration files like
@@ -104,7 +108,7 @@ public class AuthToLocalBuilder implements Cloneable {
 this.defaultRealm = defaultRealm;
 
 this.additionalRealms = (additionalRealms == null)
-? Collections.emptySet()
+? Collections.emptySet()
 : Collections.unmodifiableSet(new HashSet<>(additionalRealms));
 
 this.caseInsensitiveUser = caseInsensitiveUserSupport;
@@ -126,20 +130,22 @@ public class AuthToLocalBuilder implements Cloneable {
*
* @param authToLocalRules config property value containing the existing 
rules
*/
-  public void addRules(String authToLocalRules) {
+  public AuthToLocalBuilder addRules(String authToLocalRules) {
 if (!StringUtils.isEmpty(authToLocalRules)) {
   String[] rules = authToLocalRules.split("RULE:|DEFAULT");
   for (String r : rules) {
 r = r.trim();
 if (!r.isEmpty()) {
   Rule rule = createRule(r);
-  setRules.add(rule);
+  if (!setRules.contains(rule.caseSensitivityInverted())) {
+setRules.add(rule);
+  }
 }
   }
 }
+return this;
   }
 
-
   /**
* Adds a rule for the given principal and local user.
* The principal must contain a realm component.
@@ -157,7 +163,7 @@ public class AuthToLocalBuilder implements Cloneable {
* @param localUsername a string declaring that local username to map the 
principal to
* @throws IllegalArgumentException if the provided principal doesn't 
contain a realm element
*/
-  public void addRule(String principal, String localUsername) {
+  public AuthToLocalBuilder addRule(String principal, String localUsername) {
 if (!StringUtils.isEmpty(principal) && 
!StringUtils.isEmpty(localUsername)) {
   Principal p = new Principal(principal);
   if (p.getRealm() == null) {
@@ -168,6 +174,7 @@ public class AuthToLocalBuilder implements Cloneable {
   Rule rule = createHostAgnosticRule(p, localUsername);
   setRules.add(rule);
 }
+return this;
   }
 
   /**
@@ -264,10 +271,10 @@ public class AuthToLocalBuilder implements Cloneable {
   private Rule createHostAgnosticRule(Principal principal, String localUser) {
 List principalComponents = principal.getComponents();
 int componentCount = principalComponents.size();
-
-return new Rule(principal, componentCount, 1, String.format(
-"RULE:[%d:$1@$0](%s@%s)s/.*/%s/", componentCount,
-principal.getComponent(1), principal.getRealm(), localUser));
+return new Rule(
+  MatchingRule.ignoreHostWhenComponentCountIs(componentCount),
+  new Principal(principal.getComponent(1) + "@" + principal.getRealm()),
+  new Substitution(".*", localUser, "", false));
   }
 
   /**
@@ -278,10 +285,10 @@ public class AuthToLocalBuilder implements Cloneable {
* @return a new default realm rule
*/
   private Rule createDefaultRealmRule(String realm, boolean caseInsensitive) {
-String caseSensitivityRule = caseIns

ambari git commit: AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case sensitiveness option (/L) depending on the case_insensitive_username_rules. (amagyar)

2017-07-24 Thread amagyar
Repository: ambari
Updated Branches:
  refs/heads/trunk 95e7719b1 -> bfe772be2


AMBARI-21418. Ambari rebuilds custom auth_to_local rules changing its case 
sensitiveness option (/L) depending on the case_insensitive_username_rules. 
(amagyar)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bfe772be
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bfe772be
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bfe772be

Branch: refs/heads/trunk
Commit: bfe772be2858dbf488aa940b0e513141fb018dc1
Parents: 95e7719
Author: Attila Magyar 
Authored: Mon Jul 24 14:55:50 2017 +0200
Committer: Attila Magyar 
Committed: Mon Jul 24 14:55:50 2017 +0200

--
 .../server/controller/AuthToLocalBuilder.java   | 328 +++
 .../controller/AuthToLocalBuilderTest.java  |  45 +++
 2 files changed, 241 insertions(+), 132 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/bfe772be/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
--
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
index 1d4abdd..b301ed2 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java
@@ -28,7 +28,11 @@ import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.annotation.Nullable;
+
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
 
 /**
  * AuthToLocalBuilder helps to create auth_to_local rules for use in 
configuration files like
@@ -104,7 +108,7 @@ public class AuthToLocalBuilder implements Cloneable {
 this.defaultRealm = defaultRealm;
 
 this.additionalRealms = (additionalRealms == null)
-? Collections.emptySet()
+? Collections.emptySet()
 : Collections.unmodifiableSet(new HashSet<>(additionalRealms));
 
 this.caseInsensitiveUser = caseInsensitiveUserSupport;
@@ -126,20 +130,22 @@ public class AuthToLocalBuilder implements Cloneable {
*
* @param authToLocalRules config property value containing the existing 
rules
*/
-  public void addRules(String authToLocalRules) {
+  public AuthToLocalBuilder addRules(String authToLocalRules) {
 if (!StringUtils.isEmpty(authToLocalRules)) {
   String[] rules = authToLocalRules.split("RULE:|DEFAULT");
   for (String r : rules) {
 r = r.trim();
 if (!r.isEmpty()) {
   Rule rule = createRule(r);
-  setRules.add(rule);
+  if (!setRules.contains(rule.caseSensitivityInverted())) {
+setRules.add(rule);
+  }
 }
   }
 }
+return this;
   }
 
-
   /**
* Adds a rule for the given principal and local user.
* The principal must contain a realm component.
@@ -157,7 +163,7 @@ public class AuthToLocalBuilder implements Cloneable {
* @param localUsername a string declaring that local username to map the 
principal to
* @throws IllegalArgumentException if the provided principal doesn't 
contain a realm element
*/
-  public void addRule(String principal, String localUsername) {
+  public AuthToLocalBuilder addRule(String principal, String localUsername) {
 if (!StringUtils.isEmpty(principal) && 
!StringUtils.isEmpty(localUsername)) {
   Principal p = new Principal(principal);
   if (p.getRealm() == null) {
@@ -168,6 +174,7 @@ public class AuthToLocalBuilder implements Cloneable {
   Rule rule = createHostAgnosticRule(p, localUsername);
   setRules.add(rule);
 }
+return this;
   }
 
   /**
@@ -264,10 +271,10 @@ public class AuthToLocalBuilder implements Cloneable {
   private Rule createHostAgnosticRule(Principal principal, String localUser) {
 List principalComponents = principal.getComponents();
 int componentCount = principalComponents.size();
-
-return new Rule(principal, componentCount, 1, String.format(
-"RULE:[%d:$1@$0](%s@%s)s/.*/%s/", componentCount,
-principal.getComponent(1), principal.getRealm(), localUser));
+return new Rule(
+  MatchingRule.ignoreHostWhenComponentCountIs(componentCount),
+  new Principal(principal.getComponent(1) + "@" + principal.getRealm()),
+  new Substitution(".*", localUser, "", false));
   }
 
   /**
@@ -278,10 +285,10 @@ public class AuthToLocalBuilder implements Cloneable {
* @return a new default realm rule
*/
   private Rule createDefaultRealmRule(String realm, boolean c