//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); }
//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); }
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 } } }
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 } } }
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 } } }