jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1437644 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: security/authentication/ldap/ spi/security/authentication/external/
Date Wed, 23 Jan 2013 19:34:07 GMT
Author: angela
Date: Wed Jan 23 19:34:07 2013
New Revision: 1437644

URL: http://svn.apache.org/viewvc?rev=1437644&view=rev
Log:
OAK-516 : Create LdapLoginModule based on ExternalLoginModule

- fixing coding style issues
- add annotations

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/JndiLdapSearch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapGroup.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginModule.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapSettings.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapUser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalUser.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/JndiLdapSearch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/JndiLdapSearch.java?rev=1437644&r1=1437643&r2=1437644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/JndiLdapSearch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/JndiLdapSearch.java
Wed Jan 23 19:34:07 2013
@@ -33,6 +33,7 @@ import javax.naming.directory.SearchCont
 import javax.naming.directory.SearchResult;
 import javax.security.auth.login.LoginException;
 
+import com.google.common.collect.ImmutableMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,19 +42,19 @@ public class JndiLdapSearch implements L
     private static final Logger log = LoggerFactory.getLogger(JndiLdapSearch.class);
 
     private final LdapSettings settings;
-    private final Hashtable ldapEnvironment;
+    private final Map<String,String> ldapEnvironment;
 
     public JndiLdapSearch(LdapSettings settings) {
         this.settings = settings;
         this.ldapEnvironment = createEnvironment(settings);
     }
 
-    private static Hashtable createEnvironment(LdapSettings settings) {
-        Hashtable env = new Hashtable();
+    private static Map createEnvironment(LdapSettings settings) {
+        Map<String,String> env = new HashMap<String,String>();
         env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
         StringBuilder url = new StringBuilder();
         url.append("ldap://").append(settings.getHost()).append(':').append(settings.getPort());
-        env.put(Context.PROVIDER_URL, url);
+        env.put(Context.PROVIDER_URL, url.toString());
         if (settings.isSecure()) {
             env.put(Context.SECURITY_PROTOCOL, "ssl");
         }
@@ -61,13 +62,12 @@ public class JndiLdapSearch implements L
         String authPw = settings.getAuthPw();
         if (authDn == null || authDn.length() == 0) {
             env.put(Context.SECURITY_AUTHENTICATION, "none");
-        }
-        else {
+        } else {
             env.put(Context.SECURITY_AUTHENTICATION, "simple");
             env.put(Context.SECURITY_PRINCIPAL, authDn);
-            env.put(Context.SECURITY_CREDENTIALS,authPw);
+            env.put(Context.SECURITY_CREDENTIALS, authPw);
         }
-        return env;
+        return ImmutableMap.copyOf(env);
     }
 
     private Object parseAttributeValue(Attribute attribute) throws NamingException {
@@ -78,8 +78,7 @@ public class JndiLdapSearch implements L
                 values.add(String.valueOf(attribute.get(k)));
             }
             return values;
-        }
-        else {
+        } else {
             return String.valueOf(attribute.get());
         }
     }
@@ -89,8 +88,8 @@ public class JndiLdapSearch implements L
         NamingEnumeration<? extends Attribute> namingEnumeration = attributes.getAll();
         Map<String, Object> properties = new HashMap<String, Object>();
         Map<String, String> syncMap = user instanceof LdapGroup ?
-                this.settings.getGroupAttributes() : this.settings.getUserAttributes();
-        while ( namingEnumeration.hasMore() ) {
+                settings.getGroupAttributes() : settings.getUserAttributes();
+        while (namingEnumeration.hasMore()) {
             Attribute attribute = namingEnumeration.next();
             String key = attribute.getID();
             if (syncMap.containsKey(key)) {
@@ -112,7 +111,7 @@ public class JndiLdapSearch implements L
         List<SearchResult> tmp = new ArrayList<SearchResult>();
         InitialDirContext context = null;
         try {
-            context = new InitialDirContext(this.ldapEnvironment);
+            context = new InitialDirContext(new Hashtable<String,String>(ldapEnvironment));
             NamingEnumeration<SearchResult> namingEnumeration = context.search(baseDN,
filter, attributes, constraints);
             while (namingEnumeration.hasMore()) {
                 tmp.add(namingEnumeration.next());
@@ -159,37 +158,37 @@ public class JndiLdapSearch implements L
 
     private List<SearchResult> searchUser(String id)
             throws NamingException {
-        Set<String> attributeSet = new HashSet<String>(this.settings.getUserAttributes().keySet());
-        attributeSet.add(this.settings.getUserIdAttribute());
+        Set<String> attributeSet = new HashSet<String>(settings.getUserAttributes().keySet());
+        attributeSet.add(settings.getUserIdAttribute());
         String[] attributes = new String[attributeSet.size()];
         attributeSet.toArray(attributes);
-        return this.search(this.settings.getUserRoot(),
-                this.compileSearchFilter(this.settings.getUserFilter(), this.settings.getUserIdAttribute()
+ '=' + id),
+        return search(settings.getUserRoot(),
+                compileSearchFilter(settings.getUserFilter(), settings.getUserIdAttribute()
+ '=' + id),
                 SearchControls.SUBTREE_SCOPE,
                 attributes);
     }
 
     private List<SearchResult> searchGroups(String dn)
             throws NamingException {
-        Set<String> attributeSet = new HashSet<String>(this.settings.getGroupAttributes().keySet());
+        Set<String> attributeSet = new HashSet<String>(settings.getGroupAttributes().keySet());
         String[] attributes = new String[attributeSet.size()];
         attributeSet.toArray(attributes);
-        return search(this.settings.getGroupRoot(),
-                this.compileSearchFilter(this.settings.getGroupFilter(), this.settings.getGroupMembershipAttribute()
+ '=' + dn),
+        return search(settings.getGroupRoot(),
+                compileSearchFilter(settings.getGroupFilter(), settings.getGroupMembershipAttribute()
+ '=' + dn),
                 SearchControls.SUBTREE_SCOPE,
                 attributes);
     }
 
     private boolean findUser(LdapUser user, String id) {
         try {
-            List<SearchResult> entries = this.searchUser(id);
+            List<SearchResult> entries = searchUser(id);
             if (!entries.isEmpty()) {
                 SearchResult entry = entries.get(0);
                 user.setDN(entry.getNameInNamespace());
-                this.initProperties(user, entry.getAttributes());
+                initProperties(user, entry.getAttributes());
                 return true;
-            } else  if (id.contains("\\")) {
-                return this.findUser(user, id.substring(id.indexOf('\\') + 1));
+            } else if (id.contains("\\")) {
+                return findUser(user, id.substring(id.indexOf('\\') + 1));
             }
         } catch (NamingException e) {
             //TODO
@@ -199,7 +198,7 @@ public class JndiLdapSearch implements L
 
     @Override
     public boolean findUser(LdapUser user) {
-        return this.findUser(user, user.getId());
+        return findUser(user, user.getId());
     }
 
     @Override
@@ -207,11 +206,11 @@ public class JndiLdapSearch implements L
         final HashSet<LdapGroup> groups = new HashSet<LdapGroup>();
         List<SearchResult> ldapEntries;
         try {
-            ldapEntries = this.searchGroups(user.getDN());
+            ldapEntries = searchGroups(user.getDN());
             for (SearchResult entry : ldapEntries) {
                 LdapGroup group = new LdapGroup(entry.getNameInNamespace(), this);
                 groups.add(group);
-                this.initProperties(group, entry.getAttributes());
+                initProperties(group, entry.getAttributes());
             }
         } catch (NamingException e) {
             //TODO
@@ -222,7 +221,7 @@ public class JndiLdapSearch implements L
     @Override
     public void authenticate(LdapUser user) throws LoginException {
         try {
-            Hashtable env = new Hashtable(this.ldapEnvironment);
+            Hashtable<String,String> env = new Hashtable<String,String>(ldapEnvironment);
             env.put(Context.SECURITY_PRINCIPAL, user.getDN());
             env.put(Context.SECURITY_CREDENTIALS, user.getPassword());
             //TODO

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapGroup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapGroup.java?rev=1437644&r1=1437643&r2=1437644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapGroup.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapGroup.java
Wed Jan 23 19:34:07 2013
@@ -16,12 +16,14 @@
  */
 package org.apache.jackrabbit.oak.security.authentication.ldap;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup;
 
 public class LdapGroup extends LdapUser implements ExternalGroup {
 
-    public LdapGroup(String dn, LdapSearch search) {
+    public LdapGroup(@Nonnull String dn, @Nonnull LdapSearch search) {
         super(dn, null, search);
-        this.setDN(dn);
+        setDN(dn);
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginModule.java?rev=1437644&r1=1437643&r2=1437644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginModule.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginModule.java
Wed Jan 23 19:34:07 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.security.authentication.ldap;
 
+import java.util.Map;
 import javax.jcr.Credentials;
 import javax.jcr.SimpleCredentials;
 import javax.security.auth.Subject;
@@ -24,70 +25,67 @@ import javax.security.auth.login.LoginEx
 
 import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalLoginModule;
 import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Map;
 
 public final class LdapLoginModule extends ExternalLoginModule {
 
-    private static final Logger log = LoggerFactory.getLogger(ExternalLoginModule.class);
-
     private Credentials credentials;
     private LdapUser ldapUser;
     private boolean success;
 
     private LdapSearch search;
 
+    //--------------------------------------------------------< LoginModule >---
     @Override
     public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String,
?> sharedState, Map<String, ?> options) {
         super.initialize(subject, callbackHandler, sharedState, options);
         //TODO
-        this.search = new JndiLdapSearch(new LdapSettings(options));
-    }
-
-    @Override
-    protected boolean loginSucceeded() {
-        return this.success;
-    }
-
-    @Override
-    protected ExternalUser getExternalUser() {
-        if (this.ldapUser == null) {
-            Credentials creds = getCredentials();
-            if (creds instanceof SimpleCredentials) {
-                String uid = ((SimpleCredentials) creds).getUserID();
-                char[] pwd = ((SimpleCredentials) creds).getPassword();
-                this.ldapUser = new LdapUser(uid, new String(pwd), this.search);
-            }
-        }
-        return this.ldapUser;
+        search = new JndiLdapSearch(new LdapSettings(options));
     }
 
     @Override
     public boolean login() throws LoginException {
         getExternalUser();
-        if (this.ldapUser != null && this.search.findUser(this.ldapUser)) {
-            this.search.authenticate(this.ldapUser);
-            this.success = true;
+        if (ldapUser != null && search.findUser(ldapUser)) {
+            search.authenticate(ldapUser);
+            success = true;
         }
-        return this.success;
+        return success;
     }
 
+    //------------------------------------------------< AbstractLoginModule >---
     @Override
     protected Credentials getCredentials() {
-        if (this.credentials == null) {
-            this.credentials = super.getCredentials();
+        if (credentials == null) {
+            credentials = super.getCredentials();
         }
-        return this.credentials;
+        return credentials;
     }
 
     @Override
     protected void clearState() {
         super.clearState();
-        this.success = false;
-        this.credentials = null;
-        this.ldapUser = null;
-        this.search = null;
+        success = false;
+        credentials = null;
+        ldapUser = null;
+        search = null;
+    }
+
+    //------------------------------------------------< ExternalLoginModule >---
+    @Override
+    protected boolean loginSucceeded() {
+        return success;
+    }
+
+    @Override
+    protected ExternalUser getExternalUser() {
+        if (ldapUser == null) {
+            Credentials creds = getCredentials();
+            if (creds instanceof SimpleCredentials) {
+                String uid = ((SimpleCredentials) creds).getUserID();
+                char[] pwd = ((SimpleCredentials) creds).getPassword();
+                ldapUser = new LdapUser(uid, new String(pwd), search);
+            }
+        }
+        return ldapUser;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapSettings.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapSettings.java?rev=1437644&r1=1437643&r2=1437644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapSettings.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapSettings.java
Wed Jan 23 19:34:07 2013
@@ -24,22 +24,22 @@ public final class LdapSettings {
     //TODO support autocreate.user.membership
     //TODO support autocreate.path
 
-    public final static String KEY_HOST = "host";
-    public final static String KEY_PORT = "port";
-    public final static String KEY_SECURE = "secure";
-    public final static String KEY_AUTHDN = "authDn";
-    public final static String KEY_AUTHPW = "authPw";
-    public final static String KEY_SEARCHTIMEOUT = "searchTimeout";
-    public final static String KEY_USERROOT = "userRoot";
-    public final static String KEY_USERFILTER = "userFilter";
-    public final static String KEY_USERIDATTRIBUTE = "userIdAttribute";
-    public final static String KEY_GROUPROOT = "groupRoot";
-    public final static String KEY_GROUPFILTER = "groupFilter";
-    public final static String KEY_GROUPMEMBERSHIPATTRIBUTE = "groupMembershipAttribute";
-    public final static String KEY_GROUPNAMEATTRIBUTE = "groupNameAttribute";
-    public final static String KEY_AUTOCREATEPATH = "autocreate.path";
-    public final static String KEY_AUTOCREATEUSER = "autocreate.user.";
-    public final static String KEY_AUTOCREATEGROUP = "autocreate.group.";
+    public static final String KEY_HOST = "host";
+    public static final String KEY_PORT = "port";
+    public static final String KEY_SECURE = "secure";
+    public static final String KEY_AUTHDN = "authDn";
+    public static final String KEY_AUTHPW = "authPw";
+    public static final String KEY_SEARCHTIMEOUT = "searchTimeout";
+    public static final String KEY_USERROOT = "userRoot";
+    public static final String KEY_USERFILTER = "userFilter";
+    public static final String KEY_USERIDATTRIBUTE = "userIdAttribute";
+    public static final String KEY_GROUPROOT = "groupRoot";
+    public static final String KEY_GROUPFILTER = "groupFilter";
+    public static final String KEY_GROUPMEMBERSHIPATTRIBUTE = "groupMembershipAttribute";
+    public static final String KEY_GROUPNAMEATTRIBUTE = "groupNameAttribute";
+    public static final String KEY_AUTOCREATEPATH = "autocreate.path";
+    public static final String KEY_AUTOCREATEUSER = "autocreate.user.";
+    public static final String KEY_AUTOCREATEGROUP = "autocreate.group.";
 
     //Connection settings
     private String host;
@@ -65,127 +65,127 @@ public final class LdapSettings {
 
     public LdapSettings(Map<String, ?> options) {
         if (options.containsKey(KEY_HOST)) {
-            this.host = (String) options.get(KEY_HOST);
+            host = (String) options.get(KEY_HOST);
         }
         if (options.containsKey(KEY_PORT)) {
             String s = (String) options.get(KEY_PORT);
             if (s != null && s.length() > 0) {
-                this.port = Integer.parseInt(s);
+                port = Integer.parseInt(s);
             }
         }
         if (options.containsKey(KEY_SECURE)) {
             String s = (String) options.get(KEY_SECURE);
             if (s != null && s.length() > 0) {
-                this.secure = Boolean.parseBoolean(s);
+                secure = Boolean.parseBoolean(s);
             }
         }
         if (options.containsKey(KEY_AUTHDN)) {
-            this.authDn = (String) options.get(KEY_AUTHDN);
+            authDn = (String) options.get(KEY_AUTHDN);
         }
         if (options.containsKey(KEY_AUTHPW)) {
-            this.authPw = (String) options.get(KEY_AUTHPW);
+            authPw = (String) options.get(KEY_AUTHPW);
         }
         if (options.containsKey(KEY_SEARCHTIMEOUT)) {
             String s = (String) options.get(KEY_SEARCHTIMEOUT);
             if (s != null && s.length() > 0) {
-                this.searchTimeout = Integer.parseInt(s);
+                searchTimeout = Integer.parseInt(s);
             }
         }
         if (options.containsKey(KEY_USERROOT)) {
-            this.userRoot = (String) options.get(KEY_USERROOT);
+            userRoot = (String) options.get(KEY_USERROOT);
         }
         if (options.containsKey(KEY_USERFILTER)) {
-            this.userFilter = (String) options.get(KEY_USERFILTER);
+            userFilter = (String) options.get(KEY_USERFILTER);
         }
         if (options.containsKey(KEY_USERIDATTRIBUTE)) {
-            this.userIdAttribute = (String) options.get(KEY_USERIDATTRIBUTE);
+            userIdAttribute = (String) options.get(KEY_USERIDATTRIBUTE);
         }
         if (options.containsKey(KEY_GROUPROOT)) {
-            this.groupRoot = (String) options.get(KEY_GROUPROOT);
+            groupRoot = (String) options.get(KEY_GROUPROOT);
         }
         if (options.containsKey(KEY_GROUPFILTER)) {
-            this.groupFilter = (String) options.get(KEY_GROUPFILTER);
+            groupFilter = (String) options.get(KEY_GROUPFILTER);
         }
         if (options.containsKey(KEY_GROUPMEMBERSHIPATTRIBUTE)) {
-            this.groupMembershipAttribute = (String) options.get(KEY_GROUPMEMBERSHIPATTRIBUTE);
+            groupMembershipAttribute = (String) options.get(KEY_GROUPMEMBERSHIPATTRIBUTE);
         }
         if (options.containsKey(KEY_GROUPNAMEATTRIBUTE)) {
-            this.groupNameAttribute = (String) options.get(KEY_GROUPNAMEATTRIBUTE);
+            groupNameAttribute = (String) options.get(KEY_GROUPNAMEATTRIBUTE);
         }
         if (options.containsKey(KEY_AUTOCREATEPATH)) {
-            this.splitPath = "splitdn".equals(options.get(KEY_AUTOCREATEPATH));
+            splitPath = "splitdn".equals(options.get(KEY_AUTOCREATEPATH));
         }
         for (String key : options.keySet()) {
             if (key.startsWith(KEY_AUTOCREATEUSER)) {
-                this.userAttributes.put(key.substring(KEY_AUTOCREATEUSER.length()), (String)
options.get(key));
+                userAttributes.put(key.substring(KEY_AUTOCREATEUSER.length()), (String) options.get(key));
             }
             if (key.startsWith(KEY_AUTOCREATEGROUP)) {
-                this.groupAttributes.put(key.substring(KEY_AUTOCREATEGROUP.length()), (String)
options.get(key));
+                groupAttributes.put(key.substring(KEY_AUTOCREATEGROUP.length()), (String)
options.get(key));
             }
         }
     }
 
     public String getHost() {
-        return this.host;
+        return host;
     }
 
     public int getPort() {
-        return this.port;
+        return port;
     }
 
     public boolean isSecure() {
-        return this.secure;
+        return secure;
     }
 
     public String getAuthDn() {
-        return this.authDn;
+        return authDn;
     }
 
     public String getAuthPw() {
-        return this.authPw;
+        return authPw;
     }
 
     public int getSearchTimeout() {
-        return this.searchTimeout;
+        return searchTimeout;
     }
 
     public String getUserRoot() {
-        return this.userRoot;
+        return userRoot;
     }
 
     public String getUserFilter() {
-        return this.userFilter;
+        return userFilter;
     }
 
     public String getUserIdAttribute() {
-        return this.userIdAttribute;
+        return userIdAttribute;
     }
 
     public String getGroupRoot() {
-        return this.groupRoot;
+        return groupRoot;
     }
 
     public String getGroupFilter() {
-        return this.groupFilter;
+        return groupFilter;
     }
 
     public String getGroupMembershipAttribute() {
-        return this.groupMembershipAttribute;
+        return groupMembershipAttribute;
     }
 
     public String getGroupNameAttribute() {
-        return this.groupNameAttribute;
+        return groupNameAttribute;
     }
 
     public boolean isSplitPath() {
-        return this.splitPath;
+        return splitPath;
     }
 
     public Map<String, String> getUserAttributes() {
-        return this.userAttributes;
+        return userAttributes;
     }
 
     public Map<String, String> getGroupAttributes() {
-        return this.groupAttributes;
+        return groupAttributes;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapUser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapUser.java?rev=1437644&r1=1437643&r2=1437644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapUser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapUser.java
Wed Jan 23 19:34:07 2013
@@ -20,6 +20,8 @@ import java.security.Principal;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.apache.jackrabbit.oak.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser;
@@ -36,61 +38,64 @@ public class LdapUser implements Externa
     private Set<LdapGroup> groups;
     private Map<String, ?> properties = new HashMap<String, Object>();
 
-    public LdapUser(String uid, String pwd, LdapSearch search) {
+    public LdapUser(@Nonnull String uid, @Nullable String pwd, @Nonnull LdapSearch search)
{
         this.uid = uid;
         this.pwd = pwd;
         this.search = search;
     }
 
+    //-------------------------------------------------------< ExternalUser >---
     @Override
     public String getId() {
-        return this.uid;
+        return uid;
     }
 
     @Override
     public String getPassword() {
-        return this.pwd;
+        return pwd;
     }
 
     @Override
     public Principal getPrincipal() {
-        if (this.principal == null) {
-            this.principal = new PrincipalImpl(this.uid);
+        if (principal == null) {
+            principal = new PrincipalImpl(uid);
         }
-        return this.principal;
+        return principal;
     }
 
     @Override
     public String getPath() {
         //TODO also support splitdn mode
-        if (this.path == null) {
-            this.path = this.getDN();
+        if (path == null) {
+            path = getDN();
         }
-        return this.path;
+        return path;
     }
 
     @Override
     public Set<LdapGroup> getGroups() {
-        if (this.groups == null) {
-            this.groups = this.search.findGroups(this);
+        if (groups == null) {
+            groups = search.findGroups(this);
         }
-        return this.groups;
+        return groups;
     }
 
     @Override
     public Map<String, ?> getProperties() {
-        return this.properties;
+        return properties;
     }
 
-    public void setProperties(Map<String, ?> properties) {
+    //--------------------------------------------------------------------------
+
+    void setProperties(Map<String, ?> properties) {
         this.properties = properties;
     }
 
-    public String getDN() {
-        return this.dn;
+    String getDN() {
+        return dn;
     }
 
-    public void setDN(String dn) {
+    void setDN(String dn) {
         this.dn = dn;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalUser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalUser.java?rev=1437644&r1=1437643&r2=1437644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalUser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalUser.java
Wed Jan 23 19:34:07 2013
@@ -19,21 +19,29 @@ package org.apache.jackrabbit.oak.spi.se
 import java.security.Principal;
 import java.util.Map;
 import java.util.Set;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 
 /**
  * ExternalUser... TODO
  */
 public interface ExternalUser {
 
+    @Nonnull
     String getId();
 
+    @CheckForNull
     String getPassword();
 
+    @Nonnull
     Principal getPrincipal();
 
+    @Nonnull
     String getPath();
 
+    @Nonnull
     Set<? extends ExternalGroup> getGroups();
 
+    @Nonnull
     Map<String, ?> getProperties();
 }
\ No newline at end of file



Mime
View raw message