...
Extension Class
Code Block |
---|
public class MyDataConnector extends BaseDataConnector {
private String lookupUrl; //This is an example custom field, yours may vary (if any)
public MyDataConnector(String url) {
this.lookupUrl = url;
}
public Map<String, BaseAttribute> resolve(ShibbolethResolutionContext resolutionContext)
throws AttributeResolutionException {
Map<String, BaseAttribute> result = new HashMap<String, BaseAttribute>();
String username = resolutionContext.getAttributeRequestContext().getPrincipalName();
// add BasicAttributes to the result here.
return result;
}
}
|
...
Located in your JAR file as schema/myConnectors.xsd. (Note this name is not special in anyway, it must just match between the locations it is referenced)
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="urn:example.org:shibboleth:2.0:resolver"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
elementFormDefault="qualified">
<import namespace="urn:mace:shibboleth:2.0:resolver"
schemaLocation="classpath:/schema/shibboleth-2.0-attribute-resolver.xsd" />
<complexType name="UserLookup">
<annotation>
<documentation>
Description of your data connector.
</documentation>
</annotation>
<complexContent>
<extension base="resolver:BaseDataConnectorType">
<attribute name="lookupUrl" type="string" use="required">
<annotation>
<documentation>
This is an example of a custom attribute called "lookupUrl".
Look in the shib-common.jar at schema/shibboleth-2.0-attribute-resolver-dc.xml
for more examples of how to define custom attributes and elements.
</documentation>
</annotation>
</attribute>
</extension>
</complexContent>
</complexType>
</schema>
|
Bean Definition Parser
Code Block |
---|
public class MyDataConnectorBeanDefinitionParser extends BaseDataConnectorBeanDefinitionParser {
public static final QName SCHEMA_NAME = new QName(MyDataConnectorNamespaceHandler.NAMESPACE, "UserLookup");
protected Class getBeanClass(Element element) {
return MyDataConnectorFactoryBean.class;
}
protected void doParse(Element element, BeanDefinitionBuilder builder) {
super.doParse(element, builder);
String lookupUrl = pluginConfig.getAttributeNS(null, "lookupUrl");
builder.addPropertyValue("lookupUrl", lookupUrl);
}
}
|
Bean Factory
Code Block |
---|
public class MyDataConnectorFactoryBean extends BaseDataConnectorFactoryBean {
private String lookupUrl;
public Class getObjectType() {
return MyDataConnector.class;
}
protected Object createInstance() throws Exception {
MyDataConnector connector = new MyDataConnector(getLookupUrl());
populateDataConnector(connector);
return connector;
}
public void setLookupUrl(String url) { this.lookupUrl = url; }
public String getLookupUrl() { return this.lookupUrl; }
}
|
Namespace Handler
Code Block |
---|
public class MyDataConnectorNamespaceHandler extends BaseSpringNamespaceHandler {
public static String NAMESPACE = "urn:example.org:shibboleth:2.0:resolver";
public void init() {
registerBeanDefinitionParser(MyDataConnectorBeanDefinitionParser.SCHEMA_NAME,
new MyDataConnectorBeanDefinitionParser());
}
}
|
...
Located in your JAR file as META-INF/spring.schemas.
Code Block |
---|
urn\:example.org\:shibboleth\:2.0\:resolver = schema/myConnectors.xsd
|
spring.
...
handlers File
Located in your JAR file as META-INF/spring.handlers.
Code Block |
---|
urn\:example.org\:shibboleth\:2.0\:resolver = com.example.shibboleth.MyDataConnectorNamespaceHandler
|
...
Declare your name space, add your XML schema file to the documents schemaLocation and add your DataConnector:
Code Block |
---|
<ProfileHandlerGroup xmlns="urn:mace:shibboleth:2.0:idp:profile-handler"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:example="http://example.org/shibboleth/authn"
xsi:schemaLocation="urn:mace:shibboleth:2.0:idp:profile-handler classpath:/schema/shibboleth-2.0-idp-profile-handler.xsd
urn:example.org:shibboleth:2.0:resolver classpath:/schema/myConnectors.xsd">
[..]
<resolver:DataConnector id="userLookupAttributes" xsi:type="UserLookup" xmlns="urn:example.org:shibboleth:2.0:resolver">
<lookupUrl>http://data.example.org</lookupUrl>
</resolver:DataConnector>
|