Skip to main content
Jump to: navigation, search

Difference between revisions of "Context Discovery Components Without XRDS"

(No difference)

Revision as of 03:22, 28 January 2008

About

This page outlines an alternative way to perform two core services of the IdASRegistry, which are "normally" handled using XRDS documents (as described in ContextDiscoveryComponents)

On this page, "normal" means the XRDS way, whereas "alternative" means the Configuration API way, as described on this page. (Markus: Sorry for calling the XRDS way the "normal" one, it helps me write this page :) ).

These two services are:

  1. Configuration and registration of context factories
  2. Configuration of contexts

This is now possible without requiring XRDS documents. The way of doing this is to use the Configuration API. This means that IdASRegistry is now an IConfigurableComponent. The map passed to its configure() method contains the information that is "normally" found in XRDS documents, i.e. 1) a list of context factories (+ configuration) and 2) context ids (+configuration).

Configuration and registration of context factories

As described in ContextDiscoveryComponents, this "normally" happens by looking into an XRDS document (by default a local file called "contextfactories.xrds").

The alternative way is that this is also possible by including a list of context factories (and their context types) in the map passed to IdASRegistry's configure() method.

Both ways can be combined. The IdASRegistry will then "know" all context factories from the XRDS document, and all context factories obtained through the Configuration API.

There is also a "manual" way to register context factories: The registerContextFactory() methods.

Configuration of contexts

Configuring and instantiating contexts involves a context ID.

A context ID somehow can be used to obtain one or more context types, and context configuration. The context type is used to find a suitable context factory. In the "normal" way, a context ID can be an XRI, URI or a local XRDS document. From that document the necessary information is read.

The alternative way is that the map passed to IdASRegistry's configure() method contains a list (called "ContextIdsList" in the example). Each entry in the list contains a context ID, plus the usual information (context types and context configuration). These context IDs can then be used just like the "normal" XRDS-based ones, e.g. in the IdASRegistry.createContext(contextID) method.

Like before, both ways can be combined. The IdASRegistry will be able to "resolve" context IDs from the "normal" way (i.e. XRIs, URIs, and local XRDS documents), but it will also "know" the context IDs obtained through the Configuration API.

Example

This is a sample configuration file that contains configuration for both context factories and contexts.

(Thanks to Jim, Mike, Daniel for writing the example, this helps a lot)


<Configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns="http://higgins.eclipse.org/Configuration"
	xmlns:htf="http://higgins.eclipse.org/Configuration">

	<!--  The setting handlers are classes that consume Setting elements where the Type matches and generate an object of the Class -->
	<SettingHandlers>
		<SettingHandler Type="xsd:integer" Class="java.lang.Integer" Handler="org.eclipse.higgins.configuration.xml.IntegerHandler" />
		<SettingHandler Type="xsd:string" Class="java.lang.String" Handler="org.eclipse.higgins.configuration.xml.StringHandler" />
		<SettingHandler Type="htf:uri" Class="java.net.URI" Handler="org.eclipse.higgins.configuration.xml.URIHandler" />
		<SettingHandler Type="htf:list" Class="java.util.List" Handler="org.eclipse.higgins.configuration.xml.ListHandler" />
		<SettingHandler Type="htf:map" Class="java.util.Map" Handler="org.eclipse.higgins.configuration.xml.MapHandler" />
		<SettingHandler Type="htf:instance" Class="Object" Handler="org.eclipse.higgins.configuration.xml.ClassInstanceHandler" />
		<SettingHandler Type="htf:singleton" Class="Object" Handler="org.eclipse.higgins.configuration.xml.SingletonHandler" />
		<SettingHandler Type="xsd:boolean" Class="java.lang.Boolean" Handler="org.eclipse.higgins.configuration.xml.BooleanHandler"/>
		<SettingHandler Type="htf:file" Class="java.io.FileInputStream" Handler="org.eclipse.higgins.configuration.xml.FileHandler"/>
		<SettingHandler Type="htf:keystore" Class="java.security.KeyStore" Handler="org.eclipse.higgins.configuration.xml.KeyStoreHandler"/>
	</SettingHandlers>

	<Setting Name="Configuration" Type="htf:map">

		<Setting Name="ComponentSettings" Type="htf:map">
	
			<Setting Name="TestContextFactory1" Type="htf:map">
				<Setting Name="value" Type="xsd:integer">10</Setting>
				<Setting Name="policy" Type="xsd:string">Hello World</Setting>
			</Setting>
	
			<Setting Name="TestContextFactory2" Type="htf:map">
				<Setting Name="value" Type="xsd:integer">20</Setting>
				<Setting Name="policy" Type="xsd:string">Good Bye World</Setting>
			</Setting>
	
			<Setting Name="TestContextFactory3" Type="htf:map">
				<Setting Name="value" Type="xsd:integer">30</Setting>
				<Setting Name="policy" Type="xsd:string">Hey World</Setting>
			</Setting>
	
			<Setting Name="IdASRegistry" Type="htf:map">
				<Setting Name="ContextFactoryInstancesList" Type="htf:list">
					<Setting Name="ContextFactory1" Type="htf:map">
						<Setting Name="Instance" Type="xsd:string">TestContextFactory1</Setting>
						<Setting Name="ContextTypes" Type="htf:list">
							<Setting Name="ContextType1" Type="xsd:string">$context+ldap</Setting>
							<Setting Name="ContextType2" Type="xsd:string">$context+openid</Setting>
						</Setting>
					</Setting>
					<Setting Name="ContextFactory2" Type="htf:map">
						<Setting Name="Instance" Type="xsd:string">TestContextFactory2</Setting>
						<Setting Name="ContextTypes" Type="htf:list">
							<Setting Name="ContextType1" Type="xsd:string">$context+openid</Setting>
						</Setting>
					</Setting>
					<Setting Name="ContextFactory3" Type="htf:map">
						<Setting Name="Instance" Type="xsd:string">TestContextFactory3</Setting>
						<Setting Name="ContextTypes" Type="htf:list">
							<Setting Name="ContextType1" Type="xsd:string">$context+jdbc</Setting>
						</Setting>
					</Setting>
				</Setting>
				<Setting Name="ContextIdsList" Type="htf:list">
					<Setting Name="ContextId1" Type="htf:map">
						<Setting Name="ContextId" Type="xsd:string">Jim's Context</Setting>
						<Setting Name="ContextTypes" Type="htf:list">
							<Setting Name="ContextType1" Type="xsd:string">$context+jndi</Setting>
						</Setting>
						<Setting Name="ContextUris" Type="htf:list">
							<Setting Name="ContextUri1" Type="htf:uri">http://authn.freexri.com/authentication</Setting>
						</Setting>
						<Setting Name="Connection" Type="htf:map">
							<Setting Name="ConnectionType" Type="xsd:string">LDAP</Setting>
							<Setting Name="AddressList" Type="htf:list">
								<Setting Name="Address" Type="xsd:string">ldap://wag.bandit-project.org:389</Setting>
							</Setting>
							<Setting Name="jndiProvider" Type="xsd:string">com.sun.jndi.ldap.LdapCtxFactory</Setting>
							<Setting Name="searchBase" Type="xsd:string">ou=people,dc=wag,dc=bandit-project,dc=org</Setting>
						</Setting>
						<Setting Name="env" Type="htf:map">
							<Setting Name="java.naming.security.authentication" Type="xsd:string">simple</Setting>
							<Setting Name="java.naming.security.principal" Type="xsd:string">cn=admin,o=novell</Setting>
							<Setting Name="java.naming.security.credentials" Type="xsd:string">novelled8</Setting>
							<Setting Name="org.eclipse.higgins.idas.cp.jndi.startTLS" Type="xsd:string">true</Setting>
							<Setting Name="org.eclipse.higgins.idas.cp.jndi.trustStore" Type="xsd:string">JNDICPTest.keystore</Setting>
							<Setting Name="java.naming.ldap.attributes.binary" Type="xsd:string">guid</Setting>
						</Setting>
					</Setting>
					<Setting Name="ContextId2" Type="htf:map">
						<Setting Name="ContextId" Type="xsd:string">Mike's Context</Setting>
						<Setting Name="ContextTypes" Type="htf:list">
							<Setting Name="ContextType1" Type="xsd:string">$context+jdbc</Setting>
						</Setting>
						<Setting Name="username" Type="xsd:string">dbuser</Setting>
						<Setting Name="password" Type="xsd:string">dbpass</Setting>
					</Setting>
				</Setting>
			</Setting>
		</Setting>
	
		<Setting Name="TestContextFactory1" Type="htf:instance">org.eclipse.higgins.idas.registry.test.TestContextFactory1</Setting>
	
		<Setting Name="TestContextFactory2" Type="htf:instance">org.eclipse.higgins.idas.registry.test.TestContextFactory2</Setting>
	
		<Setting Name="TestContextFactory3" Type="htf:instance">org.eclipse.higgins.idas.registry.test.TestContextFactory3</Setting>
	
		<Setting Name="IdASRegistry" Type="htf:singleton">org.eclipse.higgins.idas.registry.IdASRegistry</Setting>

	</Setting>

</Configuration>

Example code

The following code could be used to obtain the IdASRegistry instance and instantiate a context. The context configuration, the context factory configuration, and the context type that links them all are configured by the file above.


	// use the Configuration API to configure the IdASRegistry
	
	ConfigurationHandler handler = new ConfigurationHandler();
		
	handler.setConfigurationBase(".");
	handler.setFileName("resources/idasregistryconfig.xml");
	handler.configure(null);
	registry = (IdASRegistry) handler.getSettings().get("IdASRegistry");

	// obtain a context from a context id (long way)

	IContextId contextId = ContextIdFactory.fromString("Mike's Context");
	IContextFactory factory = registry.getContextFactory(contextId);
	IContext context = factory.createContext(contextId);

	// obtain a context from a context id (short way)

	IContext context2 = registry.createContext("Jim's Context");

Copyright © Eclipse Foundation, Inc. All Rights Reserved.