Encapsulates parameters of an Ldap URL query as defined in RFC2255. An LdapUrl object can be passed to LdapConnection.search to retrieve search results.
상속: System.ICloneable
		/// <summary>
		/// Initializes the Entry specific properties e.g entry DN etc.
		/// </summary>
		void InitEntry()
		{			
			LdapUrl lUrl = new LdapUrl (ADsPath);
			string dn = lUrl.getDN();
			if (dn != null ) {
				if (String.Compare (dn,"rootDSE",true) == 0)
					InitToRootDse (lUrl.Host,lUrl.Port);
				else {
				DN userDn = new DN (dn);
				String[] lRdn = userDn.explodeDN(false);
				_Name = (string)lRdn[0];
				_Parent = new DirectoryEntry(conn);
				_Parent.Path = GetLdapUrlString (lUrl.Host,lUrl.Port,userDn.Parent.ToString ());
				}
			}
			else			{
				_Name=lUrl.Host+":"+lUrl.Port;
				_Parent = new DirectoryEntry(conn);
				_Parent.Path = "Ldap:";
			}
		}
예제 #2
0
 /// <summary> Construct the ReferralInfo class
 /// 
 /// </summary>
 /// <param name="lc">The DirectoryEntry opened to process this referral
 /// 
 /// </param>
 /// <param name="refUrl">The URL string associated with this connection
 /// </param>
 public ReferralInfo(LdapConnection lc, System.String[] refList, LdapUrl refUrl)
 {
     conn = lc;
     referralUrl = refUrl;
     referralList = refList;
     return ;
 }
 /// <summary> Construct the ReferralInfo class
 ///
 /// </summary>
 /// <param name="lc">The DirectoryEntry opened to process this referral
 ///
 /// </param>
 /// <param name="refUrl">The URL string associated with this connection
 /// </param>
 public ReferralInfo(LdapConnection lc, System.String[] refList, LdapUrl refUrl)
 {
     conn         = lc;
     referralUrl  = refUrl;
     referralList = refList;
     return;
 }
		private void InitBlock()
		{
			_conn = new LdapConnection();
			LdapUrl lUrl=new LdapUrl(SearchRoot.Path);
			_Host=lUrl.Host;
			_Port=lUrl.Port;
			_conn.Connect(_Host,_Port);
			_conn.Bind(SearchRoot.Username,SearchRoot.Password);

		}
예제 #5
0
		private void InitBlock()
		{
			_conn = new LdapConnection();
			LdapUrl lUrl=new LdapUrl(SearchRoot.ADsPath);
			_Host=lUrl.Host;
			_Port=lUrl.Port;
			_conn.Connect(_Host,_Port);
			_conn.Bind(SearchRoot.Username,SearchRoot.Password,(Novell.Directory.Ldap.AuthenticationTypes)SearchRoot.AuthenticationType);

		}
		/// <summary> Initializes the Connection and other properties.
		/// 
		/// </summary>
		private void InitBlock()
		{
			try			{
				LdapUrl lUrl=new LdapUrl(_Bpath);
				_Conn = new LdapConnection();
				_Conn.Connect(lUrl.Host,lUrl.Port);
				_Conn.Bind(_Buser,_Bpass);
			}
			catch(LdapException ex)			{
				throw ex;
			}
			catch(Exception e)				{
				throw e;
			}
		}
		/// <summary> Initializes the Connection and other properties.
		/// 
		/// </summary>
		private void InitBlock()
		{
			try			{
				_conn= new LdapConnection ();
				LdapUrl lUrl = new LdapUrl (ADsPath);
				_conn.Connect(lUrl.Host,lUrl.Port);
				_conn.Bind(Username,Password, (Novell.Directory.Ldap.AuthenticationTypes)AuthenticationType);
			}
			catch(LdapException ex)			{
				throw ex;
			}
			catch(Exception e)			{
				throw e;
			}
		}
		internal static string GetLdapUrlString(string host, int port, string dn)
		{
			LdapUrl lUrl;
			if (port == LdapConnection.DEFAULT_PORT)
				lUrl = new LdapUrl (host,0,dn);
			else
				lUrl = new LdapUrl (host,port,dn);
			return lUrl.ToString();
		}
예제 #9
0
파일: ReferralInfo.cs 프로젝트: cmsd2/oidc
 /// <summary> Construct the ReferralInfo class
 ///
 /// </summary>
 /// <param name="lc">The DirectoryEntry opened to process this referral
 ///
 /// </param>
 /// <param name="refUrl">The URL string associated with this connection
 /// </param>
 public ReferralInfo(LdapConnection lc, string[] refList, LdapUrl refUrl)
 {
     conn         = lc;
     referralUrl  = refUrl;
     referralList = refList;
 }
예제 #10
0
		/*
		* Ldap URL search
		*/
		
		/// <summary> Synchronously performs the search specified by the Ldap URL, returning
		/// an enumerable LdapSearchResults object.
		/// 
		/// </summary>
		/// <param name="toGet">The Ldap URL specifying the entry to read.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public static LdapSearchResults Search(LdapUrl toGet)
		{
			// Get a clone of default search constraints, method alters batchSize
			return Search(toGet, null);
		}
		/// <summary>
		/// Searches the directory store at the specified path to see whether 
		/// an entry exists
		/// </summary>
		/// <param name="path">
		/// The path at which to search the directory store. 
		/// </param>
		/// <returns>
		/// true if an entry exists in the directory store at the specified 
		/// path; otherwise, false.
		/// </returns>
		public static bool Exists(string path)
		{
			LdapConnection aconn=new LdapConnection();
			LdapUrl lurl=new LdapUrl(path);
			aconn.Connect(lurl.Host,lurl.Port);
			aconn.Bind("","");
			if(CheckEntry(aconn,path))
				return true;
			else
				return false;
		}
		/// <summary>
		/// Checks whether the entry with the specified Relative distinguised name
		/// exists or not.
		/// </summary>
		/// <param name="rdn"> Relative distinguished name of the entry</param>
		/// <returns>DirectoryEntry object of Entry if entry exists,
		/// Null if entry doesn't exist </returns>
		private DirectoryEntry CheckEntry(string rdn)
		{
			string Ofdn=null;
			DirectoryEntry cEntry=null;

			Ofdn=rdn+","+Basedn;
			string[] attrs={"objectClass"};
			try										{
				LdapSearchResults lsc= Conn.Search(	Ofdn,
													LdapConnection.SCOPE_BASE,
													"objectClass=*",
													attrs,
													false);
				while(lsc.hasMore())				{
					LdapEntry nextEntry = null;
					try								{
						nextEntry = lsc.next();
						cEntry =  new DirectoryEntry(Conn);
						LdapUrl Burl=new LdapUrl(_Bpath);
						LdapUrl curl=new LdapUrl(Burl.Host,Burl.Port,Ofdn);
						cEntry.Path=curl.ToString();
					}
					catch(LdapException e) 			{
						// Exception is thrown, go for next entry
						throw e;
					}
					break;
				}

			}
			catch(LdapException le)
			{
				if(le.ResultCode == LdapException.NO_SUCH_OBJECT)	{
					return null;
				}
				else		{
					throw le;
				}
			}
			catch(Exception e)		{
				throw e;
			}
			return cEntry;
		}
		/// <summary>
		/// Deletes a child DirectoryEntry from this collection
		/// </summary>
		/// <param name="entry">The DirectoryEntry to delete</param>
		public void Remove(	DirectoryEntry entry )
		{
			LdapUrl Burl=new LdapUrl(_Bpath);
			string eFDN = entry.Name + "," + Burl.getDN();
			Conn.Delete( eFDN);
		}
		/// <summary> Creates a request to create a new entry in the container.
		/// 
		/// </summary>
		/// <param name="name"> RDN of the entry to be created
		/// </param>
		/// <param name="schemaClassName"> StructuralClassName of the entry to be
		/// created.
		/// </param>
		public DirectoryEntry Add(	string name,string schemaClassName)
		{
			DirectoryEntry ent=new DirectoryEntry(Conn);
			LdapUrl Burl=new LdapUrl(_Bpath);
			string eFdn=name+","+Burl.getDN();
			LdapUrl curl=new LdapUrl(Burl.Host,Burl.Port,eFdn);
			ent.Path=curl.ToString();
			ent.Nflag = true;
			return ent;
		}
		public  IEnumerator GetEnumerator()
		{
			m_oValues= new ArrayList();
			string[] attrs={"objectClass"};
			LdapSearchResults lsc= Conn.Search(	Basedn,
												LdapConnection.SCOPE_ONE,
												"objectClass=*",
												attrs,
												false);

			LdapUrl Burl=new LdapUrl(_Bpath);
			string host=Burl.Host;
			int port=Burl.Port;

			while (lsc.hasMore())			{
				LdapEntry nextEntry = null;
				try					{
					nextEntry = lsc.next();
				}
				catch(LdapException e) 		{
					// Exception is thrown, go for next entry
					continue;
				}
				DirectoryEntry dEntry=new DirectoryEntry(Conn);
				string eFdn=nextEntry.DN;
				LdapUrl curl=new LdapUrl(host,port,eFdn);
				dEntry.Path=curl.ToString();
				m_oValues.Add((DirectoryEntry) dEntry);
			}
			return m_oValues.GetEnumerator();
		}
		private void InitToRootDse(string host,int port)
		{
			if ( host == null )
				host = DefaultHost;
			if ( port < 0 )
				port = DefaultPort;	
		
			LdapUrl rootPath = new LdapUrl (host,port,String.Empty);
			string [] attrs = new string [] {"+","*"};
			DirectoryEntry rootEntry = new DirectoryEntry (rootPath.ToString (),this.Username,this.Password,this.AuthenticationType);
			DirectorySearcher searcher = new DirectorySearcher (rootEntry,null,attrs,SearchScope.Base);

			SearchResult result = searcher.FindOne ();			
			// copy properties from search result
			PropertyCollection pcoll = new PropertyCollection ();
			foreach (string propertyName in result.Properties.PropertyNames) {
				System.Collections.IEnumerator enumerator = result.Properties [propertyName].GetEnumerator ();
				if (enumerator != null)
					while (enumerator.MoveNext ())
						if (String.Compare (propertyName,"ADsPath",true) != 0)
							pcoll [propertyName].Add (enumerator.Current);
			}			
			this.SetProperties (pcoll);
			this._Name = "rootDSE";
		}
		/// <summary>
		/// Checks whether the entry exists in the Ldap directory or not
		/// </summary>
		/// <param name="lconn">
		/// Connection used to communicate with directory
		/// </param>
		/// <param name="epath">
		/// path of the entry
		/// </param>
		/// <returns>
		///		true of the entry exists in the Ldap directory
		///		false if entry doesn't exists
		/// </returns>
		private static bool CheckEntry(LdapConnection lconn, string epath)
		{
			LdapUrl lUrl=new LdapUrl(epath);
			string eDn=lUrl.getDN();
			if(eDn==null)
			{
				eDn = String.Empty;
			}
			// rootDSE is a "virtual" entry that always exists
			else if (String.Compare (eDn,"rootDSE",true) == 0)
				return true;

			string[] attrs={"objectClass"};
			try
			{
				LdapSearchResults lsc=lconn.Search(	eDn,
					LdapConnection.SCOPE_BASE,
					"objectClass=*",
					attrs,
					false);
				while(lsc.hasMore())
				{
					LdapEntry nextEntry = null;
					try 
					{
						nextEntry = lsc.next();
					}
					catch(LdapException e) 
					{
						// Exception is thrown, go for next entry
						throw e;
					}
					break;
				}

			}
			catch(LdapException le)
			{
				if(le.ResultCode == LdapException.NO_SUCH_OBJECT)
				{
					return false;
				}
				else
				{
					throw le;
				}
			}
			catch(Exception e)
			{
				throw e;
			}
			return true;
		}
		/// <summary> Initializes the Connection and other properties.
		/// 
		/// </summary>
		private void InitBlock()
		{
			try			{
				_conn= new LdapConnection ();
				LdapUrl lUrl=new LdapUrl (Path);
				_conn.Connect(lUrl.Host,lUrl.Port);
				_conn.Bind(Username,Password);
			}
			catch(LdapException ex)			{
				throw ex;
			}
			catch(Exception e)			{
				throw e;
			}
		}
예제 #19
0
		/// <summary> Synchronously reads the entry specified by the Ldap URL, using the
		/// specified constraints.
		/// 
		/// When this method is called, a new connection is created
		/// automatically, using the host and port specified in the URL. After
		/// finding the entry, the method closes the connection (in other words,
		/// it disconnects from the Ldap server).
		/// 
		/// If the URL specifies a filter and scope, they are not used. Of the
		/// information specified in the URL, this method only uses the Ldap host
		/// name and port number, the base distinguished name (DN), and the list
		/// of attributes to return.
		/// 
		/// </summary>
		/// <returns> The entry specified by the base DN.
		/// 
		/// </returns>
		/// <param name="toGet">      Ldap URL specifying the entry to read.
		/// 
		/// </param>
		/// <param name="cons">      Constraints specific to the operation.
		/// 
		/// </param>
		/// <exception> LdapException if the object was not found
		/// </exception>
		public static LdapEntry Read(LdapUrl toGet, LdapSearchConstraints cons)
		{
			LdapConnection lconn = new LdapConnection();
			lconn.Connect(toGet.Host, toGet.Port);
			LdapEntry toReturn = lconn.Read(toGet.getDN(), toGet.AttributeArray, cons);
			lconn.Disconnect();
			return toReturn;
		}
		/// <summary>
		/// Initializes the Entry specific properties e.g entry DN etc.
		/// </summary>
		void InitEntry()
		{
			LdapUrl lUrl=new LdapUrl (Path);
			if(lUrl.getDN()!=null)			{
				DN userDn = new DN(lUrl.getDN());
				String[] lRdn = userDn.explodeDN(false);
				_Name = (string)lRdn[0];
				_Parent = new DirectoryEntry(conn);
				LdapUrl cUrl=new LdapUrl(lUrl.Host,lUrl.Port,userDn.Parent.ToString());
				_Parent.Path=cUrl.ToString();
			}
			else			{
				_Name=lUrl.Host+":"+lUrl.Port;
				_Parent = new DirectoryEntry(conn);
				_Parent.Path = "Ldap:";
			}
		}
예제 #21
0
		/// <summary> Builds a new request replacing dn, scope, and filter where approprate
		/// 
		/// </summary>
		/// <param name="msg">the original LdapMessage to build the new request from
		/// 
		/// </param>
		/// <param name="url">the referral url
		/// 
		/// </param>
		/// <returns> a new LdapMessage with appropriate information replaced
		/// 
		/// </returns>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		private LdapMessage rebuildRequest(LdapMessage msg, LdapUrl url, bool reference)
		{
			
			System.String dn = url.getDN(); // new base
			System.String filter = null;
			
			switch (msg.Type)
			{
				
				case LdapMessage.SEARCH_REQUEST: 
					if (reference)
					{
						filter = url.Filter;
					}
					break;
					// We are allowed to get a referral for the following
				
				case LdapMessage.ADD_REQUEST: 
				case LdapMessage.BIND_REQUEST: 
				case LdapMessage.COMPARE_REQUEST: 
				case LdapMessage.DEL_REQUEST: 
				case LdapMessage.EXTENDED_REQUEST: 
				case LdapMessage.MODIFY_RDN_REQUEST: 
				case LdapMessage.MODIFY_REQUEST: 
					break;
					// The following return no response
				
				case LdapMessage.ABANDON_REQUEST: 
				case LdapMessage.UNBIND_REQUEST: 
				default: 
					throw new LdapLocalException(ExceptionMessages.IMPROPER_REFERRAL, new System.Object[]{msg.Type}, LdapException.LOCAL_ERROR);
			}
			
			return msg.Clone(dn, filter, reference);
		}
예제 #22
0
		/// <summary> get an LdapConnection object so that we can follow a referral.
		/// This function is never called if cons.getReferralFollowing() returns
		/// false.
		/// 
		/// </summary>
		/// <param name="referrals">the array of referral strings
		/// 
		/// 
		/// </param>
		/// <returns> The referralInfo object
		/// 
		/// </returns>
		/// <exception> LdapReferralException A general exception which includes
		/// an error message and an Ldap error code.
		/// </exception>
		private ReferralInfo getReferralConnection(System.String[] referrals)
		{
			ReferralInfo refInfo = null;
			System.Exception ex = null;
			LdapConnection rconn = null;
			LdapReferralHandler rh = defSearchCons.getReferralHandler();
			int i = 0;
			// Check if we use LdapRebind to get authentication credentials
			if ((rh == null) || (rh is LdapAuthHandler))
			{
				for (i = 0; i < referrals.Length; i++)
				{
					// dn, pw are null in the default case (anonymous bind)
					System.String dn = null;
					sbyte[] pw = null;
					try
					{
						rconn = new LdapConnection();
						rconn.Constraints = defSearchCons;
						LdapUrl url = new LdapUrl(referrals[i]);
						rconn.Connect(url.Host, url.Port);
						if (rh != null)
						{
							if (rh is LdapAuthHandler)
							{
								// Get application supplied dn and pw
								LdapAuthProvider ap = ((LdapAuthHandler) rh).getAuthProvider(url.Host, url.Port);
								dn = ap.DN;
								pw = ap.Password;
							}
						}
						rconn.Bind(Ldap_V3, dn, pw);
						ex = null;
						refInfo = new ReferralInfo(rconn, referrals, url);
						// Indicate this connection created to follow referral
						rconn.Connection.ActiveReferral = refInfo;
						break;
					}
					catch (System.Exception lex)
					{
						if (rconn != null)
						{
							try
							{
								rconn.Disconnect();
								rconn = null;
								ex = lex;
							}
							catch (LdapException e)
							{
								; // ignore
							}
						}
					}
				}
			}
				// Check if application gets connection and does bind
			else
			{
				//  rh instanceof LdapBind
				try
				{
					rconn = ((LdapBindHandler) rh).Bind(referrals, this);
					if (rconn == null)
					{
						LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERRAL_ERROR);
						rex.setReferrals(referrals);
						throw rex;
					}
					// Figure out which Url belongs to the connection
					for (int idx = 0; idx < referrals.Length; idx++)
					{
						try
						{
							LdapUrl url = new LdapUrl(referrals[idx]);
							if (url.Host.ToUpper().Equals(rconn.Host.ToUpper()) && (url.Port == rconn.Port))
							{
								refInfo = new ReferralInfo(rconn, referrals, url);
								break;
							}
						}
						catch (System.Exception e)
						{
							; // ignore
						}
					}
					if (refInfo == null)
					{
						// Could not match LdapBind.bind() connecction with URL list
						ex = new LdapLocalException(ExceptionMessages.REFERRAL_BIND_MATCH, LdapException.CONNECT_ERROR);
					}
				}
				catch (System.Exception lex)
				{
					rconn = null;
					ex = lex;
				}
			}
			if (ex != null)
			{
				// Could not connect to any server, throw an exception
				LdapException ldapex;
				if (ex is LdapReferralException)
				{
					throw (LdapReferralException) ex;
				}
				else if (ex is LdapException)
				{
					ldapex = (LdapException) ex;
				}
				else
				{
					ldapex = new LdapLocalException(ExceptionMessages.SERVER_CONNECT_ERROR, new System.Object[]{conn.Host}, LdapException.CONNECT_ERROR, ex);
				}
				// Error attempting to follow a referral
				LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERRAL_ERROR, ldapex);
				rex.setReferrals(referrals);
				// Use last URL string for the failed referral
				rex.FailedReferral = referrals[referrals.Length - 1];
				throw rex;
			}
			
			// We now have an authenticated connection
			// to be used to follow the referral.
			return refInfo;
		}
예제 #23
0
		/// <summary> Creates a request to create a new entry in the container.
		/// 
		/// </summary>
		/// <param name="name"> RDN of the entry to be created
		/// </param>
		/// <param name="schemaClassName"> StructuralClassName of the entry to be
		/// created.
		/// </param>
		public DirectoryEntry Add(	string name,string schemaClassName)
		{
			DirectoryEntry ent=new DirectoryEntry(Conn);
			LdapUrl Burl=new LdapUrl(_Bpath);
			string baseDn = Burl.getDN();
			string eFdn=((baseDn != null && baseDn.Length != 0) ? (name + "," + baseDn) : name);
			LdapUrl curl=new LdapUrl(Burl.Host,Burl.Port,eFdn);
			ent.Path=curl.ToString();
			ent.Nflag = true;
			return ent;
		}
예제 #24
-1
		/*
		* Ldap URL search
		*/
		
		/// <summary> Synchronously perfoms the search specified by the Ldap URL, using
		/// the specified search constraints (such as the maximum number of
		/// entries to find or the maximum time to wait for search results).
		/// 
		/// When this method is called, a new connection is created
		/// automatically, using the host and port specified in the URL. After
		/// all search results have been received from the server, the method
		/// closes the connection (in other words, it disconnects from the Ldap
		/// server).
		/// 
		/// As part of the search constraints, a choice can be made as to whether
		/// to have the results delivered all at once or in smaller batches. If
		/// the results are to be delivered in smaller batches, each iteration
		/// blocks only until the next batch of results is returned.
		/// 
		/// 
		/// </summary>
		/// <param name="toGet">         Ldap URL specifying the entry to read.
		/// 
		/// </param>
		/// <param name="cons">          The constraints specific to the search.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public static LdapSearchResults Search(LdapUrl toGet, LdapSearchConstraints cons)
		{
			LdapConnection lconn = new LdapConnection();
			lconn.Connect(toGet.Host, toGet.Port);
			if (cons == null)
			{
				// This is a clone, so we already have our own copy
				cons = lconn.SearchConstraints;
			}
			else
			{
				// get our own copy of user's constraints because we modify it
				cons = (LdapSearchConstraints) cons.Clone();
			}
			cons.BatchSize = 0; // Must wait until all results arrive
			LdapSearchResults toReturn = lconn.Search(toGet.getDN(), toGet.Scope, toGet.Filter, toGet.AttributeArray, false, cons);
			lconn.Disconnect();
			return toReturn;
		}