How do I encrypt DB connect information in an xml file?

39 views Asked by At

When I try to encrypt DB connect information, I'm at a loss as to what to do if the information is in XML rather than properties.

I'm using Spring 4.x.x, eclipse, java 1.8, jasypt spring-31(1.9.2)

To explain the context.xml and the config.xml containing db information with the just bean settings,

  • The config.xml has the following structure.
  • I put in the contact ID, PW to encrypt by CMD (jasypt-1.9.3-dist)
<?xml version="1.0" encoding="UTF-8"?>   
<config>        
    <jdbc>      
        <driverName>DBMS Driver</driverName>        
        <url>URL value</url>        
        <id>access ID</id>      
        <pw>access PW</pw>  
    </jdbc> 
</config> 
  • context.xml has the following structure.

If I set it as below and start the server, the config will get an error saying that DOCTYPE should be equal to null. (The above-mentioned config is identified as a property config of an empty id = configuration Encryptor.)

When using jasypt, it said that it is processed without having to set up a separate DOCTYPE.

I also tried to set it to the DOCTYPE system..., specify the dtd file, and add it to the metadata folder, but it was also not processed.

Therefore, in order to process DB information separately as properties, the placeholder created a location property and designated the path, but this also failed to put variable values in the dataSourceSpied bean normally.

<?xml version="1.0" encoding="UTF-8"?>
// beans xmlns, xsi
// mybatis bean

<!-- placeholder -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="properties">
            <bean class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
                <property name="configurations">
                    <list>
                        <ref bean="configuration" />
                    </list>
                </property>
            </bean>
        </property>
</bean>

<bean id="configuration" class="org.apache.commons.configuration.CompositeConfiguration">
    <constructor-arg>
        <list>
            <bean class="org.apache.commons.configuration.XMLConfiguration">
                <constructor-arg type="java.lang.String">
                    <value>config/config.xml</value>
                </constructor-arg>
            </bean>
        </list>
    </constructor-arg>
</bean>

<!-- DB connect -->
<bean id="dataSourceSpied" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.id}"/>
        <property name="password" value="${jdbc.pw}"/>
</bean>

<!-- jasypt -->
<bean id="environmentVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
        <property name="algorithm" value="PBEWITHMD5ANDDES"/>
        <property name="password" value="test"/>
</bean>

<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
        <property name="config" ref="environmentVariablesConfiguration"/>
</bean>    

<bean class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
    <constructor-arg ref="configurationEncryptor" />
    <property name="locations" value="classpath:/config/config.xml" />
</bean>

How do I solve this problem?

please let me know anything your opinion.

I tried same encrypt in srping-boot. It clearly started. But I can not solve this same thing in xml.

0

There are 0 answers