Encrypting a password within a Spring configuratio

2019-07-23 05:26发布

I have a Spring bean which uses a username/password as part of its constructor parameters :

<bean id="mysender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
         <property name="c">
             <bean class="org.apache.commons.httpclient.UsernamePasswordCredentials">
                 <constructor-arg value="plaintext"/>
                 <constructor-arg value="plaintext"/>
             </bean>
         </property>
     </bean>

Can I use jasypt to encrypt these parameters from the configuration file only ? The bean "org.apache.commons.httpclient.UsernamePasswordCredentials" will be instantiated with plain text values but to the user they will appear encrypted.

I could use core java library code using this answer : Encrypt Password in Configuration Files? and manually create the bean mysender from within java, then depcript the fields before instantiating org.apache.commons.httpclient.UsernamePasswordCredentials

Or is there a tried method of I have not mentioned which will implement this ?

1条回答
登录 后发表回答