コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.util.Collection findUserAndRoleDataByQuery(String paramString) throws javax.ejb.EJBException
        public virtual System.Collections.ICollection findUserAndRoleDataByQuery(string paramString)
        {
            LdapLoginUtil ldapLoginUtil = new LdapLoginUtil(Configuration.Options);
            List <object> arrayList     = new List <object>();

            try
            {
                InitialLdapContext initialLdapContext = ldapLoginUtil.makeLdapInitContext();
                SearchControls     searchControls     = new SearchControls();
                searchControls.SearchScope         = 2;
                searchControls.ReturningAttributes = this.attrIDs;
                searchControls.TimeLimit           = 10000;
                string str1 = Configuration.Options.get("rolesCtxDN").ToString();
                string str2 = str1;
                if (Configuration.Options.get("rolesPlaceCtxDN") != null)
                {
                    str2 = Configuration.Options.get("rolesPlaceCtxDN").ToString();
                }
                string            str3 = "(&(objectclass=person)(|(sAMAccountName=*" + paramString + "*)(name=*" + paramString + "*))(|(memberOf=CN=" + "CESAdmin" + "," + str2 + ")(memberOf=CN=" + "CESDatabaseUser" + "," + str2 + ")))";
                NamingEnumeration namingEnumeration = initialLdapContext.search(str1, str3, searchControls);
                while (namingEnumeration.hasMoreElements())
                {
                    arrayList.Add(resultToUserRolesData((SearchResult)namingEnumeration.nextElement(), initialLdapContext, ldapLoginUtil, false));
                }
                initialLdapContext.close();
            }
            catch (Exception exception)
            {
                throw new EJBException(exception.Message);
            }
            return(arrayList);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Search.cs プロジェクト: marinakotuseva/isblScan
 public void TextArea_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
 {
     if (e.Key == Key.Enter && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0)
     {
         SearchControls.Process();
     }
     if (e.Key == Key.T && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0)
     {
         new MainForm.SearchControls(SearchControls._form);
     }
     if (e.Key == Key.F2)
     {
         SearchControls.TreeSelectNextMatched(SearchControls.TreeViewResults.Nodes);
     }
     if (e.Key == Key.F3)
     {
         SearchControls.TextEditorShowNextMatchedString();
     }
     if (e.Key == Key.O && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0)
     {
         var selectedNode = SearchControls.TreeViewResults.SelectedNode;
         if (selectedNode != null)
         {
             ((SearchNode)selectedNode.Tag).IsbNode.OpenInSbrte(IsbDev.ConnectionParams);
         }
     }
 }
コード例 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public UserAndRolesData getUserAndRoleData(String paramString) throws javax.ejb.EJBException
        public virtual UserAndRolesData getUserAndRoleData(string paramString)
        {
            LdapLoginUtil    ldapLoginUtil    = new LdapLoginUtil(Configuration.Options);
            UserAndRolesData userAndRolesData = null;

            try
            {
                InitialLdapContext initialLdapContext = ldapLoginUtil.makeLdapInitContext();
                SearchControls     searchControls     = new SearchControls();
                searchControls.SearchScope         = 2;
                searchControls.ReturningAttributes = this.attrIDs;
                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())
                {
                    userAndRolesData = resultToUserRolesData((SearchResult)namingEnumeration.nextElement(), initialLdapContext, ldapLoginUtil, true);
                }
                else
                {
                    throw new RemoteException(paramString + " was not found, it may have been deleted.");
                }
                initialLdapContext.close();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
                throw new EJBException(exception.Message);
            }
            return(userAndRolesData);
        }
コード例 #5
0
//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);
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private UserAndRolesData resultToUserRolesData(javax.naming.directory.SearchResult paramSearchResult, javax.naming.ldap.InitialLdapContext paramInitialLdapContext, LdapLoginUtil paramLdapLoginUtil, boolean paramBoolean) throws Exception
        private UserAndRolesData resultToUserRolesData(SearchResult paramSearchResult, InitialLdapContext paramInitialLdapContext, LdapLoginUtil paramLdapLoginUtil, bool paramBoolean)
        {
            UserAndRolesData userAndRolesData = new UserAndRolesData();
            PrincipalsData   principalsData   = new PrincipalsData();
            Attributes       attributes       = paramSearchResult.Attributes;
            string           str1             = StringUtils.getValueFromAttribute(attributes.get("displayName"));
            string           str2             = StringUtils.getValueFromAttribute(attributes.get("description"));
            string           str3             = StringUtils.getValueFromAttribute(attributes.get("sAMAccountName"));
            string           str4             = StringUtils.getValueFromAttribute(attributes.get("userPrincipalName"));

            if (string.ReferenceEquals(str3, null))
            {
                throw new Exception("sAMAccountName not found for: " + paramSearchResult.Name);
            }
            if (string.ReferenceEquals(str1, null))
            {
                str1 = str3;
            }
            if (string.ReferenceEquals(str4, null))
            {
                str4 = "";
            }
            principalsData.Name             = str1;
            principalsData.EMail            = str4;
            principalsData.PrincipalId      = str3;
            principalsData.Password         = "******";
            userAndRolesData.PrincipalsData = principalsData;
            if (!paramBoolean)
            {
                userAndRolesData.RolesData = new RolesData[0];
            }
            else
            {
                SearchControls searchControls = new SearchControls();
                searchControls.SearchScope         = 2;
                searchControls.ReturningAttributes = this.attrIDs;
                searchControls.TimeLimit           = 10000;
                string str5 = str3 + "," + Configuration.Options.get("baseCtxDN");
                string str6 = (string)Configuration.Options.get("roleRecursion");
                int    i    = 0;
                try
                {
                    i = int.Parse(str6);
                }
                catch (Exception)
                {
                    i = 0;
                }
                System.Collections.IList list      = paramLdapLoginUtil.findRolesOfUser(paramInitialLdapContext, searchControls, str3, str5, i, 0);
                List <object>            arrayList = new List <object>(list.Count);
                foreach (string str in list)
                {
                    arrayList.Add(new RolesData(str, str3, str, "Roles"));
                }
                userAndRolesData.RolesData = (RolesData[])arrayList.ToArray(typeof(RolesData));
            }
            return(userAndRolesData);
        }
コード例 #7
0
 public void SearchForm(SearchControls searchControls)
 {
     if (searchControls.HasFlag(SearchControls.Search))
     {
         CreateAndAddSearchControl();
     }
     if (searchControls.HasFlag(SearchControls.Replace))
     {
         CreateAndAddReplaceControl();
     }
     if (searchControls.HasFlag(SearchControls.RecentSearches))
     {
         CreateAndAddRecentSearchesControl();
     }
 }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.Set<String> authorize(javax.naming.ldap.LdapContext ctx, String username) throws javax.naming.NamingException
        private ISet <string> Authorize(LdapContext ctx, string username)
        {
            ISet <string> roleNames = new LinkedHashSet <string>();

            // Setup our search controls
            SearchControls searchCtls = new SearchControls();

            searchCtls.SearchScope         = SearchControls.SUBTREE_SCOPE;
            searchCtls.ReturningAttributes = new string[] { GROUP_ID };

            // Use a search argument to prevent potential code injection
            object[] searchArguments = new object[] { username };

            // Search for groups that has the user as a member
            NamingEnumeration result = ctx.search(GROUP_SEARCH_BASE, GROUP_SEARCH_FILTER, searchArguments, searchCtls);

            if (result.hasMoreElements())
            {
                SearchResult searchResult = ( SearchResult )result.next();

                Attributes attributes = searchResult.Attributes;
                if (attributes != null)
                {
                    NamingEnumeration attributeEnumeration = attributes.All;
                    while (attributeEnumeration.hasMore())
                    {
                        Attribute attribute   = ( Attribute )attributeEnumeration.next();
                        string    attributeId = attribute.ID;
                        if (attributeId.Equals(GROUP_ID, StringComparison.OrdinalIgnoreCase))
                        {
                            // We found a group that the user is a member of. See if it has a role mapped to it
                            string groupId    = ( string )attribute.get();
                            string neo4jGroup = GetNeo4jRoleForGroupId(groupId);
                            if (!string.ReferenceEquals(neo4jGroup, null))
                            {
                                // Yay! Add it to our set of roles
                                roleNames.Add(neo4jGroup);
                            }
                        }
                    }
                }
            }
            return(roleNames);
        }
コード例 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.apache.shiro.authc.AuthenticationInfo queryForAuthenticationInfoSAM(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.realm.ldap.LdapContextFactory ldapContextFactory) throws javax.naming.NamingException
        private AuthenticationInfo QueryForAuthenticationInfoSAM(AuthenticationToken token, LdapContextFactory ldapContextFactory)
        {
            object principal   = token.Principal;
            object credentials = token.Credentials;

            LdapContext ctx = null;

            try
            {
                ctx = _useStartTls ? GetSystemLdapContextUsingStartTls(ldapContextFactory) : ldapContextFactory.SystemLdapContext;
                string[]       attrs                    = new string[] { "cn" };
                SearchControls searchCtls               = new SearchControls(SearchControls.SUBTREE_SCOPE, 1, 0, attrs, false, false);
                object[]       searchArguments          = new object[] { principal };
                string         filter                   = "sAMAccountName={0}";
                NamingEnumeration <SearchResult> search = ctx.search(_userSearchBase, filter, searchArguments, searchCtls);
                if (search.hasMore())
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final javax.naming.directory.SearchResult next = search.next();
                    SearchResult next      = search.next();
                    string       loginUser = next.NameInNamespace;
                    if (search.hasMore())
                    {
                        _securityLog.error("More than one user matching: " + principal);
                        throw new AuthenticationException("More than one user matching: " + principal);
                    }
                    else
                    {
                        LdapContext ctx2 = ldapContextFactory.getLdapContext(loginUser, credentials);
                        LdapUtils.closeContext(ctx2);
                    }
                }
                else
                {
                    throw new AuthenticationException("No user matching: " + principal);
                }
                return(CreateAuthenticationInfo(token, principal, credentials, ctx));
            }
            finally
            {
                LdapUtils.closeContext(ctx);
            }
        }
コード例 #10
0
        // TODO: Extract to an LdapAuthorizationStrategy ? This ("group by attribute") is one of multiple possible strategies
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: java.util.Set<String> findRoleNamesForUser(String username, javax.naming.ldap.LdapContext ldapContext) throws javax.naming.NamingException
        internal virtual ISet <string> FindRoleNamesForUser(string username, LdapContext ldapContext)
        {
            ISet <string> roleNames = new LinkedHashSet <string>();

            SearchControls searchCtls = new SearchControls();

            searchCtls.SearchScope         = SearchControls.SUBTREE_SCOPE;
            searchCtls.ReturningAttributes = _membershipAttributeNames.ToArray();

            // Use search argument to prevent potential code injection
            object[] searchArguments = new object[] { username };

            NamingEnumeration result = ldapContext.search(_userSearchBase, _userSearchFilter, searchArguments, searchCtls);

            if (result.hasMoreElements())
            {
                SearchResult searchResult = ( SearchResult )result.next();

                if (result.hasMoreElements())
                {
                    _securityLog.warn(_securityLog.DebugEnabled ? WithRealm("LDAP user search for user principal '%s' is ambiguous. The first match that will " + "be checked for group membership is '%s' but the search also matches '%s'. " + "Please check your LDAP realm configuration.", username, searchResult.ToString(), result.next().ToString()) : WithRealm("LDAP user search for user principal '%s' is ambiguous. The search matches more " + "than one entry. Please check your LDAP realm configuration.", username));
                }

                Attributes attributes = searchResult.Attributes;
                if (attributes != null)
                {
                    NamingEnumeration attributeEnumeration = attributes.All;
                    while (attributeEnumeration.hasMore())
                    {
                        Attribute attribute   = ( Attribute )attributeEnumeration.next();
                        string    attributeId = attribute.ID;
                        if (_membershipAttributeNames.Any(attributeId.equalsIgnoreCase))
                        {
                            ICollection <string> groupNames     = LdapUtils.getAllAttributeValues(attribute);
                            ICollection <string> rolesForGroups = GetRoleNamesForGroups(groupNames);
                            roleNames.addAll(rolesForGroups);
                        }
                    }
                }
            }
            return(roleNames);
        }
コード例 #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void rolesSearch(javax.naming.ldap.InitialLdapContext paramInitialLdapContext, javax.naming.directory.SearchControls paramSearchControls, String paramString1, String paramString2, int paramInt1, int paramInt2) throws javax.naming.NamingException
        protected internal virtual void rolesSearch(InitialLdapContext paramInitialLdapContext, SearchControls paramSearchControls, string paramString1, string paramString2, int paramInt1, int paramInt2)
        {
            object[] arrayOfObject = new object[] { paramString1, paramString2 };
            namingEnumeration = paramInitialLdapContext.search(this.rolesCtxDN, this.roleFilter, arrayOfObject, paramSearchControls);
            try
            {
                while (namingEnumeration.hasMore())
                {
                    SearchResult searchResult = (SearchResult)namingEnumeration.next();
                    string       str          = canonicalize(searchResult.Name);
                    if (paramInt2 == 0 && this.roleAttributeIsDN && !string.ReferenceEquals(this.roleNameAttributeID, null))
                    {
                        if (this.parseRoleNameFromDN)
                        {
                            parseRole(str);
                        }
                        else
                        {
                            string[]   arrayOfString1 = new string[] { this.roleNameAttributeID };
                            Attributes attributes1    = paramInitialLdapContext.getAttributes(str, arrayOfString1);
                            Attribute  attribute      = attributes1.get(this.roleNameAttributeID);
                            if (attribute != null)
                            {
                                for (sbyte b = 0; b < attribute.size(); b++)
                                {
                                    string str1 = (string)attribute.get(b);
                                    addRole(str1);
                                }
                            }
                        }
                    }
                    string[]   arrayOfString = new string[] { this.roleAttributeID };
                    Attributes attributes    = paramInitialLdapContext.getAttributes(str, arrayOfString);
                    if (attributes != null && attributes.size() > 0)
                    {
                        Attribute attribute = attributes.get(this.roleAttributeID);
                        for (sbyte b = 0; b < attribute.size(); b++)
                        {
                            string str1 = (string)attribute.get(b);
                            if (this.roleAttributeIsDN && this.parseRoleNameFromDN)
                            {
                                parseRole(str1);
                            }
                            else if (this.roleAttributeIsDN)
                            {
                                string   str2           = str1;
                                string[] arrayOfString1 = new string[] { this.roleNameAttributeID };
                                try
                                {
                                    Attributes attributes1 = paramInitialLdapContext.getAttributes(str2, arrayOfString1);
                                    Attribute  attribute1  = attributes1.get(this.roleNameAttributeID);
                                    if (attribute1 != null)
                                    {
                                        for (sbyte b1 = 0; b1 < attribute1.size(); b1++)
                                        {
                                            str1 = (string)attribute1.get(b1);
                                            addRole(str1);
                                        }
                                    }
                                }
                                catch (NamingException)
                                {
                                }
                            }
                            else
                            {
                                addRole(str1);
                            }
                        }
                    }
                    if (paramInt2 < paramInt1)
                    {
                        rolesSearch(paramInitialLdapContext, paramSearchControls, paramString1, str, paramInt1, paramInt2 + 1);
                    }
                }
            }
            finally
            {
                if (namingEnumeration != null)
                {
                    namingEnumeration.close();
                }
            }
        }
コード例 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.util.List<String> findRolesOfUser(javax.naming.ldap.InitialLdapContext paramInitialLdapContext, javax.naming.directory.SearchControls paramSearchControls, String paramString1, String paramString2, int paramInt1, int paramInt2) throws javax.naming.NamingException
        public virtual IList <string> findRolesOfUser(InitialLdapContext paramInitialLdapContext, SearchControls paramSearchControls, string paramString1, string paramString2, int paramInt1, int paramInt2)
        {
            this.userRoles = new List <object>();
            rolesSearch(paramInitialLdapContext, paramSearchControls, paramString1, paramString2, paramInt1, paramInt2);
            return(this.userRoles);
        }
コード例 #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean createLdapInitContext(String paramString, Object paramObject) throws Exception
        private bool createLdapInitContext(string paramString, object paramObject)
        {
            this.bindDN         = (string)this.options.get("bindDN");
            this.bindCredential = (string)this.options.get("bindCredential");
            string str1 = (string)this.options.get("jaasSecurityDomain");

            if (!string.ReferenceEquals(str1, null))
            {
                ObjectName objectName  = new ObjectName(str1);
                char[]     arrayOfChar = DecodeAction.decode(this.bindCredential, objectName);
                this.bindCredential = new string(arrayOfChar);
            }
            this.baseDN          = (string)this.options.get("baseCtxDN");
            this.baseFilter      = (string)this.options.get("baseFilter");
            this.roleFilter      = (string)this.options.get("roleFilter");
            this.roleAttributeID = (string)this.options.get("roleAttributeID");
            if (string.ReferenceEquals(this.roleAttributeID, null))
            {
                this.roleAttributeID = "role";
            }
            string str2 = (string)this.options.get("roleAttributeIsDN");

            this.roleAttributeIsDN   = Convert.ToBoolean(str2);
            this.roleNameAttributeID = (string)this.options.get("roleNameAttributeID");
            if (string.ReferenceEquals(this.roleNameAttributeID, null))
            {
                this.roleNameAttributeID = "name";
            }
            string str3 = (string)this.options.get("parseRoleNameFromDN");

            this.parseRoleNameFromDN = Convert.ToBoolean(str3);
            this.rolesCtxDN          = (string)this.options.get("rolesCtxDN");
            string str4 = (string)this.options.get("roleRecursion");

            try
            {
                this.recursion = int.Parse(str4);
            }
            catch (Exception)
            {
                if (this.trace)
                {
                    this.log.trace("Failed to parse: " + str4 + ", disabling recursion");
                }
                this.recursion = 0;
            }
            string str5 = (string)this.options.get("searchTimeLimit");

            if (!string.ReferenceEquals(str5, null))
            {
                try
                {
                    this.searchTimeLimit = int.Parse(str5);
                }
                catch (System.FormatException)
                {
                    if (this.trace)
                    {
                        this.log.trace("Failed to parse: " + str5 + ", using searchTimeLimit=" + this.searchTimeLimit);
                    }
                }
            }
            string str6 = (string)this.options.get("searchScope");

            if ("OBJECT_SCOPE".Equals(str6, StringComparison.OrdinalIgnoreCase))
            {
                this.searchScope = 0;
            }
            else if ("ONELEVEL_SCOPE".Equals(str6, StringComparison.OrdinalIgnoreCase))
            {
                this.searchScope = 1;
            }
            if ("SUBTREE_SCOPE".Equals(str6, StringComparison.OrdinalIgnoreCase))
            {
                this.searchScope = 2;
            }
            initialLdapContext = null;
            try
            {
                initialLdapContext = constructInitialLdapContext(this.bindDN, this.bindCredential);
                string         str            = bindDNAuthentication(initialLdapContext, paramString, paramObject, this.baseDN, this.baseFilter);
                SearchControls searchControls = new SearchControls();
                searchControls.SearchScope         = this.searchScope;
                searchControls.ReturningAttributes = new string[0];
                searchControls.TimeLimit           = this.searchTimeLimit;
                rolesSearch(initialLdapContext, searchControls, paramString, str, this.recursion, 0);
            }
            finally
            {
                if (initialLdapContext != null)
                {
                    initialLdapContext.close();
                }
            }
            return(true);
        }