Commit 8b9cef8c authored by Marvin S. Addison's avatar Marvin S. Addison
Browse files

Create ED-ID query sample solution for .NET.

git-svn-id: https://svn.middleware.vt.edu/svn/ed/edsamples@10051 fa4a4108-76f2-0310-9f0d-ba9fffaf4ff6
parent 6b180e0f

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdIdTest", "EdIdTest\EdIdTest.csproj", "{2899C510-962B-47C3-B972-F9FB7871FE27}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2899C510-962B-47C3-B972-F9FB7871FE27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2899C510-962B-47C3-B972-F9FB7871FE27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2899C510-962B-47C3-B972-F9FB7871FE27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2899C510-962B-47C3-B972-F9FB7871FE27}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
VisualSVNWorkingCopyRoot = .
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2899C510-962B-47C3-B972-F9FB7871FE27}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EdIdTest</RootNamespace>
<AssemblyName>EdIdTest</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.DirectoryServices.Protocols" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System;
using System.Security.Cryptography.X509Certificates;
using System.DirectoryServices.Protocols;
namespace EdIdTest
{
class Program
{
const string LDAP_HOST = "ed-dev.middleware.vt.edu";
const int LDAP_PORT = 10636;
const string LDAP_BASE = "ou=people,dc=vt,dc=edu";
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("USAGE: EdIdTest uusid query");
return;
}
// The following should be the uusid of your ED-ID service
string certCN = args[0];
string ldapQuery = args[1];
Console.WriteLine(string.Format("Querying {0} as service {1} for {2}", LDAP_HOST, certCN, ldapQuery));
// Create connection and attempt to bind and search
LdapConnection conn = null;
try
{
conn = new LdapConnection(
new LdapDirectoryIdentifier(LDAP_HOST, LDAP_PORT),
null,
AuthType.External);
// VT Enterprise Directory requires LDAPv3
conn.SessionOptions.ProtocolVersion = 3;
conn.SessionOptions.SecureSocketLayer = true;
// Look up client cert in Local Machine store by subject CN
conn.SessionOptions.QueryClientCertificate =
delegate(LdapConnection c, byte[][] trustedCAs)
{
X509Store lmStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
lmStore.Open(OpenFlags.ReadOnly);
// Uncomment the following lines to help diagnose cert problems
//Console.WriteLine();
//Console.WriteLine("Available certificates in Local Machine store:");
//foreach (X509Certificate cert in lmStore.Certificates)
//{
// Console.WriteLine(" " + cert.Subject);
//}
//Console.WriteLine("Querying Local Machine store for valid cert with subject " + certCN);
X509Certificate2Collection clientCerts = lmStore.Certificates.Find(
X509FindType.FindBySubjectName, certCN, true);
if (clientCerts.Count == 0)
{
throw new ArgumentException("Cannot find valid certificate with subject " + certCN);
}
return clientCerts[0];
};
conn.Bind();
// The 4th parameter, attributeList, is omitted to indicate all available attributes
SearchResponse response = (SearchResponse)conn.SendRequest(
new SearchRequest(LDAP_BASE, ldapQuery, SearchScope.Subtree));
Console.WriteLine();
Console.WriteLine(response.Entries.Count + " entries found:");
foreach (SearchResultEntry entry in response.Entries)
{
Console.WriteLine(" " + entry.DistinguishedName);
foreach (String name in entry.Attributes.AttributeNames)
{
Console.Write(" " + name + "=");
int n = 0;
foreach (object value in entry.Attributes[name].GetValues(typeof(string)))
{
if (n++ > 0)
{
Console.Write(',');
}
Console.Write(value);
}
Console.WriteLine();
}
}
}
catch (Exception e)
{
Console.WriteLine("Application error: \n" + e);
}
finally
{
if (conn != null)
{
conn.Dispose();
}
}
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EdIdTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EdIdTest")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dc897f85-4f33-45dc-bac1-4ffa7ee212b0")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment