문제

나는 Spring의 새로운 브랜드이며 Apress의 Spring Recipes 책에서 내가 가진 대부분의 지식을 얻었습니다.

하나의 웹앱 내에서 Spring Security와 함께 작동하는 LDAP 인증이 있습니다.그러나 나는 이 하나의 웹앱에서 내 애플리케이션 컨텍스트 빈과 속성 파일을 추출하고 모든 웹앱이 동일한 빈을 참조할 수 있도록 어떻게든 외부화하고 싶습니다.따라서 무언가(ldapuser 또는 ldap url과 같은)를 변경해야 할 때 한 곳에서 변경하면 나머지 앱이 이를 알 수 있습니다.

업데이트나는 구현했다 다시 로드할 수 있는 스프링 속성 이는 해당 파일이 터치될 때 속성을 다시 로드하는 것입니다.그러나 저는 암호화된 속성을 사용하고 있으므로 아래는 Reloadable Spring Properties 위에 생성한 클래스입니다.

EncryptablePropertyPlaceholderConfigurer.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 서버 목록을 반환하는 메소드 작성 - 데이터베이스 테이블 또는 속성 파일에서 읽기
  • jndi를 통해 이 방법을 노출하고 이를 사용하여 스프링 구성에 서버 목록을 삽입합니다.
  • LDAP 서버를 동적으로 새로 고쳐야 하는 경우 주기적으로 변경 사항에 대한 작업 폴링을 수행하거나 업데이트를 트리거하는 관리 웹 페이지 또는 jmx Bean을 사용할 수 있습니다.이 두 가지 방법 모두에 대한 동시성 문제(업데이트하는 동안 목록을 읽는 문제)에 주의하세요.

다른 팁

스프링 시큐리티 아닌가요?LDAP를 처리할 수 있습니다.그리고 모두가 사용하는 하나의 보안 서비스로 만든다면 그게 바로 관리의 방식이 아닐까요?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top