简体   繁体   中英

Encrypt mail password in Spring Boot + Spring Integration application

My application is developed using Spring boot , this application also reading a mailbox, this mail reading part was implemented using Spring Integration framework.

I need to encrypt all passwords using in this application. I am using Jasypt library ( http://www.jasypt.org/ ) for this encryption. All password encryptions are working fine, except the mail password.

Problem : That is, the mail password is sending as-is ( without decryption ). So, mail authentication failed.

Code involves ALL other passwords are using ONLY spring boot, so there is ONLY one application context exists. But, mail reading part alone was implemented by using Spring Integration framework. This configuration was done using an xml file,this xml file creates 2nd Application context. So, password decryption is NOT accessible for this 2nd application context.

Jasypt library related encryption code exists inside 1st application context .

Will convert the below xml based configuration of Spring Integration into Java Based config solve the problem? ( Because, there will be only one application context). If yes, can anyone provide the Java config equivalent for the below ( prior to Java 8 version )

<beans>
    <int:channel id="receiveChannel" /> 
    <mail:inbound-channel-adapter id="pop3ShouldDeleteTrue"
                                     store-uri="${mail.pop3.user.folder.uri}" 
                        channel="receiveChannel" 
                        should-delete-messages="false" 
                        should-mark-messages-as-read="true"
                        auto-startup="true"
                        java-mail-properties="javaMailProperties">

        <int:poller max-messages-per-poll="1" fixed-rate="${actor.email.polling.interval}"> 
        </int:poller>   
    </mail:inbound-channel-adapter>
    <context:property-placeholder location="file:./application-${env}.properties" local-override="true" />
    <util:properties id="javaMailProperties"> 
        <prop key="${mail.socketFactory}">false</prop> 
        <prop key="mail.debug">false</prop> 
        <prop key="mail.store.protocol">${mail.store.protocol}</prop>
    </util:properties> 
</beans>

Why is it in a second application context?

You can use @ImportResource in your Spring Boot app to pull the xml into the main Boot context.

See here for an example.

If you want to convert to Java Configuration, this answer has an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM