Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected String bindDNAuthentication(javax.naming.ldap.InitialLdapContext paramInitialLdapContext, String paramString1, String paramString2, String paramString3, String paramString4) throws javax.naming.NamingException
        protected internal virtual string bindDNAuthentication(InitialLdapContext paramInitialLdapContext, string paramString1, string paramString2, string paramString3, string paramString4)
        {
            SearchControls searchControls = new SearchControls();

            searchControls.SearchScope         = 2;
            searchControls.ReturningAttributes = new string[0];
            searchControls.TimeLimit           = 5000;
            NamingEnumeration namingEnumeration = null;

            object[] arrayOfObject = new object[] { paramString1 };
            namingEnumeration = paramInitialLdapContext.search(paramString3, paramString4, arrayOfObject, searchControls);
            if (!namingEnumeration.hasMore())
            {
                namingEnumeration.close();
                throw new NamingException("Search of baseDN(" + paramString3 + ") found no matches");
            }
            SearchResult searchResult = (SearchResult)namingEnumeration.next();
            string       str1         = searchResult.Name;
            string       str2         = null;

            if (searchResult.Relative == true)
            {
                str2 = str1 + "," + paramString3;
            }
            else
            {
                throw new NamingException("Can't follow referal for authentication: " + str1);
            }
            namingEnumeration.close();
            namingEnumeration = null;
            InitialLdapContext initialLdapContext = constructInitialLdapContext(str2, paramString2);

            initialLdapContext.close();
            return(str2);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean checkUserExists(String paramString) throws javax.ejb.EJBException
        public virtual bool checkUserExists(string paramString)
        {
            bool          @bool         = false;
            LdapLoginUtil ldapLoginUtil = new LdapLoginUtil(Configuration.Options);

            try
            {
                InitialLdapContext initialLdapContext = ldapLoginUtil.makeLdapInitContext();
                SearchControls     searchControls     = new SearchControls();
                searchControls.SearchScope         = 2;
                searchControls.ReturningAttributes = new string[0];
                searchControls.TimeLimit           = 10000;
                string            str1 = Configuration.Options.get("rolesCtxDN").ToString();
                string            str2 = "(&(objectclass=person)(sAMAccountName=" + paramString + "))";
                NamingEnumeration namingEnumeration = initialLdapContext.search(str1, str2, searchControls);
                if (namingEnumeration.hasMoreElements())
                {
                    @bool = true;
                }
                namingEnumeration.close();
                initialLdapContext.close();
            }
            catch (Exception exception)
            {
                throw new EJBException(exception.Message);
            }
            return(@bool);
        }
Пример #3
0
        public virtual IList <Group> findGroupByQueryCriteria(LdapGroupQuery query)
        {
            ensureContextInitialized();

            string groupBaseDn = composeDn(ldapConfiguration.GroupSearchBase, ldapConfiguration.BaseDn);

            if (ldapConfiguration.SortControlSupported)
            {
                applyRequestControls(query);
            }

            NamingEnumeration <SearchResult> enumeration = null;

            try
            {
                string filter = getGroupSearchFilter(query);
                enumeration = initialContext.search(groupBaseDn, filter, ldapConfiguration.SearchControls);

                // perform client-side paging
                int           resultCount = 0;
                IList <Group> groupList   = new List <Group>();

                StringBuilder resultLogger = new StringBuilder();
                if (LdapPluginLogger.INSTANCE.DebugEnabled)
                {
                    resultLogger.Append("LDAP group query results: [");
                }

                while (enumeration.hasMoreElements() && groupList.Count < query.MaxResults)
                {
                    SearchResult result = enumeration.nextElement();

                    GroupEntity group = transformGroup(result);

                    string groupId = group.Id;

                    if (string.ReferenceEquals(groupId, null))
                    {
                        LdapPluginLogger.INSTANCE.invalidLdapGroupReturned(group, result);
                    }
                    else
                    {
                        if (isAuthorized(READ, GROUP, groupId))
                        {
                            if (resultCount >= query.FirstResult)
                            {
                                if (LdapPluginLogger.INSTANCE.DebugEnabled)
                                {
                                    resultLogger.Append(group);
                                    resultLogger.Append(" based on ");
                                    resultLogger.Append(result);
                                    resultLogger.Append(", ");
                                }

                                groupList.Add(group);
                            }

                            resultCount++;
                        }
                    }
                }

                if (LdapPluginLogger.INSTANCE.DebugEnabled)
                {
                    resultLogger.Append("]");
                    LdapPluginLogger.INSTANCE.groupQueryResult(resultLogger.ToString());
                }

                return(groupList);
            }
            catch (NamingException e)
            {
                throw new IdentityProviderException("Could not query for users", e);
            }
            finally
            {
                try
                {
                    if (enumeration != null)
                    {
                        enumeration.close();
                    }
                }
                catch (Exception)
                {
                    // ignore silently
                }
            }
        }
Пример #4
0
        public virtual IList <User> findUsersWithoutGroupId(LdapUserQueryImpl query, string userBaseDn, bool ignorePagination)
        {
            if (ldapConfiguration.SortControlSupported)
            {
                applyRequestControls(query);
            }

            NamingEnumeration <SearchResult> enumeration = null;

            try
            {
                string filter = getUserSearchFilter(query);
                enumeration = initialContext.search(userBaseDn, filter, ldapConfiguration.SearchControls);

                // perform client-side paging
                int          resultCount = 0;
                IList <User> userList    = new List <User>();

                StringBuilder resultLogger = new StringBuilder();
                if (LdapPluginLogger.INSTANCE.DebugEnabled)
                {
                    resultLogger.Append("LDAP user query results: [");
                }

                while (enumeration.hasMoreElements() && (userList.Count < query.MaxResults || ignorePagination))
                {
                    SearchResult result = enumeration.nextElement();

                    UserEntity user = transformUser(result);

                    string userId = user.Id;

                    if (string.ReferenceEquals(userId, null))
                    {
                        LdapPluginLogger.INSTANCE.invalidLdapUserReturned(user, result);
                    }
                    else
                    {
                        if (isAuthenticatedUser(user) || isAuthorized(READ, USER, userId))
                        {
                            if (resultCount >= query.FirstResult || ignorePagination)
                            {
                                if (LdapPluginLogger.INSTANCE.DebugEnabled)
                                {
                                    resultLogger.Append(user);
                                    resultLogger.Append(" based on ");
                                    resultLogger.Append(result);
                                    resultLogger.Append(", ");
                                }

                                userList.Add(user);
                            }

                            resultCount++;
                        }
                    }
                }

                if (LdapPluginLogger.INSTANCE.DebugEnabled)
                {
                    resultLogger.Append("]");
                    LdapPluginLogger.INSTANCE.userQueryResult(resultLogger.ToString());
                }

                return(userList);
            }
            catch (NamingException e)
            {
                throw new IdentityProviderException("Could not query for users", e);
            }
            finally
            {
                try
                {
                    if (enumeration != null)
                    {
                        enumeration.close();
                    }
                }
                catch (Exception)
                {
                    // ignore silently
                }
            }
        }
Пример #5
0
        protected internal virtual IList <User> findUsersByGroupId(LdapUserQueryImpl query)
        {
            string baseDn = getDnForGroup(query.GroupId);

            // compose group search filter
            string groupSearchFilter = "(& " + ldapConfiguration.GroupSearchFilter + ")";

            NamingEnumeration <SearchResult> enumeration = null;

            try
            {
                enumeration = initialContext.search(baseDn, groupSearchFilter, ldapConfiguration.SearchControls);

                IList <string> groupMemberList = new List <string>();

                // first find group
                while (enumeration.hasMoreElements())
                {
                    SearchResult result          = enumeration.nextElement();
                    Attribute    memberAttribute = result.Attributes.get(ldapConfiguration.GroupMemberAttribute);
                    if (null != memberAttribute)
                    {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: javax.naming.NamingEnumeration<?> allMembers = memberAttribute.getAll();
                        NamingEnumeration <object> allMembers = memberAttribute.All;

                        // iterate group members
                        while (allMembers.hasMoreElements())
                        {
                            groupMemberList.Add((string)allMembers.nextElement());
                        }
                    }
                }

                IList <User> userList    = new List <User>();
                string       userBaseDn  = composeDn(ldapConfiguration.UserSearchBase, ldapConfiguration.BaseDn);
                int          memberCount = 0;
                foreach (string memberId in groupMemberList)
                {
                    if (userList.Count < query.MaxResults && memberCount >= query.FirstResult)
                    {
                        if (ldapConfiguration.UsePosixGroups)
                        {
                            query.userId(memberId);
                        }
                        IList <User> users = ldapConfiguration.UsePosixGroups ? findUsersWithoutGroupId(query, userBaseDn, true) : findUsersWithoutGroupId(query, memberId, true);
                        if (users.Count > 0)
                        {
                            userList.Add(users[0]);
                        }
                    }
                    memberCount++;
                }

                return(userList);
            }
            catch (NamingException e)
            {
                throw new IdentityProviderException("Could not query for users", e);
            }
            finally
            {
                try
                {
                    if (enumeration != null)
                    {
                        enumeration.close();
                    }
                }
                catch (Exception)
                {
                    // ignore silently
                }
            }
        }