Where to put PicketLink XML configuration initialization code?
moghaddam Aug 24, 2015 2:23 AMHi
As mentioned in PicketLink reference documentation, it's possible to configure its store by XML as:
String configFilePath = "config/embedded-file-config.xml";
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream(configFilePath);
XMLConfigurationProvider xmlConfigurationProvider = new XMLConfigurationProvider();
IdentityConfigurationBuilder idmConfigBuilder =
xmlConfigurationProvider.readIDMConfiguration(configStream);
I put the above code in my IdentityManagementConfiguration class as below:
public class IdentityManagementConfiguration {
public void observeIdentityConfigurationEvent(@Observes IdentityConfigurationEvent event){
String configFilePath = "idm-bootstrap.xml";
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream(configFilePath);
XMLConfigurationProvider xmlConfigurationProvider = new XMLConfigurationProvider();
IdentityConfigurationBuilder identityConfigurationBuilder = xmlConfigurationProvider.readIDMConfiguration(configStream);
identityConfigurationBuilder.buildAll();
}
}
Here is my XML configuration:
<PicketLink xmlns="urn:picketlink:identity-federation:config:2.1">
<PicketLinkIDM>
<named value="ldap.config">
<stores>
<ldap>
<baseDN value="dc=moghaddam,dc=com"/>
<bindDN value="cn=Directory Manager"/>
<bindCredential value="111"/>
<url value="ldap://localhost:389"/>
<supportCredentials value="true"/>
<mapping value="org.picketlink.idm.model.basic.User">
<baseDN value="ou=Users,dc=moghaddam,dc=com"/>
<objectClasses value="inetOrgPerson"/>
<attribute propertyName="firstName" ldapAttributeName="givenName" />
<attribute propertyName="lastName" ldapAttributeName="sn" />
<attribute propertyName="email" ldapAttributeName="mail" />
<attribute propertyName="loginName" ldapAttributeName="cn" identifier="true" />
<attribute propertyName="employeeNumber" ldapAttributeName="employeeNumber" />
</mapping>
</ldap>
</stores>
</named>
</PicketLinkIDM>
</PicketLink>
The observeIdentityConfigurationEvent method is being called successfully. But when I try to query a user that I'm sure exists in LDAP server, it returns no results. By debugging the getResultList method in DefaultIdentityQuery, I noticed the only identity store returned by the storeSelector is the default FileIdentityStore and there is no ldap store.
What I've missed in my configuration or bootstrapping process? Is it correct to place the xml configuration code in the @Observes method or it should be placed somewhere else?
Regards
Ehsan