Question

Je suis flambant neuf au printemps et ont obtenu la majorité des connaissances que je n'ai du livre Recettes de printemps Apress.

J'ai authentification LDAP travailler avec Spring Security dans l'webapp. Je voudrais arracher cependant, mon contexte d'application des haricots et des fichiers de propriétés de celui-ci webapp, et en quelque sorte de les extérioriser en sorte que tous nos webapps peuvent référencer les mêmes haricots. Donc, quand nous avons besoin de changer quelque chose (comme le ldapuser ou les urls ldap), nous changeons en un seul endroit et le reste des applications savons juste.

UPDATE J'ai mis en Propriétés Spring Reloadable qui est des propriétés rechargeant lorsque les fichiers sont ils viennent touché. J'utilise les propriétés chiffrées, cependant, donc ci-dessous classe I créé au-dessus de ceux Propriétés Spring Reloadable.

ReloadingEncryptablePropertyPlaceholderConfigurer.java

package;

import java.util.Properties;
import java.util.Set;

import org.apache.commons.lang.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.util.text.TextEncryptor;
import org.jasypt.properties.PropertyValueEncryptionUtils;

import org.springframework.beans.factory.BeanDefinitionStoreException;

public class ReloadingEncryptablePropertyPlaceholderConfigurer extends ReloadingPropertyPlaceholderConfigurer {

    protected final Log logger = LogFactory.getLog(getClass());
    private final StringEncryptor stringEncryptor;
    private final TextEncryptor textEncryptor;

    public ReloadingEncryptablePropertyPlaceholderConfigurer(TextEncryptor textEncryptor) {
        super();
        logger.info("Creating configurer with TextEncryptor");
        Validate.notNull(textEncryptor, "Encryptor cannot be null");
        this.stringEncryptor = null;
        this.textEncryptor = textEncryptor;
    }

    public ReloadingEncryptablePropertyPlaceholderConfigurer(StringEncryptor stringEncryptor) {
        super();
        logger.info("Creating configurer with StringEncryptor");
        Validate.notNull(stringEncryptor, "Encryptor cannot be null");
        this.stringEncryptor = stringEncryptor;
        this.textEncryptor = null;
    }

    @Override
    protected String convertPropertyValue(String originalValue) {
        if (!PropertyValueEncryptionUtils.isEncryptedValue(originalValue)) {
            return originalValue;
        }
        if (this.stringEncryptor != null) {
            return PropertyValueEncryptionUtils.decrypt(originalValue, this.stringEncryptor);
        }
        return PropertyValueEncryptionUtils.decrypt(originalValue, this.textEncryptor);
    }

    @Override
    protected String parseStringValue(String strVal, Properties props, Set visitedPlaceholders) throws BeanDefinitionStoreException {
        return convertPropertyValue(super.parseStringValue(strVal, props, visitedPlaceholders));
    }
}

Et voici comment je l'utilise dans mon securityContext.xml :

<bean id="securityContextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldaps://ldapserver" />
    <property name="urls" value="#{ldap.urls}" />
</bean>

<bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">
    <property name="scheduledTimerTasks">
        <bean id="reloadProperties" class="org.springframework.scheduling.timer.ScheduledTimerTask">
            <property name="period" value="1000"/>
            <property name="runnable">
                <bean class="ReloadConfiguration">
                    <property name="reconfigurableBeans">
                        <list>
                            <ref bean="configproperties"/>
                        </list>
                    </property>
                </bean>
            </property>
        </bean>
    </property>
</bean>

<bean id="configproperties" class="ReloadablePropertiesFactoryBean">
    <property name="location" value="classpath:ldap.properties"/>
</bean>

<bean id="ldapPropertyConfigurer" class="ReloadingEncryptablePropertyPlaceholderConfigurer">
    <constructor-arg ref="configurationEncryptor" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="properties" ref="configproperties"/>
</bean>

<bean id="jasyptConfig" class="org.jasypt.encryption.pbe.config.SimpleStringPBEConfig">
    <property name="algorithm" value="PBEWithMD5AndTripleDES" />
    <property name="password" value="########" />
</bean>

<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
    <property name="config" ref="jasyptConfig" />
</bean>
Était-ce utile?

La solution

Que diriez-vous:

  • L'écriture d'une méthode qui retourne une liste des serveurs LDAP - lecture d'un table de base de données ou fichiers propriété
  • exposer ce wethod via JNDI et l'utiliser pour injecter une liste des serveurs dans votre configuration de printemps
  • Si vous avez besoin des serveurs ldap à rafraîchir, vous pouvez avoir un sondage dynamique d'emploi pour les changements périodiquement ou bien avoir une page d'administration ou la fève de JMX pour déclencher la mise à jour. Méfiez-vous des isses pour ces deux accès concurrentiel méthodes (lire quelque chose la liste pendant que vous mettez à jour)

Autres conseils

Ce ne serait pas la sécurité du printemps? Il peut traiter PVI. Et si vous le faites d'un service de sécurité que tout le monde utilise, ce ne serait pas la façon de le gérer?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top