0

私はSpringで真新しいスパンキングをしていて、ApressのSpringRecipesの本から私が持っている知識の大部分を手に入れました。

LDAP認証を1つのWebアプリ内でSpringSecurityと連携させています。ただし、この1つのWebアプリケーションからアプリケーションコンテキストBeanとプロパティファイルをリッピングし、すべてのWebアプリケーションが同じBeanを参照できるようにそれらを外部化したいと思います。したがって、何か(ldapuserやldap urlなど)を変更する必要がある場合は、1つの場所で変更するだけで、残りのアプリはそれを認識します。

UPDATEリロード可能なSpringプロパティを 実装しました。これは、元のファイルにアクセスしたときにプロパティをリロードします。暗号化されたプロパティを使用していますが、以下は、リロード可能なSpringプロパティのプロパティの上に作成したクラスです。

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

そして、これが私の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>
4

2 に答える 2

1

どうですか:

  • LDAPサーバーのリストを返すメソッドの作成-データベーステーブルまたはプロパティファイルからの読み取り
  • jndiを介してこのwethodを公開し、それを使用してサーバーのリストをSpring構成に挿入します
  • LDAPサーバーを動的に更新する必要がある場合は、変更を定期的にジョブポーリングするか、管理WebページまたはjmxBeanを使用して更新をトリガーすることができます。これらの両方のメソッドの並行性の問題に注意してください(更新中にリストを読み取るもの)
于 2009-07-15T16:10:47.953 に答える
0

それはSpringSecurityではないでしょうか。LDAPを処理できます。そして、それを誰もが使用する1つのセキュリティサービスにすると、それを管理する方法ではないでしょうか。

于 2009-07-15T01:21:33.370 に答える