Pergunta

Eu sou muito novo na Primavera e ter obtido a maioria do conhecimento que eu tenho do livro Primavera Receitas da Apress.

Eu tenho a autenticação LDAP de trabalho com Spring Security dentro de um webapp. Gostaria de arrancar meu feijão contexto de aplicação e arquivos de propriedades a partir deste um webapp, no entanto, e de alguma forma exteriorizar-los para que todos os nossos webapps pode referenciar os mesmos feijões. Então, quando é preciso mudar alguma coisa (como o ldapuser ou as URLs de LDAP), podemos alterá-lo em um lugar e o resto dos aplicativos só sei.

Atualizar Eu tenho implementado Reloadable Propriedades Primavera que está recarregando propriedades quando os arquivos que eles vêm são tocado. Eu estou usando propriedades criptografadas, no entanto, assim abaixo é de classe I criado em cima dos mais Reloadable Propriedades da Primavera.

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));
    }
}

E aqui está como eu usá-lo no meu 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>
Foi útil?

Solução

Como sobre: ??

  • Escrever um método que retorna uma lista de servidores LDAP - leitura de um tabela de banco de dados ou de propriedade de arquivos
  • exponha este wethod via jndi e usá-lo para injetar uma lista dos servidores em sua primavera configuração
  • Se você precisar dos servidores LDAP para ser atualizada dinamicamente você poderia ter uma votação trabalho para mudanças periodicamente ou então tem uma página de administração ou de feijão JMX para acionar a atualização. Tenha cuidado com isses concorrência para estes dois métodos (algo ler a lista, enquanto você está atualizando)

Outras dicas

que não iria ser Spring Security? Ele pode lidar com LDAPs. E se você faz um serviço de segurança que todos os usos, que não iria ser a maneira de administrá-lo?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top