2
0
Эх сурвалжийг харах

SEC-2690: Polish LdapAuthority

- Make dn required (as javadoc inidicates)
- Simplify .equals since role cannot be null
- Formatting polish
Rob Winch 11 жил өмнө
parent
commit
0f6235bbe0

+ 14 - 7
ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapAuthority.java

@@ -16,6 +16,7 @@
 package org.springframework.security.ldap.userdetails;
 package org.springframework.security.ldap.userdetails;
 
 
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.GrantedAuthority;
+import org.springframework.util.Assert;
 
 
 import java.util.Collections;
 import java.util.Collections;
 import java.util.List;
 import java.util.List;
@@ -52,7 +53,9 @@ public class LdapAuthority implements GrantedAuthority {
      * @param attributes
      * @param attributes
      */
      */
     public LdapAuthority(String role, String dn, Map<String, List<String>> attributes) {
     public LdapAuthority(String role, String dn, Map<String, List<String>> attributes) {
-        if (role == null) throw new NullPointerException("role can not be null");
+        Assert.notNull(role, "role can not be null");
+        Assert.notNull(dn, "dn can not be null");
+
         this.role = role;
         this.role = role;
         this.dn = dn;
         this.dn = dn;
         this.attributes = attributes;
         this.attributes = attributes;
@@ -121,15 +124,19 @@ public class LdapAuthority implements GrantedAuthority {
      */
      */
     @Override
     @Override
     public boolean equals(Object o) {
     public boolean equals(Object o) {
-        if (this == o) return true;
-        if (!(o instanceof LdapAuthority)) return false;
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof LdapAuthority)) {
+            return false;
+        }
 
 
         LdapAuthority that = (LdapAuthority) o;
         LdapAuthority that = (LdapAuthority) o;
 
 
-        if (!dn.equals(that.dn)) return false;
-        if (role != null ? !role.equals(that.role) : that.role != null) return false;
-
-        return true;
+        if (!dn.equals(that.dn)) {
+            return false;
+        }
+        return role.equals(that.role);
     }
     }
 
 
     @Override
     @Override