Announcement Announcement Module
Collapse
No announcement yet.
Ensuring a system property is set Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ensuring a system property is set

    Hi

    I have a bunch of system properties that i need to be set before I can do any JSSE stuff. I wont rely on these being set with -D options on the command line (though they may be), so my bean - in this case a connection factory - which depends on these properties has a dependency like

    Code:
      <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath&#58;jsse.properties"/>
        <property name="ignoreResourceNotFound" value="true"/>
      </bean>
    
      <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" depends-on="keyStoreProperty,keyStoreTypeProperty,keyStorePasswordProperty,trustStoreProperty,trustStoreTypeProperty,trustStorePasswordProperty">
    ...
    and then my definition of one of these properties is

    Code:
      <bean id="setSystemProperty" abstract="true" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="java.lang.System"/>
        <property name="targetMethod" value="setProperty"/>
      </bean>
    
      <bean id="keyStoreProperty" parent="setSystemProperty">
        <property name="arguments">
          <list>
            <value>javax.net.ssl.keyStore</value>
            <value>$&#123;javax.net.ssl.keyStore&#125;</value>
          </list>
        </property>
      </bean>
    This works OK, because a user could invoke Java with a -Djavax.net.ssl.keyStore=whatever.jks option or put javax.net.ssl.keyStore=whatever.jks in jsse.properties (and they'd not be able to override it at the command line, which is potentially useful).

    This is all a bit long-winded - can anyone think of a more consice way to do it?

  • #2
    Actually, my main gripe with this is that there may be times when JSSE properties may not be set (when they're not relevant).

    Is there a way to avoid the PropertyPlaceholderConfigurer complaining when the JSSE properties are not set, when I'm trying to use the same set of config for non-JSSE communictions?

    I can get around this by setting

    Code:
    javax.net.ssl.keyStore=
    javax.net.ssl.keyStoreType=
    ...
    in my jsse.properties, but I'd like it to cope if there is just no jsse.properties supplied at all.

    Comment


    • #3
      I can think of two ways, both having to do with overriding some method from PropertiesLoaderSupport - PropertyPlaceholderConfigurer's grandparent class.

      You can subclass PropertyPlaceholderConfigurer and override loadProperties with some logic that ignore FileNotFoundException.

      You can also subclass the same class, but override setLocation and/or setLocations to preemptively check all the locations and filter out the ones that don't exist.

      Comment

      Working...
      X