سؤال

أنا العلامة التجارية الردف الجديدة في الربيع وقد حصلت على غالبية المعرفة لدي من كتاب وصفات الربيع من إبريس.

لقد حصلت على مصادقة LDAP تعمل مع أمان الربيع داخل ويب واحد. أرغب في مزج فاصوليا في تطبيقات التطبيق الخاصة بي وملفات الخصائص من هذا WebApp One، ومع ذلك، وفي حد ذاته، يمكن أن يقوم كل شيء بحيث يمكن أن تتمكن كل من WebApps لدينا من نفس الفاصوليا. لذلك عندما نحتاج إلى تغيير شيء ما (مثل LDAPUSER أو عناوين Url LDAP)، فإننا نغيره في مكان واحد وبقية التطبيقات تعرف فقط.

تحديثلقد نفذت خصائص الربيع القابلة لإعادة تحميل التي تم إعادة تحميل الخصائص عند لمس الملفات التي تأتي منها. أنا أستخدم خصائص مشفرة، ومع ذلك، فمن الدرجة الأولى التي قمت بإنشائها أعلى خصائص الربيع القابلة لإعادة تحميلها.

إعادة التحميل ReportablePropertyplessholderconfigurer.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>
هل كانت مفيدة؟

المحلول

ماذا عن:

  • كتابة طريقة إرجاع قائمة خوادم LDAP - قراءة من جدول قاعدة البيانات أو ملفات الخصائص
  • فضح هذا Wethod عبر JNDI واستخدمه لحقن قائمة من الخوادم في تكوين الربيع الخاص بك
  • إذا كنت بحاجة إلى تحديث خوادم LDAP بمنعشة ديناميكيا، فيمكنك إجراء استطلاع لإجراء تغييرات عن التغييرات بشكل دوري أو آخر تحتوي على صفحة ويب غير مشرف أو JMX BEAN لتشغيل التحديث. توخي الحذر من التزامن ISS لكل من هذه الأساليب (شيء يقرأ القائمة أثناء تحديثه)

نصائح أخرى

لن يكون ذلك الأمن الربيع؟ يمكن أن تتعامل مع LDAPS. وإذا قمت بإجراء خدمة أمنية واحدة يستخدمها الجميع، فلن تكون هذه هي الطريقة لإدارتها؟

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top