Spring Boot integrated jasypt security framework

Source: Internet
Author: User


The Jasypt security framework provides spring integration, primarily for

The Placeholderconfigurersupport class or its subclasses.


After Sring 3.1, it is recommended to replace the configuration class with the Propertysourcesplaceholderconfigurer class as a property, where spring integration Jasypt uses Jasypt to replace the implementation of the configuration class with the attribute. Encryptablepropertysourcesplaceholderconfigurer.

It is easier to integrate in spring, and Jasypt has also given the way to configure beans and XML using jasypt tags, and spring boot integration is a little bit different, creating an automatic configuration class, and create a bean that injects placeholderconfigurersupport jasypt implementation.



The following is an example of use:

import org.jasypt.encryption.pbe.standardpbebyteencryptor;import  org.jasypt.encryption.pbe.standardpbestringencryptor;import  org.jasypt.spring31.properties.encryptablepropertysourcesplaceholderconfigurer;import  org.springframework.boot.autoconfigure.autoconfigureorder;import  org.springframework.boot.autoconfigure.condition.conditionalonmissingbean;import  org.springframework.boot.autoconfigure.condition.searchstrategy;import  org.springframework.context.annotation.bean;import org.springframework.context.annotation.configuration; import org.springframework.context.support.propertysourcesplaceholderconfigurer;import  org.springframework.core.ordered;import org.springframework.core.io.classpathresource;/** *  author : secondriver * date   : 2016/5/26 */@ Configuration@autoconfigureorder (ordered.highest_precedence) public class  encryptpropertyplaceholderautoconfiguration {    private static final string security_properties_file =  " Security.properties ";     @Bean      @ConditionalOnMissingBean (search  = searchstrategy.current)     public static  Propertysourcesplaceholderconfigurer propertysourcesplaceholderconfigurer ()  {         StandardPBEStringEncryptor encryptor = new  Standardpbestringencryptor ();         encryptor.setalgorithm ( Standardpbebyteencryptor.default_algorithm);         Encryptor.setpassword ("Security");         encryptablepropertysourcesplaceholderconfigurer                 configurer = new  Encryptablepropertysourcesplaceholderconfigurer (ENCRYPTOR);         configurer.setlocation (New classpathresource ( Security_properties_file));        return configurer;     }}


The write of the configuration file is basically similar to the spring XML. Application.yml equivalent to Applicationcontext.xml,security.properties is the configuration file for property substitution.


APPLICATION.YML:

Spring:datasource:url:jdbc:mysql://localhost:3306/abc?usessl=false username:root password: ${jdbc.password}


Security.properties:

Jdbc.password=enc (JWGGELCKUXRUCI2AQA6CF9VCXYPUKEZR)



When you create a data source, when you use the attribute parameter, the content in enc () is decrypted, the authentication succeeds, and the data source is created.

This article is from the "Red Horse Red" blog, please be sure to keep this source http://aiilive.blog.51cto.com/1925756/1784180

Spring Boot integrated jasypt security framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.