0

We are using spring security and have it working well. I am trying to figure out one thing that has not being obvious - how do I configure ldap-server attribute to use different url based on deployed environment?

This is what I have that is working:

<ldap-server url="ldap://testserver:port/o=blah" manager-dn="cn=bind,ou=Users,o=blah" manager-password="password"/>

<authentication-manager id="authenticationManager" alias="authenticationManager">
<ldap-authentication-provider            
    user-search-filter="(cn={0})"           
    user-search-base="ou=Users"           
    group-search-filter="(uniqueMember={0})"           
    group-search-base="ou=groups"           
    group-role-attribute="cn"           
    role-prefix="none">         
</ldap-authentication-provider>

Now, how do I configure it to use a different url based on deployed environment?

thanks in advance, Sharath

Sharath
  • 65
  • 1
  • 7
  • Use a PropertyPlaceholderConfigurer. See http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/htmlsingle/#beans-factory-placeholderconfigurer – Rob Winch Aug 09 '13 at 21:52
  • @RobWinch Thanks for the response.This would need the properties file external of the application and what we are looking for is to make the configuration encapsulated within the application itself. Any thoughts? other options? – Sharath Aug 13 '13 at 15:34
  • I think you need to expand on what you are looking for. What do you mean by encapsulated within the application itself. You can place the properties file in the application if you like but then you cannot change it very easily. Rather than using a properties file, you can also use system arguments. Another thing I have done is use PropertyPlaceHolderConfigurer with JNDI lookups as the values. – Rob Winch Aug 13 '13 at 17:53
  • @RobWinch Rob, I like the idea of the jndi configurer and I tried implementing one as well. The problem is how do I replace the value of the url in 'ldap-server url="ldap://testserver:port/o=blah"' as that is not a property? I basically need **url** in to be dynamic based on deployed environment. I feel there is or should be something simple that I am missing as I feel that this should be a fairly common use case. – Sharath Aug 13 '13 at 19:17
  • @RobWinch I found a response by you on another post [link](http://forum.springsource.org/showthread.php?128650-help-configuring-LDAP-server-with-externalized-variables) and used that info to do the following which worked: Added an entry in websphere with varName and have the following in applicationContext-security xml: ` ` Thanks for your help! – Sharath Aug 13 '13 at 21:18

2 Answers2

0

I've done that with Spring profiles:

In your spring.*.xml config file use this at the end of your file:

<beans profile="production">
...
</beans>
<beans profile="local">
...
</beans>

As VM Arguments the used profile must be provided: -Dspring.profiles.active=production

Regards

Johann
  • 447
  • 4
  • 12
0

You can use the url as variables and set them in a properties file. To change the properties file should be easier. I know you can do that with Maven - with jar or war plugin depending on packaging, including generating two (or more) packages with one execution - but I suppose you can with Ant or other managers too.

Of course, you could use that solution to change the whole xml, but it's easier to do that with a properties file because that way, when changing the configuration, the markup will not be in the way, only variables and values.

dtortola
  • 768
  • 4
  • 6